Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,10 @@ linters:
checks:
- "all"
- "-QF1008" # allow embedded field in selector
forbidigo:
forbid:
- pattern: "^http\\.Method[A-Z][a-z]*$"
msg: "Use string literals instead of http.Method constants (https://pkg.go.dev/net/http#pkg-constants)"
custom:
sliceofpointers:
type: module
Expand Down
3 changes: 1 addition & 2 deletions github/classroom.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ package github
import (
"context"
"fmt"
"net/http"
)

// ClassroomService handles communication with the GitHub Classroom related
Expand Down Expand Up @@ -67,7 +66,7 @@ func (a ClassroomAssignment) String() string {
func (s *ClassroomService) GetAssignment(ctx context.Context, assignmentID int64) (*ClassroomAssignment, *Response, error) {
u := fmt.Sprintf("assignments/%v", assignmentID)

req, err := s.client.NewRequest(http.MethodGet, u, nil)
req, err := s.client.NewRequest("GET", u, nil)
if err != nil {
return nil, nil, err
}
Expand Down
10 changes: 5 additions & 5 deletions github/github.go
Original file line number Diff line number Diff line change
Expand Up @@ -587,7 +587,7 @@ func (c *Client) NewFormRequest(urlStr string, body io.Reader, opts ...RequestOp
return nil, err
}

req, err := http.NewRequest(http.MethodPost, u.String(), body)
req, err := http.NewRequest("POST", u.String(), body)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -1525,7 +1525,7 @@ func GetRateLimitCategory(method, path string) RateLimitCategory {

// https://docs.github.com/en/rest/search/search#search-code
case strings.HasPrefix(path, "/search/code") &&
method == http.MethodGet:
method == "GET":
return CodeSearchCategory

case strings.HasPrefix(path, "/search/"):
Expand All @@ -1534,13 +1534,13 @@ func GetRateLimitCategory(method, path string) RateLimitCategory {
return GraphqlCategory
case strings.HasPrefix(path, "/app-manifests/") &&
strings.HasSuffix(path, "/conversions") &&
method == http.MethodPost:
method == "POST":
return IntegrationManifestCategory

// https://docs.github.com/rest/migrations/source-imports#start-an-import
case strings.HasPrefix(path, "/repos/") &&
strings.HasSuffix(path, "/import") &&
method == http.MethodPut:
method == "PUT":
return SourceImportCategory

// https://docs.github.com/rest/code-scanning#upload-an-analysis-as-sarif-data
Expand All @@ -1554,7 +1554,7 @@ func GetRateLimitCategory(method, path string) RateLimitCategory {
// https://docs.github.com/en/rest/dependency-graph/dependency-submission#create-a-snapshot-of-dependencies-for-a-repository
case strings.HasPrefix(path, "/repos/") &&
strings.HasSuffix(path, "/dependency-graph/snapshots") &&
method == http.MethodPost:
method == "POST":
return DependencySnapshotsCategory

// https://docs.github.com/en/enterprise-cloud@latest/rest/orgs/orgs?apiVersion=2022-11-28#get-the-audit-log-for-an-organization
Expand Down
26 changes: 13 additions & 13 deletions github/github_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -646,7 +646,7 @@ func TestNewRequest_errorForNoTrailingSlash(t *testing.T) {
t.Fatalf("url.Parse returned unexpected error: %v.", err)
}
c.BaseURL = u
if _, err := c.NewRequest(http.MethodGet, "test", nil); test.wantError && err == nil {
if _, err := c.NewRequest("GET", "test", nil); test.wantError && err == nil {
t.Fatal("Expected error to be returned.")
} else if !test.wantError && err != nil {
t.Fatalf("NewRequest returned unexpected error: %v.", err)
Expand Down Expand Up @@ -1247,62 +1247,62 @@ func TestDo_rateLimitCategory(t *testing.T) {
category RateLimitCategory
}{
{
method: http.MethodGet,
method: "GET",
url: "/",
category: CoreCategory,
},
{
method: http.MethodGet,
method: "GET",
url: "/search/issues?q=rate",
category: SearchCategory,
},
{
method: http.MethodGet,
method: "GET",
url: "/graphql",
category: GraphqlCategory,
},
{
method: http.MethodPost,
method: "POST",
url: "/app-manifests/code/conversions",
category: IntegrationManifestCategory,
},
{
method: http.MethodGet,
method: "GET",
url: "/app-manifests/code/conversions",
category: CoreCategory, // only POST requests are in the integration manifest category
},
{
method: http.MethodPut,
method: "PUT",
url: "/repos/google/go-github/import",
category: SourceImportCategory,
},
{
method: http.MethodGet,
method: "GET",
url: "/repos/google/go-github/import",
category: CoreCategory, // only PUT requests are in the source import category
},
{
method: http.MethodPost,
method: "POST",
url: "/repos/google/go-github/code-scanning/sarifs",
category: CodeScanningUploadCategory,
},
{
method: http.MethodGet,
method: "GET",
url: "/scim/v2/organizations/ORG/Users",
category: ScimCategory,
},
{
method: http.MethodPost,
method: "POST",
url: "/repos/google/go-github/dependency-graph/snapshots",
category: DependencySnapshotsCategory,
},
{
method: http.MethodGet,
method: "GET",
url: "/search/code?q=rate",
category: CodeSearchCategory,
},
{
method: http.MethodGet,
method: "GET",
url: "/orgs/google/audit-log",
category: AuditLogCategory,
},
Expand Down
5 changes: 2 additions & 3 deletions github/orgs_credential_authorizations.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ package github
import (
"context"
"fmt"
"net/http"
)

// CredentialAuthorization represents a credential authorized through SAML SSO.
Expand Down Expand Up @@ -78,7 +77,7 @@ func (s *OrganizationsService) ListCredentialAuthorizations(ctx context.Context,
return nil, nil, err
}

req, err := s.client.NewRequest(http.MethodGet, u, nil)
req, err := s.client.NewRequest("GET", u, nil)
if err != nil {
return nil, nil, err
}
Expand All @@ -100,7 +99,7 @@ func (s *OrganizationsService) ListCredentialAuthorizations(ctx context.Context,
//meta:operation DELETE /orgs/{org}/credential-authorizations/{credential_id}
func (s *OrganizationsService) RemoveCredentialAuthorization(ctx context.Context, org string, credentialID int64) (*Response, error) {
u := fmt.Sprintf("orgs/%v/credential-authorizations/%v", org, credentialID)
req, err := s.client.NewRequest(http.MethodDelete, u, nil)
req, err := s.client.NewRequest("DELETE", u, nil)
if err != nil {
return nil, err
}
Expand Down
4 changes: 2 additions & 2 deletions github/orgs_credential_authorizations_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ func TestOrganizationsService_ListCredentialAuthorizations(t *testing.T) {
client, mux, _ := setup(t)

mux.HandleFunc("/orgs/o/credential-authorizations", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, http.MethodGet)
testMethod(t, r, "GET")
testFormValues(t, r, values{"per_page": "2", "page": "2", "login": "l"})
fmt.Fprint(w, `[
{
Expand Down Expand Up @@ -77,7 +77,7 @@ func TestOrganizationsService_RemoveCredentialAuthorization(t *testing.T) {
client, mux, _ := setup(t)

mux.HandleFunc("/orgs/o/credential-authorizations/1", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, http.MethodDelete)
testMethod(t, r, "DELETE")
w.WriteHeader(http.StatusNoContent)
})

Expand Down
5 changes: 2 additions & 3 deletions github/orgs_personal_access_tokens.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (
"context"
"errors"
"fmt"
"net/http"
"net/url"
"strings"
)
Expand Down Expand Up @@ -101,7 +100,7 @@ func (s *OrganizationsService) ListFineGrainedPersonalAccessTokens(ctx context.C
return nil, nil, err
}

req, err := s.client.NewRequest(http.MethodGet, u, opts)
req, err := s.client.NewRequest("GET", u, opts)
if err != nil {
return nil, nil, err
}
Expand Down Expand Up @@ -132,7 +131,7 @@ type ReviewPersonalAccessTokenRequestOptions struct {
func (s *OrganizationsService) ReviewPersonalAccessTokenRequest(ctx context.Context, org string, requestID int64, opts ReviewPersonalAccessTokenRequestOptions) (*Response, error) {
u := fmt.Sprintf("orgs/%v/personal-access-token-requests/%v", org, requestID)

req, err := s.client.NewRequest(http.MethodPost, u, &opts)
req, err := s.client.NewRequest("POST", u, &opts)
if err != nil {
return nil, err
}
Expand Down
2 changes: 1 addition & 1 deletion github/orgs_personal_access_tokens_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ func TestOrganizationsService_ReviewPersonalAccessTokenRequest(t *testing.T) {
v := new(ReviewPersonalAccessTokenRequestOptions)
assertNilError(t, json.NewDecoder(r.Body).Decode(v))

testMethod(t, r, http.MethodPost)
testMethod(t, r, "POST")
if !cmp.Equal(v, &input) {
t.Errorf("Request body = %+v, want %+v", v, input)
}
Expand Down
3 changes: 1 addition & 2 deletions github/reactions.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ package github
import (
"context"
"fmt"
"net/http"
)

// ReactionsService provides access to the reactions-related functions in the
Expand Down Expand Up @@ -530,7 +529,7 @@ func (s *ReactionsService) DeleteTeamDiscussionCommentReactionByOrgIDAndTeamID(c
}

func (s *ReactionsService) deleteReaction(ctx context.Context, url string) (*Response, error) {
req, err := s.client.NewRequest(http.MethodDelete, url, nil)
req, err := s.client.NewRequest("DELETE", url, nil)
if err != nil {
return nil, err
}
Expand Down
4 changes: 2 additions & 2 deletions github/repos_contents.go
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ func (s *RepositoriesService) DownloadContents(ctx context.Context, owner, repo,
if contents.GetDownloadURL() == "" {
return nil, resp, fmt.Errorf("no download link found for %s", filepath)
}
dlReq, err := http.NewRequestWithContext(ctx, http.MethodGet, *contents.DownloadURL, nil)
dlReq, err := http.NewRequestWithContext(ctx, "GET", *contents.DownloadURL, nil)
if err != nil {
return nil, resp, err
}
Expand Down Expand Up @@ -206,7 +206,7 @@ func (s *RepositoriesService) DownloadContentsWithMeta(ctx context.Context, owne
if contents.GetDownloadURL() == "" {
return nil, contents, resp, fmt.Errorf("no download link found for %s", filepath)
}
dlReq, err := http.NewRequestWithContext(ctx, http.MethodGet, *contents.DownloadURL, nil)
dlReq, err := http.NewRequestWithContext(ctx, "GET", *contents.DownloadURL, nil)
if err != nil {
return nil, contents, resp, err
}
Expand Down
4 changes: 2 additions & 2 deletions github/repos_hooks_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -575,7 +575,7 @@ func TestRepositoriesService_Subscribe(t *testing.T) {
client, mux, _ := setup(t)

mux.HandleFunc("/hub", func(_ http.ResponseWriter, r *http.Request) {
testMethod(t, r, http.MethodPost)
testMethod(t, r, "POST")
testHeader(t, r, "Content-Type", "application/x-www-form-urlencoded")
testFormValues(t, r, values{
"hub.mode": "subscribe",
Expand Down Expand Up @@ -608,7 +608,7 @@ func TestRepositoriesService_Unsubscribe(t *testing.T) {
client, mux, _ := setup(t)

mux.HandleFunc("/hub", func(_ http.ResponseWriter, r *http.Request) {
testMethod(t, r, http.MethodPost)
testMethod(t, r, "POST")
testHeader(t, r, "Content-Type", "application/x-www-form-urlencoded")
testFormValues(t, r, values{
"hub.mode": "unsubscribe",
Expand Down