From 55f3e09b49d21b743b52f3adf8ff1b382257d4ab Mon Sep 17 00:00:00 2001 From: Oleksandr Redko Date: Tue, 21 Jan 2025 12:53:12 +0200 Subject: [PATCH 1/2] refactor: Do not capitalize error strings --- .golangci.yml | 2 ++ github/github.go | 6 +++--- github/github_test.go | 8 ++++---- github/repos_rules.go | 2 +- 4 files changed, 10 insertions(+), 8 deletions(-) diff --git a/.golangci.yml b/.golangci.yml index 288ba4b61d2..eae5a3bdd6a 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -60,6 +60,8 @@ linters-settings: errorf: true strconcat: false revive: + # Set below 0.8 to enable error-strings rule. + confidence: 0.6 rules: - name: blank-imports - name: bool-literal-in-expr diff --git a/github/github.go b/github/github.go index 3d379774e61..60e8b86c40f 100644 --- a/github/github.go +++ b/github/github.go @@ -519,7 +519,7 @@ func WithVersion(version string) RequestOption { // request body. func (c *Client) NewRequest(method, urlStr string, body interface{}, opts ...RequestOption) (*http.Request, error) { if !strings.HasSuffix(c.BaseURL.Path, "/") { - return nil, fmt.Errorf("BaseURL must have a trailing slash, but %q does not", c.BaseURL) + return nil, fmt.Errorf("baseURL must have a trailing slash, but %q does not", c.BaseURL) } u, err := c.BaseURL.Parse(urlStr) @@ -565,7 +565,7 @@ func (c *Client) NewRequest(method, urlStr string, body interface{}, opts ...Req // Body is sent with Content-Type: application/x-www-form-urlencoded. func (c *Client) NewFormRequest(urlStr string, body io.Reader, opts ...RequestOption) (*http.Request, error) { if !strings.HasSuffix(c.BaseURL.Path, "/") { - return nil, fmt.Errorf("BaseURL must have a trailing slash, but %q does not", c.BaseURL) + return nil, fmt.Errorf("baseURL must have a trailing slash, but %q does not", c.BaseURL) } u, err := c.BaseURL.Parse(urlStr) @@ -597,7 +597,7 @@ func (c *Client) NewFormRequest(urlStr string, body io.Reader, opts ...RequestOp // Relative URLs should always be specified without a preceding slash. func (c *Client) NewUploadRequest(urlStr string, reader io.Reader, size int64, mediaType string, opts ...RequestOption) (*http.Request, error) { if !strings.HasSuffix(c.UploadURL.Path, "/") { - return nil, fmt.Errorf("UploadURL must have a trailing slash, but %q does not", c.UploadURL) + return nil, fmt.Errorf("uploadURL must have a trailing slash, but %q does not", c.UploadURL) } u, err := c.UploadURL.Parse(urlStr) if err != nil { diff --git a/github/github_test.go b/github/github_test.go index b3dd0cf10be..7116636b691 100644 --- a/github/github_test.go +++ b/github/github_test.go @@ -2180,7 +2180,7 @@ func TestErrorResponse_Is(t *testing.T) { }, "errors have different types": { wantSame: false, - otherError: errors.New("Github"), + otherError: errors.New("github"), }, } @@ -2250,7 +2250,7 @@ func TestRateLimitError_Is(t *testing.T) { "errors have different types": { wantSame: false, err: err, - otherError: errors.New("Github"), + otherError: errors.New("github"), }, } @@ -2337,7 +2337,7 @@ func TestAbuseRateLimitError_Is(t *testing.T) { "errors have different types": { wantSame: false, err: err, - otherError: errors.New("Github"), + otherError: errors.New("github"), }, } @@ -2369,7 +2369,7 @@ func TestAcceptedError_Is(t *testing.T) { }, "errors have different types": { wantSame: false, - otherError: errors.New("Github"), + otherError: errors.New("github"), }, } diff --git a/github/repos_rules.go b/github/repos_rules.go index 60e9739cdf7..571a789fef4 100644 --- a/github/repos_rules.go +++ b/github/repos_rules.go @@ -567,7 +567,7 @@ func (r *RepositoryRule) UnmarshalJSON(data []byte) error { default: r.Type = "" r.Parameters = nil - return fmt.Errorf("RepositoryRule.Type %q is not yet implemented, unable to unmarshal (%#v)", repositoryRule.Type, repositoryRule) + return fmt.Errorf("repositoryRule.Type %q is not yet implemented, unable to unmarshal (%#v)", repositoryRule.Type, repositoryRule) } return nil From c6417f8d7795d0127816fc1e2c55fe61a0fe7d8e Mon Sep 17 00:00:00 2001 From: Oleksandr Redko Date: Tue, 21 Jan 2025 13:01:03 +0200 Subject: [PATCH 2/2] Fix examples --- example/codespaces/newreposecretwithxcrypto/main.go | 4 ++-- example/codespaces/newusersecretwithxcrypto/main.go | 6 +++--- example/newreposecretwithlibsodium/main.go | 2 +- example/newreposecretwithxcrypto/main.go | 2 +- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/example/codespaces/newreposecretwithxcrypto/main.go b/example/codespaces/newreposecretwithxcrypto/main.go index 485e5b4db26..98f02604377 100644 --- a/example/codespaces/newreposecretwithxcrypto/main.go +++ b/example/codespaces/newreposecretwithxcrypto/main.go @@ -134,7 +134,7 @@ func addRepoSecret(ctx context.Context, client *github.Client, owner string, rep } if _, err := client.Codespaces.CreateOrUpdateRepoSecret(ctx, owner, repo, encryptedSecret); err != nil { - return fmt.Errorf("Codespaces.CreateOrUpdateRepoSecret returned error: %v", err) + return fmt.Errorf("client.Codespaces.CreateOrUpdateRepoSecret returned error: %v", err) } return nil @@ -143,7 +143,7 @@ func addRepoSecret(ctx context.Context, client *github.Client, owner string, rep func encryptSecretWithPublicKey(publicKey *github.PublicKey, secretName string, secretValue string) (*github.EncryptedSecret, error) { decodedPublicKey, err := base64.StdEncoding.DecodeString(publicKey.GetKey()) if err != nil { - return nil, fmt.Errorf("base64.StdEncoding.DecodeString was unable to decode public key: %v", err) + return nil, fmt.Errorf("unable to decode public key: %v", err) } var boxKey [32]byte diff --git a/example/codespaces/newusersecretwithxcrypto/main.go b/example/codespaces/newusersecretwithxcrypto/main.go index b20fc3af888..63cd5a572b9 100644 --- a/example/codespaces/newusersecretwithxcrypto/main.go +++ b/example/codespaces/newusersecretwithxcrypto/main.go @@ -129,17 +129,17 @@ func addUserSecret(ctx context.Context, client *github.Client, secretName, secre } if _, err := client.Codespaces.CreateOrUpdateUserSecret(ctx, encryptedSecret); err != nil { - return fmt.Errorf("Codespaces.CreateOrUpdateUserSecret returned error: %v", err) + return fmt.Errorf("client.Codespaces.CreateOrUpdateUserSecret returned error: %v", err) } if owner != "" && repo != "" { r, _, err := client.Repositories.Get(ctx, owner, repo) if err != nil { - return fmt.Errorf("Repositories.Get returned error: %v", err) + return fmt.Errorf("client.Repositories.Get returned error: %v", err) } _, err = client.Codespaces.AddSelectedRepoToUserSecret(ctx, encryptedSecret.Name, r) if err != nil { - return fmt.Errorf("Codespaces.AddSelectedRepoToUserSecret returned error: %v", err) + return fmt.Errorf("client.Codespaces.AddSelectedRepoToUserSecret returned error: %v", err) } fmt.Printf("Added secret %q to %v/%v\n", secretName, owner, repo) } diff --git a/example/newreposecretwithlibsodium/main.go b/example/newreposecretwithlibsodium/main.go index 9aa14cb5ae6..cae03bb72bc 100644 --- a/example/newreposecretwithlibsodium/main.go +++ b/example/newreposecretwithlibsodium/main.go @@ -130,7 +130,7 @@ func addRepoSecret(ctx context.Context, client *github.Client, owner string, rep } if _, err := client.Actions.CreateOrUpdateRepoSecret(ctx, owner, repo, encryptedSecret); err != nil { - return fmt.Errorf("Actions.CreateOrUpdateRepoSecret returned error: %v", err) + return fmt.Errorf("client.Actions.CreateOrUpdateRepoSecret returned error: %v", err) } return nil diff --git a/example/newreposecretwithxcrypto/main.go b/example/newreposecretwithxcrypto/main.go index 250b8eddd5b..cf42b1c4b0f 100644 --- a/example/newreposecretwithxcrypto/main.go +++ b/example/newreposecretwithxcrypto/main.go @@ -134,7 +134,7 @@ func addRepoSecret(ctx context.Context, client *github.Client, owner string, rep } if _, err := client.Actions.CreateOrUpdateRepoSecret(ctx, owner, repo, encryptedSecret); err != nil { - return fmt.Errorf("Actions.CreateOrUpdateRepoSecret returned error: %v", err) + return fmt.Errorf("client.Actions.CreateOrUpdateRepoSecret returned error: %v", err) } return nil