Skip to content

Commit 1861a35

Browse files
iulia-bCopilot
andauthored
Upgrade go-github from v82 to v87 (#2452)
Breaking changes addressed: - raw.NewClient: Use WithHTTPClient/WithEnterpriseURLs options, pass ctx to NewRequest, return (*Client, error) - internal/ghmcp/server.go: Use functional options for REST client creation, replace UserAgent field mutation with UserAgentTransport wrapper, add restUATransp field to githubClients struct - pkg/github/dependencies.go: Use functional options for REST client creation, handle raw.NewClient error return - pkg/github/actions.go: Handle new WorkflowDispatchRunDetails return value from CreateWorkflowDispatchEventByID/ByFileName - pkg/github/issues.go: Replace IssueListOptions with ListOptions for SubIssue.ListByIssue - pkg/github/notifications.go: MarkThreadDone now takes string instead of int64; remove ParseInt and strconv import - pkg/github/projects.go: Remove pointer indirection from ListProjectsPaginationOptions and ListProjectsOptions fields - pkg/github/issues_granular.go: Pass ctx to NewRequest, remove ctx from Do - Test files: Add mustNewGHClient helper, replace all NewClient calls, fix stubClientFnFromHTTP signature, fix lockdown_test.go BaseURL handling, fix raw_test.go, remove invalid threadID test case Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent 8a48d07 commit 1861a35

61 files changed

Lines changed: 304 additions & 304 deletions

Some content is hidden

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

e2e/e2e_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import (
1818
"github.com/github/github-mcp-server/internal/ghmcp"
1919
"github.com/github/github-mcp-server/pkg/github"
2020
"github.com/github/github-mcp-server/pkg/translations"
21-
gogithub "github.com/google/go-github/v82/github"
21+
gogithub "github.com/google/go-github/v87/github"
2222
"github.com/modelcontextprotocol/go-sdk/mcp"
2323
"github.com/stretchr/testify/require"
2424
)

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ go 1.25.0
55
require (
66
github.com/go-chi/chi/v5 v5.2.5
77
github.com/go-viper/mapstructure/v2 v2.5.0
8-
github.com/google/go-github/v82 v82.0.0
8+
github.com/google/go-github/v87 v87.0.0
99
github.com/google/jsonschema-go v0.4.2
1010
github.com/josephburnett/jd/v2 v2.5.0
1111
github.com/lithammer/fuzzysearch v1.1.8

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ github.com/golang-jwt/jwt/v5 v5.3.1/go.mod h1:fxCRLWMO43lRc8nhHWY6LGqRcf+1gQWArs
1616
github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
1717
github.com/google/go-cmp v0.7.0 h1:wk8382ETsv4JYUZwIsn6YpYiWiBsYLSJiTsyBybVuN8=
1818
github.com/google/go-cmp v0.7.0/go.mod h1:pXiqmnSA92OHEEa9HXL2W4E7lf9JzCmGVUdgjX3N/iU=
19-
github.com/google/go-github/v82 v82.0.0 h1:OH09ESON2QwKCUVMYmMcVu1IFKFoaZHwqYaUtr/MVfk=
20-
github.com/google/go-github/v82 v82.0.0/go.mod h1:hQ6Xo0VKfL8RZ7z1hSfB4fvISg0QqHOqe9BP0qo+WvM=
19+
github.com/google/go-github/v87 v87.0.0 h1:9Ck3dcOxWJyfsN8tzdah4YvmqB/7ZsstMglv/PkOsl0=
20+
github.com/google/go-github/v87 v87.0.0/go.mod h1:hGUoT5pwm/ck5uLL+wroSVQfg8mpe+buxllCcGV4VaM=
2121
github.com/google/go-querystring v1.2.0 h1:yhqkPbu2/OH+V9BfpCVPZkNmUXhb2gBxJArfhIxNtP0=
2222
github.com/google/go-querystring v1.2.0/go.mod h1:8IFJqpSRITyJ8QhQ13bmbeMBDfmeEJZD5A0egEOmkqU=
2323
github.com/google/jsonschema-go v0.4.2 h1:tmrUohrwoLZZS/P3x7ex0WAVknEkBZM46iALbcqoRA8=

internal/ghmcp/server.go

Lines changed: 32 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -24,18 +24,19 @@ import (
2424
"github.com/github/github-mcp-server/pkg/scopes"
2525
"github.com/github/github-mcp-server/pkg/translations"
2626
"github.com/github/github-mcp-server/pkg/utils"
27-
gogithub "github.com/google/go-github/v82/github"
27+
gogithub "github.com/google/go-github/v87/github"
2828
"github.com/modelcontextprotocol/go-sdk/mcp"
2929
"github.com/shurcooL/githubv4"
3030
)
3131

3232
// githubClients holds all the GitHub API clients created for a server instance.
3333
type githubClients struct {
34-
rest *gogithub.Client
35-
gql *githubv4.Client
36-
gqlHTTP *http.Client // retained for middleware to modify transport
37-
raw *raw.Client
38-
repoAccess *lockdown.RepoAccessCache
34+
rest *gogithub.Client
35+
restUATransp *transport.UserAgentTransport
36+
gql *githubv4.Client
37+
gqlHTTP *http.Client // retained for middleware to modify transport
38+
raw *raw.Client
39+
repoAccess *lockdown.RepoAccessCache
3940
}
4041

4142
// createGitHubClients creates all the GitHub API clients needed by the server.
@@ -61,10 +62,18 @@ func createGitHubClients(cfg github.MCPServerConfig, apiHost utils.APIHostResolv
6162
}
6263

6364
// Construct REST client
64-
restClient := gogithub.NewClient(nil).WithAuthToken(cfg.Token)
65-
restClient.UserAgent = fmt.Sprintf("github-mcp-server/%s", cfg.Version)
66-
restClient.BaseURL = restURL
67-
restClient.UploadURL = uploadURL
65+
restUATransport := &transport.UserAgentTransport{
66+
Transport: http.DefaultTransport,
67+
Agent: fmt.Sprintf("github-mcp-server/%s", cfg.Version),
68+
}
69+
restClient, err := gogithub.NewClient(
70+
gogithub.WithHTTPClient(&http.Client{Transport: restUATransport}),
71+
gogithub.WithAuthToken(cfg.Token),
72+
gogithub.WithEnterpriseURLs(restURL.String(), uploadURL.String()),
73+
)
74+
if err != nil {
75+
return nil, fmt.Errorf("failed to create REST client: %w", err)
76+
}
6877

6978
// Construct GraphQL client
7079
// We use NewEnterpriseClient unconditionally since we already parsed the API host
@@ -80,7 +89,10 @@ func createGitHubClients(cfg github.MCPServerConfig, apiHost utils.APIHostResolv
8089
gqlClient := githubv4.NewEnterpriseClient(graphQLURL.String(), gqlHTTPClient)
8190

8291
// Create raw content client (shares REST client's HTTP transport)
83-
rawClient := raw.NewClient(restClient, rawURL)
92+
rawClient, err := raw.NewClient(restClient, rawURL)
93+
if err != nil {
94+
return nil, fmt.Errorf("failed to create raw client: %w", err)
95+
}
8496

8597
// Set up repo access cache for lockdown mode
8698
var repoAccessCache *lockdown.RepoAccessCache
@@ -95,11 +107,12 @@ func createGitHubClients(cfg github.MCPServerConfig, apiHost utils.APIHostResolv
95107
}
96108

97109
return &githubClients{
98-
rest: restClient,
99-
gql: gqlClient,
100-
gqlHTTP: gqlHTTPClient,
101-
raw: rawClient,
102-
repoAccess: repoAccessCache,
110+
rest: restClient,
111+
restUATransp: restUATransport,
112+
gql: gqlClient,
113+
gqlHTTP: gqlHTTPClient,
114+
raw: rawClient,
115+
repoAccess: repoAccessCache,
103116
}, nil
104117
}
105118

@@ -170,7 +183,7 @@ func NewStdioMCPServer(ctx context.Context, cfg github.MCPServerConfig) (*mcp.Se
170183
github.RegisterUIResources(ghServer)
171184
}
172185

173-
ghServer.AddReceivingMiddleware(addUserAgentsMiddleware(cfg, clients.rest, clients.gqlHTTP))
186+
ghServer.AddReceivingMiddleware(addUserAgentsMiddleware(cfg, clients.restUATransp, clients.gqlHTTP))
174187

175188
return ghServer, nil
176189
}
@@ -345,7 +358,7 @@ func createFeatureChecker(enabledFeatures []string, insidersMode bool) inventory
345358
}
346359
}
347360

