Skip to content

Commit 9932b6c

Browse files
committed
chore: enable Go code formatters: gci and gofumpt
1 parent 16ff74a commit 9932b6c

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

80 files changed

+302
-229
lines changed

.golangci.yml

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,12 @@ linters:
4141
- -QF1008
4242
- -ST1000
4343
formatters:
44-
exclusions:
45-
generated: lax
46-
paths:
47-
- third_party$
48-
- builtin$
49-
- examples$
44+
enable:
45+
- gci
46+
- gofumpt
47+
settings:
48+
gci:
49+
sections:
50+
- standard
51+
- default
52+
- localmodule

cmd/github-mcp-server/generate_docs.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,12 @@ import (
99
"sort"
1010
"strings"
1111

12+
"github.com/google/jsonschema-go/jsonschema"
13+
"github.com/spf13/cobra"
14+
1215
"github.com/github/github-mcp-server/pkg/github"
1316
"github.com/github/github-mcp-server/pkg/inventory"
1417
"github.com/github/github-mcp-server/pkg/translations"
15-
"github.com/google/jsonschema-go/jsonschema"
16-
"github.com/spf13/cobra"
1718
)
1819

1920
var generateDocsCmd = &cobra.Command{
@@ -81,7 +82,7 @@ func generateReadmeDocs(readmePath string) error {
8182
}
8283

8384
// Write back to file
84-
err = os.WriteFile(readmePath, []byte(updatedContent), 0600)
85+
err = os.WriteFile(readmePath, []byte(updatedContent), 0o600)
8586
if err != nil {
8687
return fmt.Errorf("failed to write README.md: %w", err)
8788
}
@@ -110,7 +111,7 @@ func generateRemoteServerDocs(docsPath string) error {
110111
return err
111112
}
112113

113-
return os.WriteFile(docsPath, []byte(updatedContent), 0600) //#nosec G306
114+
return os.WriteFile(docsPath, []byte(updatedContent), 0o600) //#nosec G306
114115
}
115116

116117
// octiconImg returns an img tag for an Octicon that works with GitHub's light/dark theme.
@@ -436,7 +437,7 @@ func generateDeprecatedAliasesDocs(docsPath string) error {
436437
}
437438

438439
// Write back to file
439-
err = os.WriteFile(docsPath, []byte(updatedContent), 0600)
440+
err = os.WriteFile(docsPath, []byte(updatedContent), 0o600)
440441
if err != nil {
441442
return fmt.Errorf("failed to write deprecated aliases docs: %w", err)
442443
}

cmd/github-mcp-server/list_scopes.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,12 @@ import (
88
"sort"
99
"strings"
1010

11+
"github.com/spf13/cobra"
12+
"github.com/spf13/viper"
13+
1114
"github.com/github/github-mcp-server/pkg/github"
1215
"github.com/github/github-mcp-server/pkg/inventory"
1316
"github.com/github/github-mcp-server/pkg/translations"
14-
"github.com/spf13/cobra"
15-
"github.com/spf13/viper"
1617
)
1718

1819
// ToolScopeInfo contains scope information for a single tool.

cmd/github-mcp-server/main.go

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,21 @@ import (
77
"strings"
88
"time"
99

10-
"github.com/github/github-mcp-server/internal/ghmcp"
11-
"github.com/github/github-mcp-server/pkg/github"
12-
ghhttp "github.com/github/github-mcp-server/pkg/http"
1310
"github.com/spf13/cobra"
1411
"github.com/spf13/pflag"
1512
"github.com/spf13/viper"
13+
14+
"github.com/github/github-mcp-server/internal/ghmcp"
15+
"github.com/github/github-mcp-server/pkg/github"
16+
ghhttp "github.com/github/github-mcp-server/pkg/http"
1617
)
1718

1819
// These variables are set by the build process using ldflags.
19-
var version = "version"
20-
var commit = "commit"
21-
var date = "date"
20+
var (
21+
version = "version"
22+
commit = "commit"
23+
date = "date"
24+
)
2225

