Skip to content

Commit

Permalink
Remove unused code
Browse files Browse the repository at this point in the history
Signed-off-by: jesus m. rodriguez <[email protected]>
  • Loading branch information
jmrodri committed Sep 30, 2022
1 parent 5569e84 commit adfae2b
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 131 deletions.
14 changes: 14 additions & 0 deletions internal/jira/mock/endpointpattern.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
// Copyright © 2022 jesus m. rodriguez [email protected]
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package mock

var PostIssue EndpointPattern = EndpointPattern{
Expand Down
73 changes: 14 additions & 59 deletions internal/jira/mock/server.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
// Copyright © 2022 jesus m. rodriguez [email protected]
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package mock

import (
Expand Down Expand Up @@ -49,65 +63,6 @@ func (srh *FIFOReponseHandler) ServeHTTP(w http.ResponseWriter, r *http.Request)
w.Write(srh.Responses[srh.CurrentIndex])
}

// PaginatedReponseHandler handler implementation that
// responds to the HTTP requests and honors the pagination headers
//
// Header e.g: `Link: <https://api.github.com/search/code?q=addClass+user%3Amozilla&page=15>; rel="next",
// <https://api.github.com/search/code?q=addClass+user%3Amozilla&page=34>; rel="last",
// <https://api.github.com/search/code?q=addClass+user%3Amozilla&page=1>; rel="first",
// <https://api.github.com/search/code?q=addClass+user%3Amozilla&page=13>; rel="prev"`
//
// See: https://docs.github.com/en/rest/guides/traversing-with-pagination
// type PaginatedReponseHandler struct {
// ResponsePages [][]byte
// }

// func (prh *PaginatedReponseHandler) getCurrentPage(r *http.Request) int {
// strPage := r.URL.Query().Get("page")
//
// if strPage == "" {
// return 1
// }
//
// page, err := strconv.Atoi(r.URL.Query().Get("page"))
//
// if err == nil {
// return page
// }
//
// // this should never happen as the request is being made by the SDK
// panic(fmt.Sprintf("invalid page: %s", strPage))
// }

// func (prh *PaginatedReponseHandler) generateLinkHeader(
// w http.ResponseWriter,
// r *http.Request,
// ) {
// currentPage := prh.getCurrentPage(r)
// lastPage := len(prh.ResponsePages)
//
// buf := bytes.NewBufferString(`<?page=1>; rel="first",`)
// buf.WriteString(fmt.Sprintf(`<?page=%d>; rel="last",`, lastPage))
//
// if currentPage < lastPage {
// // when resp.NextPage == 0, it means no more pages
// // which is basically as not setting it in the response
// buf.WriteString(fmt.Sprintf(`<?page=%d>; rel="next",`, currentPage+1))
// }
//
// if currentPage > 1 {
// buf.WriteString(fmt.Sprintf(`<?page=%d>; rel="prev",`, currentPage-1))
// }
//
// w.Header().Add("Link", buf.String())
// }

// ServeHTTP implementation of `http.Handler`
// func (prh *PaginatedReponseHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
// prh.generateLinkHeader(w, r)
// w.Write(prh.ResponsePages[prh.getCurrentPage(r)-1])
// }

// EnforceHostRoundTripper rewrites all requests with the given `Host`.
type EnforceHostRoundTripper struct {
Host string
Expand Down
56 changes: 14 additions & 42 deletions internal/jira/mock/server_options.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
// Copyright © 2022 jesus m. rodriguez [email protected]
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package mock

import (
Expand Down Expand Up @@ -62,45 +76,3 @@ func WithRequestMatch(
Responses: responses,
})
}

// WithRequestMatchPages honors pagination directives.
//
// Pages can be requested in any order and each page can be called multiple times.
//
// E.g.
//
// mockedHTTPClient := NewMockedHTTPClient(
// WithRequestMatchPages(
// GetOrgsReposByOrg,
// []github.Repository{
// {
// Name: github.String("repo-A-on-first-page"),
// },
// {
// Name: github.String("repo-B-on-first-page"),
// },
// },
// []github.Repository{
// {
// Name: github.String("repo-C-on-second-page"),
// },
// {
// Name: github.String("repo-D-on-second-page"),
// },
// },
// ),
// )
// func WithRequestMatchPages(
// ep EndpointPattern,
// pages ...interface{},
// ) MockBackendOption {
// p := [][]byte{}
//
// for _, r := range pages {
// p = append(p, MustMarshal(r))
// }
//
// return WithRequestMatchHandler(ep, &PaginatedReponseHandler{
// ResponsePages: p,
// })
// }
14 changes: 14 additions & 0 deletions internal/jira/mock/utils.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
// Copyright © 2022 jesus m. rodriguez [email protected]
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package mock

import (
Expand Down
30 changes: 0 additions & 30 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@ package main
import (
"os"

// "github.com/jmrodri/gh2jira/internal/gh"
// "github.com/jmrodri/gh2jira/internal/jira"
"github.com/jmrodri/gh2jira/cmd/root"
)

Expand All @@ -42,32 +40,4 @@ func main() {
if err := cmd.Execute(); err != nil {
os.Exit(1)
}
// if len(os.Args) < 2 {
// fmt.Println("Usage: list or clone")
// os.Exit(1)
// }
//
// command := os.Args[1]
//
// switch command {
// case "list":
// // Pass in options to the List command
// gh.ListIssues()
// case "clone":
// // Need github issue number
// if len(os.Args) < 3 {
// fmt.Println("Usage: clone ISSUE_TO_CLONE")
// os.Exit(1)
// }
// issueNum, _ := strconv.Atoi(os.Args[2])
// issue := gh.GetIssue(issueNum)
//
// var dryRun bool
// if len(os.Args) > 3 {
// dryRun = os.Args[3] == "--dryrun"
// }
// jira.CloneIssueToJira(issue, dryRun)
// default:
// fmt.Printf("Unsupported command: %s\n", command)
// }
}

0 comments on commit adfae2b

Please sign in to comment.