348-
func addUserAgentsMiddleware(cfg github.MCPServerConfig, restClient *gogithub.Client, gqlHTTPClient *http.Client) func(next mcp.MethodHandler) mcp.MethodHandler {
361+
func addUserAgentsMiddleware(cfg github.MCPServerConfig, restUATransp *transport.UserAgentTransport, gqlHTTPClient *http.Client) func(next mcp.MethodHandler) mcp.MethodHandler {
349362
return func(next mcp.MethodHandler) mcp.MethodHandler {
350363
return func(ctx context.Context, method string, request mcp.Request) (result mcp.Result, err error) {
351364
if method != "initialize" {
@@ -368,7 +381,7 @@ func addUserAgentsMiddleware(cfg github.MCPServerConfig, restClient *gogithub.Cl
368381
userAgent += " (insiders)"
369382
}
370383

371-
restClient.UserAgent = userAgent
384+
restUATransp.Agent = userAgent
372385

373386
gqlHTTPClient.Transport = &transport.UserAgentTransport{
374387
Transport: gqlHTTPClient.Transport,

pkg/errors/error.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import (
66
"net/http"
77

88
"github.com/github/github-mcp-server/pkg/utils"
9-
"github.com/google/go-github/v82/github"
9+
"github.com/google/go-github/v87/github"
1010
"github.com/modelcontextprotocol/go-sdk/mcp"
1111
)
1212

pkg/errors/error_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import (
66
"net/http"
77
"testing"
88

9-
"github.com/google/go-github/v82/github"
9+
"github.com/google/go-github/v87/github"
1010
"github.com/stretchr/testify/assert"
1111
"github.com/stretchr/testify/require"
1212
)

pkg/github/actions.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import (
1616
"github.com/github/github-mcp-server/pkg/scopes"
1717
"github.com/github/github-mcp-server/pkg/translations"
1818
"github.com/github/github-mcp-server/pkg/utils"
19-
"github.com/google/go-github/v82/github"
19+
"github.com/google/go-github/v87/github"
2020
"github.com/google/jsonschema-go/jsonschema"
2121
"github.com/modelcontextprotocol/go-sdk/mcp"
2222
)
@@ -989,10 +989,10 @@ func runWorkflow(ctx context.Context, client *github.Client, owner, repo, workfl
989989
var workflowType string
990990

991991
if workflowIDInt, parseErr := strconv.ParseInt(workflowID, 10, 64); parseErr == nil {
992-
resp, err = client.Actions.CreateWorkflowDispatchEventByID(ctx, owner, repo, workflowIDInt, event)
992+
_, resp, err = client.Actions.CreateWorkflowDispatchEventByID(ctx, owner, repo, workflowIDInt, event)
993993
workflowType = "workflow_id"
994994
} else {
995-
resp, err = client.Actions.CreateWorkflowDispatchEventByFileName(ctx, owner, repo, workflowID, event)
995+
_, resp, err = client.Actions.CreateWorkflowDispatchEventByFileName(ctx, owner, repo, workflowID, event)
996996
workflowType = "workflow_file"
997997
}
998998

pkg/github/actions_test.go

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import (
88

99
"github.com/github/github-mcp-server/internal/toolsnaps"
1010
"github.com/github/github-mcp-server/pkg/translations"
11-
"github.com/google/go-github/v82/github"
11+
"github.com/google/go-github/v87/github"
1212
"github.com/google/jsonschema-go/jsonschema"
1313
"github.com/stretchr/testify/assert"
1414
"github.com/stretchr/testify/require"
@@ -86,7 +86,7 @@ func Test_ActionsList_ListWorkflows(t *testing.T) {
8686

8787
for _, tc := range tests {
8888
t.Run(tc.name, func(t *testing.T) {
89-
client := github.NewClient(tc.mockedClient)
89+
client := mustNewGHClient(t, tc.mockedClient)
9090
deps := BaseDeps{
9191
Client: client,
9292
}
@@ -136,7 +136,7 @@ func Test_ActionsList_ListWorkflowRuns(t *testing.T) {
136136
}),
137137
})
138138

139-
client := github.NewClient(mockedClient)
139+
client := mustNewGHClient(t, mockedClient)
140140
deps := BaseDeps{
141141
Client: client,
142142
}
@@ -185,7 +185,7 @@ func Test_ActionsList_ListWorkflowRuns(t *testing.T) {
185185
}),
186186
})
187187

188-
client := github.NewClient(mockedClient)
188+
client := mustNewGHClient(t, mockedClient)
189189
deps := BaseDeps{
190190
Client: client,
191191
}
@@ -241,7 +241,7 @@ func Test_ActionsGet_GetWorkflow(t *testing.T) {
241241
}),
242242
})
243243

244-
client := github.NewClient(mockedClient)
244+
client := mustNewGHClient(t, mockedClient)
245245
deps := BaseDeps{
246246
Client: client,
247247
}
@@ -284,7 +284,7 @@ func Test_ActionsGet_GetWorkflowRun(t *testing.T) {
284284
}),
285285
})
286286