2326
var (
2427
rootCmd = &cobra.Command{

e2e/e2e_test.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,13 @@ import (
1515
"testing"
1616
"time"
1717

18-
"github.com/github/github-mcp-server/internal/ghmcp"
19-
"github.com/github/github-mcp-server/pkg/github"
20-
"github.com/github/github-mcp-server/pkg/translations"
2118
gogithub "github.com/google/go-github/v82/github"
2219
"github.com/modelcontextprotocol/go-sdk/mcp"
2320
"github.com/stretchr/testify/require"
21+
22+
"github.com/github/github-mcp-server/internal/ghmcp"
23+
"github.com/github/github-mcp-server/pkg/github"
24+
"github.com/github/github-mcp-server/pkg/translations"
2425
)
2526

2627
var (
@@ -277,7 +278,6 @@ func TestGetMe(t *testing.T) {
277278
user, _, err := ghClient.Users.Get(context.Background(), "")
278279
require.NoError(t, err, "expected to get user successfully")
279280
require.Equal(t, trimmedContent.Login, *user.Login, "expected login to match")
280-
281281
}
282282

283283
func TestToolsets(t *testing.T) {
@@ -296,7 +296,7 @@ func TestToolsets(t *testing.T) {
296296
// We could enumerate the tools here, but we'll need to expose that information
297297
// declaratively in the MCP server, so for the moment let's just check the existence
298298
// of an issue and repo tool, and the non-existence of a pull_request tool.
299-
var toolsContains = func(expectedName string) bool {
299+
toolsContains := func(expectedName string) bool {
300300
return slices.ContainsFunc(response.Tools, func(tool *mcp.Tool) bool {
301301
return tool.Name == expectedName
302302
})

internal/ghmcp/server.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@ import (
1212
"syscall"
1313
"time"
1414

15+
gogithub "github.com/google/go-github/v82/github"
16+
"github.com/modelcontextprotocol/go-sdk/mcp"
17+
"github.com/shurcooL/githubv4"
18+
1519
"github.com/github/github-mcp-server/pkg/errors"
1620
"github.com/github/github-mcp-server/pkg/github"
1721
"github.com/github/github-mcp-server/pkg/http/transport"
@@ -22,9 +26,6 @@ import (
2226
"github.com/github/github-mcp-server/pkg/scopes"
2327
"github.com/github/github-mcp-server/pkg/translations"
2428
"github.com/github/github-mcp-server/pkg/utils"
25-
gogithub "github.com/google/go-github/v82/github"
26-
"github.com/modelcontextprotocol/go-sdk/mcp"
27-
"github.com/shurcooL/githubv4"
2829
)
2930

3031
// githubClients holds all the GitHub API clients created for a server instance.
@@ -235,7 +236,7 @@ func RunStdioServer(cfg StdioServerConfig) error {
235236
var slogHandler slog.Handler
236237
var logOutput io.Writer
237238
if cfg.LogFilePath != "" {
238-
file, err := os.OpenFile(cfg.LogFilePath, os.O_CREATE|os.O_WRONLY|os.O_APPEND, 0600)
239+
file, err := os.OpenFile(cfg.LogFilePath, os.O_CREATE|os.O_WRONLY|os.O_APPEND, 0o600)
239240
if err != nil {
240241
return fmt.Errorf("failed to open log file: %w", err)
241242
}

internal/profiler/profiler.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,12 @@ package profiler
33
import (
44
"context"
55
"fmt"
6+
"log/slog"
7+
"math"
68
"os"
79
"runtime"
810
"strconv"
911
"time"
10-
11-
"log/slog"
12-
"math"
1312
)
1413

1514
// Profile represents performance metrics for an operation

internal/toolsnaps/toolsnaps.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,12 +76,12 @@ func writeSnap(snapPath string, contents []byte) error {
7676
}
7777

7878
// Ensure the directory exists
79-
if err := os.MkdirAll(filepath.Dir(snapPath), 0700); err != nil {
79+
if err := os.MkdirAll(filepath.Dir(snapPath), 0o700); err != nil {
8080
return fmt.Errorf("failed to create snapshot directory: %w", err)
8181
}
8282

8383
// Write the snapshot file
84-
if err := os.WriteFile(snapPath, sortedJSON, 0600); err != nil {
84+
if err := os.WriteFile(snapPath, sortedJSON, 0o600); err != nil {
8585
return fmt.Errorf("failed to write snapshot file: %w", err)
8686
}
8787

internal/toolsnaps/toolsnaps_test.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,8 @@ func TestSnapshotExistsMatch(t *testing.T) {
6565
// Given a matching snapshot file exists
6666
tool := dummyTool{"foo", 42}
6767
b, _ := json.MarshalIndent(tool, "", " ")
68-
require.NoError(t, os.MkdirAll("__toolsnaps__", 0700))
69-
require.NoError(t, os.WriteFile(filepath.Join("__toolsnaps__", "dummy.snap"), b, 0600))
68+
require.NoError(t, os.MkdirAll("__toolsnaps__", 0o700))
69+
require.NoError(t, os.WriteFile(filepath.Join("__toolsnaps__", "dummy.snap"), b, 0o600))
7070

7171
// When we test the snapshot
7272
err := Test("dummy", tool)
@@ -82,8 +82,8 @@ func TestSnapshotExistsDiff(t *testing.T) {
8282
t.Setenv("UPDATE_TOOLSNAPS", "false")
8383

8484
// Given a non-matching snapshot file exists
85-
require.NoError(t, os.MkdirAll("__toolsnaps__", 0700))
86-
require.NoError(t, os.WriteFile(filepath.Join("__toolsnaps__", "dummy.snap"), []byte(`{"name":"foo","value":1}`), 0600))
85+
require.NoError(t, os.MkdirAll("__toolsnaps__", 0o700))
86+
require.NoError(t, os.WriteFile(filepath.Join("__toolsnaps__", "dummy.snap"), []byte(`{"name":"foo","value":1}`), 0o600))
8787
tool := dummyTool{"foo", 2}
8888

8989
// When we test the snapshot
@@ -99,8 +99,8 @@ func TestUpdateToolsnaps(t *testing.T) {
9999

100100
// Given UPDATE_TOOLSNAPS is set, regardless of whether a matching snapshot file exists
101101
t.Setenv("UPDATE_TOOLSNAPS", "true")
102-
require.NoError(t, os.MkdirAll("__toolsnaps__", 0700))
103-
require.NoError(t, os.WriteFile(filepath.Join("__toolsnaps__", "dummy.snap"), []byte(`{"name":"foo","value":1}`), 0600))
102+
require.NoError(t, os.MkdirAll("__toolsnaps__", 0o700))
103+
require.NoError(t, os.WriteFile(filepath.Join("__toolsnaps__", "dummy.snap"), []byte(`{"name":"foo","value":1}`), 0o600))
104104
tool := dummyTool{"foo", 42}
105105

106106
// When we test the snapshot
@@ -120,8 +120,8 @@ func TestMalformedSnapshotJSON(t *testing.T) {
120120
t.Setenv("UPDATE_TOOLSNAPS", "false")
121121

122122
// Given a malformed snapshot file exists
123-
require.NoError(t, os.MkdirAll("__toolsnaps__", 0700))
124-
require.NoError(t, os.WriteFile(filepath.Join("__toolsnaps__", "dummy.snap"), []byte(`not-json`), 0600))
123+
require.NoError(t, os.MkdirAll("__toolsnaps__", 0o700))
124+
require.NoError(t, os.WriteFile(filepath.Join("__toolsnaps__", "dummy.snap"), []byte(`not-json`), 0o600))
125125
tool := dummyTool{"foo", 42}
126126

127127
// When we test the snapshot

pkg/errors/error.go

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,10 @@ import (
55
"fmt"
66
"net/http"
77

8-
"github.com/github/github-mcp-server/pkg/utils"
98
"github.com/google/go-github/v82/github"
109
"github.com/modelcontextprotocol/go-sdk/mcp"
10+
11+
"github.com/github/github-mcp-server/pkg/utils"
1112
)
1213

1314
type GitHubAPIError struct {
@@ -63,12 +64,14 @@ func (e *GitHubRawAPIError) Error() string {
6364
return fmt.Errorf("%s: %w", e.Message, e.Err).Error()
6465
}
6566

66-
type GitHubErrorKey struct{}
67-
type GitHubCtxErrors struct {
68-
api []*GitHubAPIError
69-
graphQL []*GitHubGraphQLError
70-
raw []*GitHubRawAPIError
71-
}
67+
type (
68+
GitHubErrorKey struct{}
69+
GitHubCtxErrors struct {
70+
api []*GitHubAPIError
71+
graphQL []*GitHubGraphQLError
72+
raw []*GitHubRawAPIError
73+
}
74+
)
7275

7376
// ContextWithGitHubErrors updates or creates a context with a pointer to GitHub error information (to be used by middleware).
7477
func ContextWithGitHubErrors(ctx context.Context) context.Context {

0 commit comments

Comments
 (0)