287-
client := github.NewClient(mockedClient)
287+
client := mustNewGHClient(t, mockedClient)
288288
deps := BaseDeps{
289289
Client: client,
290290
}
@@ -412,7 +412,7 @@ func Test_ActionsRunTrigger_RunWorkflow(t *testing.T) {
412412

413413
for _, tc := range tests {
414414
t.Run(tc.name, func(t *testing.T) {
415-
client := github.NewClient(tc.mockedClient)
415+
client := mustNewGHClient(t, tc.mockedClient)
416416
deps := BaseDeps{
417417
Client: client,
418418
}
@@ -449,7 +449,7 @@ func Test_ActionsRunTrigger_CancelWorkflowRun(t *testing.T) {
449449
}),
450450
})
451451

452-
client := github.NewClient(mockedClient)
452+
client := mustNewGHClient(t, mockedClient)
453453
deps := BaseDeps{
454454
Client: client,
455455
}
@@ -480,7 +480,7 @@ func Test_ActionsRunTrigger_CancelWorkflowRun(t *testing.T) {
480480
}),
481481
})
482482

483-
client := github.NewClient(mockedClient)
483+
client := mustNewGHClient(t, mockedClient)
484484
deps := BaseDeps{
485485
Client: client,
486486
}
@@ -504,7 +504,7 @@ func Test_ActionsRunTrigger_CancelWorkflowRun(t *testing.T) {
504504
t.Run("missing run_id for non-run_workflow methods", func(t *testing.T) {
505505
mockedClient := MockHTTPClientWithHandlers(map[string]http.HandlerFunc{})
506506

507-
client := github.NewClient(mockedClient)
507+
client := mustNewGHClient(t, mockedClient)
508508
deps := BaseDeps{
509509
Client: client,
510510
}
@@ -556,7 +556,7 @@ func Test_ActionsGetJobLogs_SingleJob(t *testing.T) {
556556
}),
557557
})
558558

559-
client := github.NewClient(mockedClient)
559+
client := mustNewGHClient(t, mockedClient)
560560
deps := BaseDeps{
561561
Client: client,
562562
ContentWindowSize: 5000,
@@ -618,7 +618,7 @@ func Test_ActionsGetJobLogs_FailedJobs(t *testing.T) {
618618
}),
619619
})
620620

621-
client := github.NewClient(mockedClient)
621+
client := mustNewGHClient(t, mockedClient)
622622
deps := BaseDeps{
623623
Client: client,
624624
ContentWindowSize: 5000,
@@ -668,7 +668,7 @@ func Test_ActionsGetJobLogs_FailedJobs(t *testing.T) {
668668
}),
669669
})
670670

671-
client := github.NewClient(mockedClient)
671+
client := mustNewGHClient(t, mockedClient)
672672
deps := BaseDeps{
673673
Client: client,
674674
ContentWindowSize: 5000,

pkg/github/code_scanning.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import (
1111
"github.com/github/github-mcp-server/pkg/scopes"
1212
"github.com/github/github-mcp-server/pkg/translations"
1313
"github.com/github/github-mcp-server/pkg/utils"
14-
"github.com/google/go-github/v82/github"
14+
"github.com/google/go-github/v87/github"
1515
"github.com/google/jsonschema-go/jsonschema"
1616
"github.com/modelcontextprotocol/go-sdk/mcp"
1717
)

pkg/github/code_scanning_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import (
88

99
"github.com/github/github-mcp-server/internal/toolsnaps"
1010
"github.com/github/github-mcp-server/pkg/translations"
11-
"github.com/google/go-github/v82/github"
11+
"github.com/google/go-github/v87/github"
1212
"github.com/google/jsonschema-go/jsonschema"
1313
"github.com/stretchr/testify/assert"
1414
"github.com/stretchr/testify/require"
@@ -80,7 +80,7 @@ func Test_GetCodeScanningAlert(t *testing.T) {
8080
for _, tc := range tests {
8181
t.Run(tc.name, func(t *testing.T) {
8282
// Setup client with mock
83-
client := github.NewClient(tc.mockedClient)
83+
client := mustNewGHClient(t, tc.mockedClient)
8484
deps := BaseDeps{
8585
Client: client,
8686
}
@@ -206,7 +206,7 @@ func Test_ListCodeScanningAlerts(t *testing.T) {
206206
for _, tc := range tests {
207207
t.Run(tc.name, func(t *testing.T) {
208208
// Setup client with mock
209-
client := github.NewClient(tc.mockedClient)
209+
client := mustNewGHClient(t, tc.mockedClient)
210210
deps := BaseDeps{
211211
Client: client,
212212
}

0 commit comments

Comments
 (0)