From 07e24668f8708a143bdbec700c20f5e6c4942e28 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 12 Oct 2026 16:08:51 +0200 Subject: [PATCH 1/6] build(deps): bump @modelcontextprotocol/client in /ui (#3462) Bumps [@modelcontextprotocol/client](https://github.com/modelcontextprotocol/typescript-sdk) from 2.2.0 to 2.3.1. - [Release notes](https://github.com/modelcontextprotocol/typescript-sdk/releases) - [Commits](https://github.com/modelcontextprotocol/typescript-sdk/compare/@modelcontextprotocol/client@2.2.0...@modelcontextprotocol/client@2.3.1) --- updated-dependencies: - dependency-name: "@modelcontextprotocol/client" dependency-version: 2.3.1 dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- ui/package-lock.json | 22 +++++++++++----------- ui/package.json | 2 +- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/ui/package-lock.json b/ui/package-lock.json index 4211483e2b..04d7b8bb68 100644 --- a/ui/package-lock.json +++ b/ui/package-lock.json @@ -9,7 +9,7 @@ "version": "1.0.0", "dependencies": { "@github/markdown-toolbar-element": "^2.2.3", - "@modelcontextprotocol/client": "^2.0.0", + "@modelcontextprotocol/client": "^2.3.1", "@modelcontextprotocol/ext-apps": "^2.0.3", "@primer/octicons-react": "^19.38.0", "@primer/primitives": "^11.10.0", @@ -73,15 +73,15 @@ "license": "BSD-3-Clause" }, "node_modules/@modelcontextprotocol/client": { - "version": "2.2.0", - "resolved": "https://registry.npmjs.org/@modelcontextprotocol/client/-/client-2.2.0.tgz", - "integrity": "sha512-LxCou/CSYQ6dwEnjhLZY0KnEuc8V4UJ3IEQCl/uR2yHobSQIEdJKUlKLRYRF5i5FqRGHy1eK7une3aAWDHLtig==", - "license": "MIT", + "version": "2.3.1", + "resolved": "https://registry.npmjs.org/@modelcontextprotocol/client/-/client-2.3.1.tgz", + "integrity": "sha512-mIGZXpHsjnZ6lD+gD/WCMpR5k8yVQQ8nNFH1N0Srf7AvnwTUMYD6pvTY8ng2+He5FfV7YMZLmrjL7cLa/cc3dQ==", + "license": "Apache-2.0", "dependencies": { - "@modelcontextprotocol/core": "2.2.0", + "@modelcontextprotocol/core": "2.3.1", "cross-spawn": "^7.0.5", "eventsource": "^3.0.2", - "eventsource-parser": "^3.0.0", + "eventsource-parser": "^3.0.8", "jose": "^6.1.3", "pkce-challenge": "^5.0.0", "zod": "^4.2.0" @@ -91,10 +91,10 @@ } }, "node_modules/@modelcontextprotocol/core": { - "version": "2.2.0", - "resolved": "https://registry.npmjs.org/@modelcontextprotocol/core/-/core-2.2.0.tgz", - "integrity": "sha512-iLhmprRmWI8EcosOA3wVvww22z02NkgqhV4fBH6f/odQBsi7xnJc0HGmi21yWO+/iKw2yzqVE127Zhna5/+JXw==", - "license": "MIT", + "version": "2.3.1", + "resolved": "https://registry.npmjs.org/@modelcontextprotocol/core/-/core-2.3.1.tgz", + "integrity": "sha512-laVmIhPGpWi7rG9q+0UigblRN0Hws/Yjlb6qLFtVqryXVLkc4h+yN8z731POD2LnAGQlFe7/tXhUm7Bi0YB91g==", + "license": "Apache-2.0", "dependencies": { "zod": "^4.2.0" }, diff --git a/ui/package.json b/ui/package.json index 039cd12b0c..7c167f57de 100644 --- a/ui/package.json +++ b/ui/package.json @@ -16,7 +16,7 @@ }, "dependencies": { "@github/markdown-toolbar-element": "^2.2.3", - "@modelcontextprotocol/client": "^2.0.0", + "@modelcontextprotocol/client": "^2.3.1", "@modelcontextprotocol/ext-apps": "^2.0.3", "@primer/octicons-react": "^19.38.0", "@primer/primitives": "^11.10.0", From f727c8b07b393bca6e62e14c905fda403d65c64a Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Tue, 13 Oct 2026 14:38:12 +0200 Subject: [PATCH 2/6] build(deps-dev): bump @vitejs/plugin-react from 6.1.1 to 6.1.2 in /ui (#3461) Bumps [@vitejs/plugin-react](https://github.com/vitejs/vite-plugin-react/tree/HEAD/packages/plugin-react) from 6.1.1 to 6.1.2. - [Release notes](https://github.com/vitejs/vite-plugin-react/releases) - [Changelog](https://github.com/vitejs/vite-plugin-react/blob/main/packages/plugin-react/CHANGELOG.md) - [Commits](https://github.com/vitejs/vite-plugin-react/commits/plugin-react@6.1.2/packages/plugin-react) --- updated-dependencies: - dependency-name: "@vitejs/plugin-react" dependency-version: 6.1.2 dependency-type: direct:development update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- ui/package-lock.json | 10 +++++----- ui/package.json | 2 +- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/ui/package-lock.json b/ui/package-lock.json index 04d7b8bb68..39ab143490 100644 --- a/ui/package-lock.json +++ b/ui/package-lock.json @@ -24,7 +24,7 @@ "@types/node": "^26.6.4", "@types/react": "^19.3.0", "@types/react-dom": "^19.3.0", - "@vitejs/plugin-react": "^6.1.1", + "@vitejs/plugin-react": "^6.1.2", "typescript": "^7.0.2", "vite": "^8.3.2", "vite-plugin-singlefile": "^2.3.3" @@ -960,9 +960,9 @@ "license": "ISC" }, "node_modules/@vitejs/plugin-react": { - "version": "6.1.1", - "resolved": "https://registry.npmjs.org/@vitejs/plugin-react/-/plugin-react-6.1.1.tgz", - "integrity": "sha512-yxLaQV9gkhS8ezJqCM6+ndU7mDY6gqAg75NQ+0IjwEI8IYOmQCgkRwHKVSfWXW076DsqMo0Dk+0FK1U+M5RgFw==", + "version": "6.1.2", + "resolved": "https://registry.npmjs.org/@vitejs/plugin-react/-/plugin-react-6.1.2.tgz", + "integrity": "sha512-fhJNGUdscQa4HkI0xFxwonWyhnVReCPDbXI7FH7jmzpnVCrFQI7PRrhWecO263610vOrs9tr2Y4xcf8uAdFxbw==", "dev": true, "license": "MIT", "dependencies": { @@ -974,7 +974,7 @@ "peerDependencies": { "@rolldown/plugin-babel": "^0.1.7 || ^0.2.0", "babel-plugin-react-compiler": "^1.0.0", - "oxc-transform-react": "^0.145.0", + "oxc-transform-react": "^0.152.0", "vite": "^8.0.0" }, "peerDependenciesMeta": { diff --git a/ui/package.json b/ui/package.json index 7c167f57de..96626e241c 100644 --- a/ui/package.json +++ b/ui/package.json @@ -31,7 +31,7 @@ "@types/node": "^26.6.4", "@types/react": "^19.3.0", "@types/react-dom": "^19.3.0", - "@vitejs/plugin-react": "^6.1.1", + "@vitejs/plugin-react": "^6.1.2", "typescript": "^7.0.2", "vite": "^8.3.2", "vite-plugin-singlefile": "^2.3.3" From c59e8c199efbf14467211861de44afaeeb6873e3 Mon Sep 17 00:00:00 2001 From: lorenzozane Date: Tue, 13 Oct 2026 20:47:01 +0800 Subject: [PATCH 3/6] fix: encode repository resource URIs as UTF-8 (#3437) Co-authored-by: Iryna Kulakova <52420926+IrynaKulakova@users.noreply.github.com> --- pkg/github/repositories_test.go | 61 ++++++++++++++ pkg/github/repository_resource.go | 106 ++++++++++++++++++------- pkg/github/repository_resource_test.go | 86 ++++++++++++++++++++ 3 files changed, 225 insertions(+), 28 deletions(-) diff --git a/pkg/github/repositories_test.go b/pkg/github/repositories_test.go index a054de6db7..8679df8191 100644 --- a/pkg/github/repositories_test.go +++ b/pkg/github/repositories_test.go @@ -582,6 +582,67 @@ func Test_GetFileContents(t *testing.T) { } } +func Test_GetFileContents_UsesUTF8ResourceURI(t *testing.T) { + content := []byte("package example") + sha := strings.Repeat("a", 40) + result, _ := runRepositoryReadFixture(t, repositoryReadFixture{ + contents: &github.RepositoryContent{ + Name: new("Þfoo.go"), + Path: new("test/Þfoo.go"), + SHA: new(gitBlobSHA(content)), + Type: new("file"), + Content: new(string(content)), + Size: new(len(content)), + }, + }, map[string]any{ + "owner": "owner", + "repo": "repo", + "path": "test/Þfoo.go", + "sha": sha, + }) + + resource := getResourceResult(t, result) + require.Equal(t, "repo://owner/repo/sha/"+sha+"/contents/test/%C3%9Efoo.go", resource.URI) +} + +func Test_GetFileContents_LargeFileUsesUTF8ResourceURI(t *testing.T) { + sha := strings.Repeat("a", 40) + result, _ := runRepositoryReadFixture(t, repositoryReadFixture{ + contents: &github.RepositoryContent{ + Name: new("Þlarge.bin"), + Path: new("test/Þlarge.bin"), + SHA: new(sha), + Type: new("file"), + Size: new(2 * 1024 * 1024), + DownloadURL: new("https://raw.example.com/owner/repo/" + sha + "/test/%C3%9Elarge.bin"), + }, + trees: map[string]*github.Tree{ + sha: {Entries: []*github.TreeEntry{{ + Path: new("test"), + Mode: new("040000"), + Type: new("tree"), + SHA: new("b"), + }}}, + "b": {Entries: []*github.TreeEntry{{ + Path: new("Þlarge.bin"), + Mode: new("100644"), + Type: new("blob"), + SHA: new(sha), + }}}, + }, + }, map[string]any{ + "owner": "owner", + "repo": "repo", + "path": "test/Þlarge.bin", + "sha": sha, + }) + + require.Len(t, result.Content, 2) + resource, ok := result.Content[1].(*mcp.ResourceLink) + require.True(t, ok) + require.Equal(t, "repo://owner/repo/sha/"+sha+"/contents/test/%C3%9Elarge.bin", resource.URI) +} + func Test_GetFileContents_SymlinkDisclosure(t *testing.T) { commitSHA := strings.Repeat("c", 40) args := func(path string) map[string]any { diff --git a/pkg/github/repository_resource.go b/pkg/github/repository_resource.go index f7e8410146..8141e2f0f6 100644 --- a/pkg/github/repository_resource.go +++ b/pkg/github/repository_resource.go @@ -10,6 +10,7 @@ import ( "path/filepath" "strconv" "strings" + "unicode/utf8" "github.com/github/github-mcp-server/v2/pkg/inventory" "github.com/github/github-mcp-server/v2/pkg/octicons" @@ -247,53 +248,102 @@ func RepositoryResourceContentsHandler(resourceURITemplate *uritemplate.Template } } -// expandRepoResourceURI builds a resource URI using the appropriate URI template -// based on the provided parameters (sha, ref, or default). +func escapeRepoResourceURIComponent(value string) (string, error) { + if !utf8.ValidString(value) { + return "", errors.New("invalid UTF-8 in repository resource URI") + } + + const hex = "0123456789ABCDEF" + var escaped strings.Builder + escaped.Grow(len(value)) + for i := range len(value) { + b := value[i] + if (b >= 'a' && b <= 'z') || (b >= 'A' && b <= 'Z') || + (b >= '0' && b <= '9') || b == '-' || b == '.' || b == '_' || b == '~' { + escaped.WriteByte(b) + continue + } + escaped.WriteByte('%') + escaped.WriteByte(hex[b>>4]) + escaped.WriteByte(hex[b&0x0f]) + } + return escaped.String(), nil +} + func expandRepoResourceURI(owner, repo, sha, ref string, pathParts []string) (string, error) { - baseValues := uritemplate.Values{ - "owner": uritemplate.String(owner), - "repo": uritemplate.String(repo), - "path": uritemplate.List(pathParts...), + owner, err := escapeRepoResourceURIComponent(owner) + if err != nil { + return "", err + } + repo, err = escapeRepoResourceURIComponent(repo) + if err != nil { + return "", err + } + + path := make([]string, len(pathParts)) + for i, part := range pathParts { + path[i], err = escapeRepoResourceURIComponent(part) + if err != nil { + return "", err + } + } + + base := "repo://" + owner + "/" + repo + withPath := func(uri string) string { + uri += "/contents" + if len(path) > 0 { + uri += "/" + strings.Join(path, "/") + } + return uri } switch { case sha != "": - baseValues["sha"] = uritemplate.String(sha) - return repositoryResourceCommitContentURITemplate.Expand(baseValues) + sha, err = escapeRepoResourceURIComponent(sha) + if err != nil { + return "", err + } + return withPath(base + "/sha/" + sha), nil case ref != "": - // Parse ref to determine which template to use switch { case strings.HasPrefix(ref, "refs/heads/"): - branch := strings.TrimPrefix(ref, "refs/heads/") - baseValues["branch"] = uritemplate.String(branch) - return repositoryResourceBranchContentURITemplate.Expand(baseValues) + branch, err := escapeRepoResourceURIComponent(strings.TrimPrefix(ref, "refs/heads/")) + if err != nil { + return "", err + } + return withPath(base + "/refs/heads/" + branch), nil case strings.HasPrefix(ref, "refs/tags/"): - tag := strings.TrimPrefix(ref, "refs/tags/") - baseValues["tag"] = uritemplate.String(tag) - return repositoryResourceTagContentURITemplate.Expand(baseValues) + tag, err := escapeRepoResourceURIComponent(strings.TrimPrefix(ref, "refs/tags/")) + if err != nil { + return "", err + } + return withPath(base + "/refs/tags/" + tag), nil case strings.HasPrefix(ref, "refs/pull/") && strings.HasSuffix(ref, "/head"): - // Extract PR number from "refs/pull/{number}/head" - prPart := strings.TrimPrefix(ref, "refs/pull/") - prNumber := strings.TrimSuffix(prPart, "/head") - baseValues["prNumber"] = uritemplate.String(prNumber) - return repositoryResourcePrContentURITemplate.Expand(baseValues) + prNumber, err := escapeRepoResourceURIComponent(strings.TrimSuffix(strings.TrimPrefix(ref, "refs/pull/"), "/head")) + if err != nil { + return "", err + } + return withPath(base + "/refs/pull/" + prNumber + "/head"), nil case looksLikeSHA(ref): - // ref is actually a SHA (e.g., from resolveGitReference) - baseValues["sha"] = uritemplate.String(ref) - return repositoryResourceCommitContentURITemplate.Expand(baseValues) + sha, err := escapeRepoResourceURIComponent(ref) + if err != nil { + return "", err + } + return withPath(base + "/sha/" + sha), nil default: - // For other refs (like a branch name without refs/heads/ prefix), - // treat it as a branch - baseValues["branch"] = uritemplate.String(ref) - return repositoryResourceBranchContentURITemplate.Expand(baseValues) + branch, err := escapeRepoResourceURIComponent(ref) + if err != nil { + return "", err + } + return withPath(base + "/refs/heads/" + branch), nil } default: - return repositoryResourceContentURITemplate.Expand(baseValues) + return withPath(base), nil } } diff --git a/pkg/github/repository_resource_test.go b/pkg/github/repository_resource_test.go index 900842b9bb..8ef31fda90 100644 --- a/pkg/github/repository_resource_test.go +++ b/pkg/github/repository_resource_test.go @@ -32,6 +32,92 @@ const ( resourceResponseTypeText ) +func TestExpandRepoResourceURIUsesUTF8PercentEncoding(t *testing.T) { + sha := strings.Repeat("a", 40) + tests := []struct { + name string + sha string + ref string + path []string + expected string + }{ + { + name: "sha path", + sha: sha, + path: []string{"test", "Þfoo.go"}, + expected: "repo://owner/repo/sha/" + sha + + "/contents/test/%C3%9Efoo.go", + }, + { + name: "branch path", + ref: "refs/heads/main", + path: []string{"ملف.txt"}, + expected: "repo://owner/repo/refs/heads/main/contents/" + + "%D9%85%D9%84%D9%81.txt", + }, + { + name: "unicode branch and path", + ref: "refs/heads/分支", + path: []string{"日本語 ファイル.md"}, + expected: "repo://owner/repo/refs/heads/%E5%88%86%E6%94%AF/contents/" + + "%E6%97%A5%E6%9C%AC%E8%AA%9E%20%E3%83%95%E3%82%A1%E3%82%A4%E3%83%AB.md", + }, + { + name: "unicode tag", + ref: "refs/tags/v1-Þ", + path: []string{"README.md"}, + expected: "repo://owner/repo/refs/tags/v1-%C3%9E/contents/README.md", + }, + { + name: "pull request ref", + ref: "refs/pull/42/head", + path: []string{"𝄞.txt"}, + expected: "repo://owner/repo/refs/pull/42/head/contents/%F0%9D%84%9E.txt", + }, + { + name: "reserved path characters", + path: []string{"a%b", "query?value"}, + expected: "repo://owner/repo/contents/a%25b/query%3Fvalue", + }, + { + name: "ascii path remains unchanged", + path: []string{"docs", "README.md"}, + expected: "repo://owner/repo/contents/docs/README.md", + }, + } + + for _, tc := range tests { + t.Run(tc.name, func(t *testing.T) { + actual, err := expandRepoResourceURI("owner", "repo", tc.sha, tc.ref, tc.path) + require.NoError(t, err) + require.Equal(t, tc.expected, actual) + }) + } +} + +func TestRepositoryResourceContentsDecodesUTF8Path(t *testing.T) { + base, _ := url.Parse("https://raw.example.com/") + sha := strings.Repeat("a", 40) + client := mustNewGHClient(t, MockHTTPClientWithHandlers(map[string]http.HandlerFunc{ + GetRawReposContentsByOwnerByRepoBySHAByPath: func(w http.ResponseWriter, r *http.Request) { + require.True(t, strings.HasSuffix(r.URL.Path, "/test/Þfoo.go")) + w.Header().Set("Content-Type", "text/plain") + _, err := w.Write([]byte("package x")) + require.NoError(t, err) + }, + })) + rawClient, err := raw.NewClient(client, base) + require.NoError(t, err) + ctx := ContextWithDeps(context.Background(), BaseDeps{Client: client, RawClient: rawClient}) + handler := RepositoryResourceContentsHandler(repositoryResourceCommitContentURITemplate) + + result, err := handler(ctx, &mcp.ReadResourceRequest{Params: &mcp.ReadResourceParams{ + URI: "repo://owner/repo/sha/" + sha + "/contents/test/%C3%9Efoo.go", + }}) + require.NoError(t, err) + require.Equal(t, "package x", result.Contents[0].Text) +} + func Test_repositoryResourceContents(t *testing.T) { base, _ := url.Parse("https://raw.example.com/") tests := []struct { From 796afb74711ddc856fe587debc49373e21c8d0f7 Mon Sep 17 00:00:00 2001 From: Jay Hemnani <193022578+jayhemnani9910@users.noreply.github.com> Date: Thu, 15 Oct 2026 16:05:06 +0530 Subject: [PATCH 4/6] fix(repos): return a resource link for files over 1 MB in get_file_contents (#3419) The Contents API returns files over 1 MB with an empty content field and encoding "none". Since the symlink read checks, get_file_contents tried to decode that content and failed with "unsupported content encoding: none" before reaching the large-file branch. Treat that response as content not available so the tool returns the resource link again. Co-authored-by: Iryna Kulakova <52420926+IrynaKulakova@users.noreply.github.com> --- pkg/github/repositories_helper.go | 3 ++- pkg/github/repositories_test.go | 16 ++++++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/pkg/github/repositories_helper.go b/pkg/github/repositories_helper.go index 62a4fcf755..fe1983252c 100644 --- a/pkg/github/repositories_helper.go +++ b/pkg/github/repositories_helper.go @@ -214,7 +214,8 @@ func inspectRepositoryFile(ctx context.Context, client *github.Client, owner, re } func repositoryContentBytes(file *github.RepositoryContent) ([]byte, bool, error) { - if file.Content == nil { + // Files over 1 MB come back with encoding "none" and no content. + if file.Content == nil || file.GetEncoding() == "none" { return []byte{}, file.GetType() != "symlink" && file.GetSize() == 0, nil } content, err := file.GetContent() diff --git a/pkg/github/repositories_test.go b/pkg/github/repositories_test.go index 8679df8191..966390b920 100644 --- a/pkg/github/repositories_test.go +++ b/pkg/github/repositories_test.go @@ -795,6 +795,22 @@ func Test_GetFileContents_ContentlessRequestCounts(t *testing.T) { require.True(t, ok) }) + t.Run("large file with encoding none", func(t *testing.T) { + result, requests := runRepositoryReadFixture(t, repositoryReadFixture{ + contents: &github.RepositoryContent{ + Type: new("file"), Path: new("large.bin"), SHA: new(fileSHA), Size: new(largeSize), + Content: new(""), Encoding: new("none"), + }, + trees: map[string]*github.Tree{commitSHA: {Entries: []*github.TreeEntry{ + {Path: new("large.bin"), Mode: new("100644"), Type: new("blob"), SHA: new(fileSHA)}, + }}}, + }, args("large.bin")) + require.False(t, result.IsError) + assert.Equal(t, 2, requests) + _, ok := result.Content[1].(*mcp.ResourceLink) + require.True(t, ok) + }) + t.Run("internal large link uses exact-path tree descent", func(t *testing.T) { target := "../target.bin" linkSHA := gitBlobSHA([]byte(target)) From e3809fe91c7546633241006bf0b91f23b2595e28 Mon Sep 17 00:00:00 2001 From: Andrew Georgiou Date: Thu, 15 Oct 2026 22:16:37 +0100 Subject: [PATCH 5/6] Add cursor pagination to list_label (#3505) * Return every label from list_label instead of the first 100 Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: d8a9000c-ebe8-4118-ae89-a942861e4166 * Page list_label with cursors instead of fetching every label Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: d8a9000c-ebe8-4118-ae89-a942861e4166 * Match list_issues wording in the list_label description Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: d8a9000c-ebe8-4118-ae89-a942861e4166 --------- Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: d8a9000c-ebe8-4118-ae89-a942861e4166 --- README.md | 2 + pkg/github/__toolsnaps__/list_label.snap | 37 ++++- pkg/github/labels.go | 43 +++++- pkg/github/labels_test.go | 148 ++++++++++++++------ pkg/github/typed_governance_outputs.go | 5 +- pkg/github/typed_governance_outputs_test.go | 4 +- 6 files changed, 184 insertions(+), 55 deletions(-) diff --git a/README.md b/README.md index 6413b58760..432541f434 100644 --- a/README.md +++ b/README.md @@ -1126,7 +1126,9 @@ For negotiated supported protocol versions `2026-07-28` or newer, the consolidat - **list_label** - List labels from a repository - **OAuth Challenge Scopes**: `repo` + - `after`: Cursor for pagination. Use the cursor from the previous response. (string, optional) - `owner`: Repository owner (username or organization name) - required for all operations (string, required) + - `perPage`: Results per page for pagination (min 1, max 100) (number, optional) - `repo`: Repository name - required for all operations (string, required) diff --git a/pkg/github/__toolsnaps__/list_label.snap b/pkg/github/__toolsnaps__/list_label.snap index f85cd9a77d..80e898b71b 100644 --- a/pkg/github/__toolsnaps__/list_label.snap +++ b/pkg/github/__toolsnaps__/list_label.snap @@ -4,13 +4,23 @@ "readOnlyHint": true, "title": "List labels from a repository" }, - "description": "List labels from a repository, ordered by issue count (descending) so the most-used labels are returned first", + "description": "List labels from a repository, ordered by issue count (descending) so the most-used labels are returned first. For pagination, use the 'endCursor' from the previous response's 'pageInfo' in the 'after' parameter.", "inputSchema": { "properties": { + "after": { + "description": "Cursor for pagination. Use the cursor from the previous response.", + "type": "string" + }, "owner": { "description": "Repository owner (username or organization name) - required for all operations", "type": "string" }, + "perPage": { + "description": "Results per page for pagination (min 1, max 100)", + "maximum": 100, + "minimum": 1, + "type": "number" + }, "repo": { "description": "Repository name - required for all operations", "type": "string" @@ -53,6 +63,28 @@ "array" ] }, + "pageInfo": { + "additionalProperties": false, + "properties": { + "endCursor": { + "type": "string" + }, + "hasNextPage": { + "type": "boolean" + }, + "hasPreviousPage": { + "type": "boolean" + }, + "startCursor": { + "type": "string" + } + }, + "required": [ + "hasNextPage", + "hasPreviousPage" + ], + "type": "object" + }, "totalCount": { "description": "Total labels in the repository.", "type": "integer" @@ -60,7 +92,8 @@ }, "required": [ "labels", - "totalCount" + "totalCount", + "pageInfo" ], "type": "object" } diff --git a/pkg/github/labels.go b/pkg/github/labels.go index 70b5c5d8db..c9479e5062 100644 --- a/pkg/github/labels.go +++ b/pkg/github/labels.go @@ -132,6 +132,9 @@ func GetLabelForLabelsToolset(t translations.TranslationHelperFunc) inventory.Se return tool } +// listLabelsDefaultPerPage keeps the first page as large as GraphQL allows, so most repositories need one call. +const listLabelsDefaultPerPage = 100 + // ListLabels lists labels from a repository func ListLabels(t translations.TranslationHelperFunc) inventory.ServerTool { return typedGovernanceTool(listLabelsLegacy(t), listLabelsOutputSchema(), decodeGovernanceJSON[ListLabelsOutput]) @@ -142,12 +145,12 @@ func listLabelsLegacy(t translations.TranslationHelperFunc) inventory.ServerTool ToolsetLabels, mcp.Tool{ Name: "list_label", - Description: t("TOOL_LIST_LABEL_DESCRIPTION", "List labels from a repository, ordered by issue count (descending) so the most-used labels are returned first"), + Description: t("TOOL_LIST_LABEL_DESCRIPTION", "List labels from a repository, ordered by issue count (descending) so the most-used labels are returned first. For pagination, use the 'endCursor' from the previous response's 'pageInfo' in the 'after' parameter."), Annotations: &mcp.ToolAnnotations{ Title: t("TOOL_LIST_LABEL_TITLE", "List labels from a repository"), ReadOnlyHint: true, }, - InputSchema: &jsonschema.Schema{ + InputSchema: WithCursorPagination(&jsonschema.Schema{ Type: "object", Properties: map[string]*jsonschema.Schema{ "owner": { @@ -160,7 +163,7 @@ func listLabelsLegacy(t translations.TranslationHelperFunc) inventory.ServerTool }, }, Required: []string{"owner", "repo"}, - }, + }), }, scopes.PublicRead(scopes.Repo), func(ctx context.Context, deps ToolDependencies, _ *mcp.CallToolRequest, args map[string]any) (*mcp.CallToolResult, any, error) { @@ -174,6 +177,19 @@ func listLabelsLegacy(t translations.TranslationHelperFunc) inventory.ServerTool return utils.NewToolResultError(err.Error()), nil, nil } + perPage, err := OptionalIntParamWithDefault(args, "perPage", listLabelsDefaultPerPage) + if err != nil { + return utils.NewToolResultError(err.Error()), nil, nil + } + after, err := OptionalParam[string](args, "after") + if err != nil { + return utils.NewToolResultError(err.Error()), nil, nil + } + paginationParams, err := CursorPaginationParams{PerPage: perPage, After: after}.ToGraphQLParams() + if err != nil { + return utils.NewToolResultError(err.Error()), nil, nil + } + client, err := deps.GetGQLClient(ctx) if err != nil { return nil, nil, fmt.Errorf("failed to get GitHub client: %w", err) @@ -189,17 +205,29 @@ func listLabelsLegacy(t translations.TranslationHelperFunc) inventory.ServerTool Description githubv4.String } TotalCount githubv4.Int - } `graphql:"labels(first: 100, orderBy: {field: $orderByField, direction: $orderByDirection})"` + PageInfo struct { + HasNextPage githubv4.Boolean + HasPreviousPage githubv4.Boolean + StartCursor githubv4.String + EndCursor githubv4.String + } + } `graphql:"labels(first: $first, after: $after, orderBy: {field: $orderByField, direction: $orderByDirection})"` } `graphql:"repository(owner: $owner, name: $repo)"` } vars := map[string]any{ "owner": githubv4.String(owner), "repo": githubv4.String(repo), + "first": githubv4.Int(*paginationParams.First), // Order labels by issue count (descending) so the most-used labels are returned first. "orderByField": labelOrderFieldIssueCount, "orderByDirection": githubv4.OrderDirectionDesc, } + if paginationParams.After != nil { + vars["after"] = githubv4.String(*paginationParams.After) + } else { + vars["after"] = (*githubv4.String)(nil) + } if err := client.Query(ctx, &query, vars); err != nil { return ghErrors.NewGitHubGraphQLErrorResponse(ctx, "Failed to list labels", err), nil, nil @@ -215,9 +243,16 @@ func listLabelsLegacy(t translations.TranslationHelperFunc) inventory.ServerTool } } + labelsPage := query.Repository.Labels.PageInfo response := map[string]any{ "labels": labels, "totalCount": int(query.Repository.Labels.TotalCount), + "pageInfo": MinimalPageInfo{ + HasNextPage: bool(labelsPage.HasNextPage), + HasPreviousPage: bool(labelsPage.HasPreviousPage), + StartCursor: string(labelsPage.StartCursor), + EndCursor: string(labelsPage.EndCursor), + }, } out, err := json.Marshal(response) diff --git a/pkg/github/labels_test.go b/pkg/github/labels_test.go index a527664a81..43075659bc 100644 --- a/pkg/github/labels_test.go +++ b/pkg/github/labels_test.go @@ -2,6 +2,7 @@ package github import ( "context" + "encoding/json" "net/http" "testing" @@ -156,6 +157,7 @@ func TestListLabels(t *testing.T) { mockedClient *http.Client expectToolError bool expectedToolErrMsg string + expectedPageInfo MinimalPageInfo }{ { name: "successful repository labels listing", @@ -163,51 +165,57 @@ func TestListLabels(t *testing.T) { "owner": "owner", "repo": "repo", }, - mockedClient: githubv4mock.NewMockedHTTPClient( - githubv4mock.NewQueryMatcher( - struct { - Repository struct { - Labels struct { - Nodes []struct { - ID githubv4.ID - Name githubv4.String - Color githubv4.String - Description githubv4.String - } - TotalCount githubv4.Int - } `graphql:"labels(first: 100, orderBy: {field: $orderByField, direction: $orderByDirection})"` - } `graphql:"repository(owner: $owner, name: $repo)"` - }{}, - map[string]any{ - "owner": githubv4.String("owner"), - "repo": githubv4.String("repo"), - "orderByField": labelOrderFieldIssueCount, - "orderByDirection": githubv4.OrderDirectionDesc, - }, - githubv4mock.DataResponse(map[string]any{ - "repository": map[string]any{ - "labels": map[string]any{ - "nodes": []any{ - map[string]any{ - "id": githubv4.ID("label-1"), - "name": githubv4.String("bug"), - "color": githubv4.String("d73a4a"), - "description": githubv4.String("Something isn't working"), - }, - map[string]any{ - "id": githubv4.ID("label-2"), - "name": githubv4.String("enhancement"), - "color": githubv4.String("a2eeef"), - "description": githubv4.String("New feature or request"), - }, - }, - "totalCount": githubv4.Int(2), - }, - }, - }), - ), - ), - expectToolError: false, + mockedClient: githubv4mock.NewMockedHTTPClient(listLabelsMatcher(100, (*githubv4.String)(nil), map[string]any{ + "hasNextPage": githubv4.Boolean(false), + "hasPreviousPage": githubv4.Boolean(false), + "startCursor": githubv4.String("c1"), + "endCursor": githubv4.String("c2"), + })), + expectToolError: false, + expectedPageInfo: MinimalPageInfo{StartCursor: "c1", EndCursor: "c2"}, + }, + { + name: "reports the next page when the repository has more labels", + requestArgs: map[string]any{ + "owner": "owner", + "repo": "repo", + "perPage": float64(2), + }, + mockedClient: githubv4mock.NewMockedHTTPClient(listLabelsMatcher(2, (*githubv4.String)(nil), map[string]any{ + "hasNextPage": githubv4.Boolean(true), + "hasPreviousPage": githubv4.Boolean(false), + "startCursor": githubv4.String("c1"), + "endCursor": githubv4.String("c2"), + })), + expectToolError: false, + expectedPageInfo: MinimalPageInfo{HasNextPage: true, StartCursor: "c1", EndCursor: "c2"}, + }, + { + name: "passes the after cursor to fetch the next page", + requestArgs: map[string]any{ + "owner": "owner", + "repo": "repo", + "after": "c2", + }, + mockedClient: githubv4mock.NewMockedHTTPClient(listLabelsMatcher(100, githubv4.String("c2"), map[string]any{ + "hasNextPage": githubv4.Boolean(false), + "hasPreviousPage": githubv4.Boolean(true), + "startCursor": githubv4.String("c3"), + "endCursor": githubv4.String("c4"), + })), + expectToolError: false, + expectedPageInfo: MinimalPageInfo{HasPreviousPage: true, StartCursor: "c3", EndCursor: "c4"}, + }, + { + name: "rejects a page size above 100", + requestArgs: map[string]any{ + "owner": "owner", + "repo": "repo", + "perPage": float64(101), + }, + mockedClient: githubv4mock.NewMockedHTTPClient(), + expectToolError: true, + expectedToolErrMsg: "perPage value 101 exceeds maximum of 100", }, } @@ -233,11 +241,61 @@ func TestListLabels(t *testing.T) { } } else { assert.False(t, result.IsError) + var response ListLabelsOutput + require.NoError(t, json.Unmarshal([]byte(getTextResult(t, result).Text), &response)) + assert.Len(t, response.Labels, 2) + assert.Equal(t, 5, response.TotalCount) + assert.Equal(t, tc.expectedPageInfo, response.PageInfo) } }) } } +// listLabelsMatcher matches one list_label page request and answers with two labels and the given page info. +func listLabelsMatcher(first int32, after any, pageInfo map[string]any) githubv4mock.Matcher { + return githubv4mock.NewQueryMatcher( + struct { + Repository struct { + Labels struct { + Nodes []struct { + ID githubv4.ID + Name githubv4.String + Color githubv4.String + Description githubv4.String + } + TotalCount githubv4.Int + PageInfo struct { + HasNextPage githubv4.Boolean + HasPreviousPage githubv4.Boolean + StartCursor githubv4.String + EndCursor githubv4.String + } + } `graphql:"labels(first: $first, after: $after, orderBy: {field: $orderByField, direction: $orderByDirection})"` + } `graphql:"repository(owner: $owner, name: $repo)"` + }{}, + map[string]any{ + "owner": githubv4.String("owner"), + "repo": githubv4.String("repo"), + "first": githubv4.Int(first), + "after": after, + "orderByField": labelOrderFieldIssueCount, + "orderByDirection": githubv4.OrderDirectionDesc, + }, + githubv4mock.DataResponse(map[string]any{ + "repository": map[string]any{ + "labels": map[string]any{ + "nodes": []any{ + map[string]any{"id": githubv4.ID("label-1"), "name": githubv4.String("bug"), "color": githubv4.String("d73a4a"), "description": githubv4.String("Something isn't working")}, + map[string]any{"id": githubv4.ID("label-2"), "name": githubv4.String("enhancement"), "color": githubv4.String("a2eeef"), "description": githubv4.String("New feature or request")}, + }, + "totalCount": githubv4.Int(5), + "pageInfo": pageInfo, + }, + }, + }), + ) +} + func TestWriteLabel(t *testing.T) { t.Parallel() diff --git a/pkg/github/typed_governance_outputs.go b/pkg/github/typed_governance_outputs.go index 74925ad881..02952bac0b 100644 --- a/pkg/github/typed_governance_outputs.go +++ b/pkg/github/typed_governance_outputs.go @@ -20,8 +20,9 @@ type MinimalLabel struct { } type ListLabelsOutput struct { - Labels []MinimalLabel `json:"labels"` - TotalCount int `json:"totalCount" jsonschema:"Total labels in the repository."` + Labels []MinimalLabel `json:"labels"` + TotalCount int `json:"totalCount" jsonschema:"Total labels in the repository."` + PageInfo MinimalPageInfo `json:"pageInfo"` } type LabelWriteOutput struct { diff --git a/pkg/github/typed_governance_outputs_test.go b/pkg/github/typed_governance_outputs_test.go index b274d0e68d..094de91547 100644 --- a/pkg/github/typed_governance_outputs_test.go +++ b/pkg/github/typed_governance_outputs_test.go @@ -72,7 +72,7 @@ func assertGovernanceProjection(t *testing.T, tc governanceWireCase, output any) case "get_label": assert.JSONEq(t, `{"name":"bug","color":"ff0000","description":"desc"}`, mustMarshalJSON(t, output)) case "list_label": - assert.JSONEq(t, `{"labels":[{"name":"bug","color":"ff0000","description":"desc"}],"totalCount":1}`, mustMarshalJSON(t, output)) + assert.JSONEq(t, `{"labels":[{"name":"bug","color":"ff0000","description":"desc"}],"totalCount":1,"pageInfo":{"hasNextPage":false,"hasPreviousPage":false}}`, mustMarshalJSON(t, output)) case "label_write": assert.Equal(t, tc.args["method"], object["method"]) assert.Equal(t, tc.text, object["message"]) @@ -236,7 +236,7 @@ func governanceWireCases(t *testing.T) []governanceWireCase { tr := translations.NullTranslationHelper return []governanceWireCase{ {tool: GetLabel(tr), args: map[string]any{"owner": "o", "repo": "r", "name": "bug"}, text: `{"id":"L1","name":"bug","color":"ff0000","description":"desc"}`}, - {tool: ListLabels(tr), args: map[string]any{"owner": "o", "repo": "r"}, text: `{"labels":[{"id":"L1","name":"bug","color":"ff0000","description":"desc"}],"totalCount":1}`}, + {tool: ListLabels(tr), args: map[string]any{"owner": "o", "repo": "r"}, text: `{"labels":[{"id":"L1","name":"bug","color":"ff0000","description":"desc"}],"totalCount":1,"pageInfo":{"hasNextPage":false,"hasPreviousPage":false}}`}, {tool: LabelWrite(tr), args: map[string]any{"method": "create", "owner": "o", "repo": "r", "name": "feature", "color": "abcdef"}, text: "label 'feature' created successfully"}, {tool: LabelWrite(tr), args: map[string]any{"method": "update", "owner": "o", "repo": "r", "name": "bug", "new_name": "defect"}, text: "label 'defect' updated successfully"}, {tool: LabelWrite(tr), args: map[string]any{"method": "delete", "owner": "o", "repo": "r", "name": "bug"}, text: "label 'bug' deleted successfully"}, From b98d115bbb080e9555466a96656ec4df605aea21 Mon Sep 17 00:00:00 2001 From: Marc Herschel <22261092+marcherschel@users.noreply.github.com> Date: Wed, 21 Oct 2026 11:46:50 +0200 Subject: [PATCH 6/6] upgrade to Go 1.27.3 for compromised CA mitigation (#3540) * upgrade to Go 1.27.3 for compromised CA mitigation Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: 3c4f7224-1f03-44c2-ab67-db76f7c8eceb * isolate HTTP transports in parallel tests Use the existing per-test transport helper so httptest server cleanup cannot close another test's shared default connections. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: 3c4f7224-1f03-44c2-ab67-db76f7c8eceb * remove unused CodeQL environment resolution Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: 3c4f7224-1f03-44c2-ab67-db76f7c8eceb --------- Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: 3c4f7224-1f03-44c2-ab67-db76f7c8eceb --- .github/copilot-instructions.md | 6 ++-- .github/workflows/code-scanning.yml | 9 ++--- .github/workflows/registry-releaser.yml | 2 +- CONTRIBUTING.md | 2 +- Dockerfile | 2 +- go.mod | 2 +- pkg/github/actions.go | 22 +++++------- pkg/github/csv_output_test.go | 2 +- pkg/github/gists.go | 6 ++-- pkg/github/granular_issue_types.go | 20 +++++------ pkg/github/issues.go | 12 +++---- pkg/github/notifications.go | 6 ++-- pkg/github/projects.go | 8 ++--- pkg/github/pullrequests.go | 12 +++---- pkg/github/repositories.go | 30 ++++++---------- pkg/github/repositories_test.go | 32 ++++++++--------- pkg/github/repository_resource_completions.go | 14 ++++---- pkg/github/rulesets.go | 6 ++-- pkg/github/sanitize_coverage_test.go | 2 +- pkg/github/search.go | 36 ++++++++----------- pkg/github/search_utils.go | 10 +++--- pkg/github/security_advisories_test.go | 20 +++++------ pkg/github/typed_actions_outputs_test.go | 10 +++--- pkg/github/typed_security_outputs_test.go | 2 +- pkg/github/ui_tools.go | 8 ++--- pkg/http/transport/etag_test.go | 20 +++++------ pkg/http/transport/user_agent_test.go | 2 +- 27 files changed, 127 insertions(+), 176 deletions(-) diff --git a/.github/copilot-instructions.md b/.github/copilot-instructions.md index 975df2a633..0db7990bc4 100644 --- a/.github/copilot-instructions.md +++ b/.github/copilot-instructions.md @@ -5,7 +5,7 @@ This is the **GitHub MCP Server**, a Model Context Protocol (MCP) server that connects AI tools to GitHub's platform. It enables AI agents to manage repositories, issues, pull requests, workflows, and more through natural language. **Key Details:** -- **Language:** Go 1.24+ (~38k lines of code) +- **Language:** Go 1.27.3+ (~38k lines of code) - **Type:** MCP server application with CLI interface - **Primary Package:** github-mcp-server (stdio MCP server - **this is the main focus**) - **Secondary Package:** mcpcurl (testing utility - don't break it, but not the priority) @@ -92,9 +92,9 @@ go test ./pkg/github -run TestGetMe ### Key Configuration Files -- **go.mod / go.sum:** Go module dependencies (Go 1.24.0+) +- **go.mod / go.sum:** Go module dependencies (Go 1.27.3+) - **.golangci.yml:** Linter configuration (v2 format, ~15 linters enabled) -- **Dockerfile:** Multi-stage build (golang:1.25.8-alpine → distroless) +- **Dockerfile:** Multi-stage build (golang:1.27.3-alpine → distroless) - **server.json:** MCP server metadata for registry - **.goreleaser.yaml:** Release automation config - **.gitignore:** Excludes bin/, dist/, vendor/, *.DS_Store, github-mcp-server binary diff --git a/.github/workflows/code-scanning.yml b/.github/workflows/code-scanning.yml index 26d61a2faa..f7ff6e5ecd 100644 --- a/.github/workflows/code-scanning.yml +++ b/.github/workflows/code-scanning.yml @@ -66,16 +66,11 @@ jobs: registries_credentials: ${{ secrets.GITHUB_REGISTRIES_PROXY }} language: ${{ matrix.language }} - - name: Configure - uses: github/codeql-action/resolve-environment@2892aa5e19bbd11bc0cff5427e3b750a04d9e3c2 # v4.38.2 - id: resolve-environment - with: - language: ${{ matrix.language }} - name: Setup Go uses: actions/setup-go@b7ad1dad31e06c5925ef5d2fc7ad053ef454303e # v7 - if: matrix.language == 'go' && fromJSON(steps.resolve-environment.outputs.environment).configuration.go.version + if: matrix.language == 'go' with: - go-version: ${{ fromJSON(steps.resolve-environment.outputs.environment).configuration.go.version }} + go-version-file: "go.mod" cache: false - name: Set up Node.js (for JavaScript CodeQL) diff --git a/.github/workflows/registry-releaser.yml b/.github/workflows/registry-releaser.yml index a1db9759cf..5f698eab96 100644 --- a/.github/workflows/registry-releaser.yml +++ b/.github/workflows/registry-releaser.yml @@ -19,7 +19,7 @@ jobs: - name: Setup Go uses: actions/setup-go@b7ad1dad31e06c5925ef5d2fc7ad053ef454303e # v7 with: - go-version: "stable" + go-version-file: "go.mod" - name: Fetch tags run: | diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 0c97c238c5..b7595682ce 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -26,7 +26,7 @@ Thanks for contributing and for helping us build toolsets that are truly valuabl These are one time installations required to be able to test your changes locally as part of the pull request (PR) submission process. -1. Install Go 1.26.8 or later [through download](https://go.dev/doc/install) | [through Homebrew](https://formulae.brew.sh/formula/go) +1. Install Go 1.27.3 or later [through download](https://go.dev/doc/install) | [through Homebrew](https://formulae.brew.sh/formula/go) 2. [Install golangci-lint v2.14.0](https://golangci-lint.run/welcome/install/#local-installation), or let `script/lint` install the repository-pinned version. The pinned version supports both Go 1.26 and Go 1.27. ### UI development diff --git a/Dockerfile b/Dockerfile index e555c50045..849e924be7 100644 --- a/Dockerfile +++ b/Dockerfile @@ -7,7 +7,7 @@ COPY ui/ ./ui/ RUN mkdir -p ./pkg/github/ui_dist && \ cd ui && npm run build -FROM golang:1.27.1-alpine@sha256:8a5910f31396cd4d89662f56c68b3ae31d374308270a1c3bd96672ee5ed43414 AS build +FROM golang:1.27.3-alpine@sha256:f2c872bcee949b7be9c490efd02b48a8a2fbf947cdf533f1c58525ec9d8170fd AS build ARG VERSION="dev" # Set the working directory diff --git a/go.mod b/go.mod index ea0cd5eb9d..6e854e8103 100644 --- a/go.mod +++ b/go.mod @@ -1,6 +1,6 @@ module github.com/github/github-mcp-server/v2 -go 1.26.8 +go 1.27.3 require ( github.com/go-chi/chi/v5 v5.3.2 diff --git a/pkg/github/actions.go b/pkg/github/actions.go index fc31477f63..dc71ab5261 100644 --- a/pkg/github/actions.go +++ b/pkg/github/actions.go @@ -745,14 +745,12 @@ func listWorkflowRuns(ctx context.Context, client *github.Client, filter Actions } listWorkflowRunsOptions := &github.ListWorkflowRunsOptions{ - Actor: filter.Actor, - Branch: filter.Branch, - Event: filter.Event, - Status: filter.Status, - ListOptions: github.ListOptions{ - Page: pagination.Page, - PerPage: pagination.PerPage, - }, + Actor: filter.Actor, + Branch: filter.Branch, + Event: filter.Event, + Status: filter.Status, + Page: pagination.Page, + PerPage: pagination.PerPage, } var workflowRuns *github.WorkflowRuns @@ -787,11 +785,9 @@ func listWorkflowJobs(ctx context.Context, client *github.Client, filter Actions } workflowJobs, resp, err := client.Actions.ListWorkflowJobs(ctx, owner, repo, resourceID, &github.ListWorkflowJobsOptions{ - Filter: filter.Filter, - ListOptions: github.ListOptions{ - Page: pagination.Page, - PerPage: pagination.PerPage, - }, + Filter: filter.Filter, + Page: pagination.Page, + PerPage: pagination.PerPage, }) if err != nil { return ghErrors.NewGitHubAPIErrorResponse(ctx, "failed to list workflow jobs", resp, err), nil, nil diff --git a/pkg/github/csv_output_test.go b/pkg/github/csv_output_test.go index 43e59ec0e9..0582353cc8 100644 --- a/pkg/github/csv_output_test.go +++ b/pkg/github/csv_output_test.go @@ -474,7 +474,7 @@ func buildCSVOutputInventory(t *testing.T, tools []inventory.ServerTool, _ bool) } func newCSVOutputTestDeps(csvOutputEnabled bool) ToolDependencies { - return csvOutputTestDeps{stubDeps: stubDeps{obsv: stubExporters()}, csvOn: csvOutputEnabled} + return csvOutputTestDeps{obsv: stubExporters(), csvOn: csvOutputEnabled} } type csvOutputTestDeps struct { diff --git a/pkg/github/gists.go b/pkg/github/gists.go index 9d9861470e..cca3529644 100644 --- a/pkg/github/gists.go +++ b/pkg/github/gists.go @@ -64,10 +64,8 @@ func ListGists(t translations.TranslationHelperFunc) inventory.ServerTool { } opts := &github.GistListOptions{ - ListOptions: github.ListOptions{ - Page: pagination.Page, - PerPage: pagination.PerPage, - }, + Page: pagination.Page, + PerPage: pagination.PerPage, } // Parse since timestamp if provided diff --git a/pkg/github/granular_issue_types.go b/pkg/github/granular_issue_types.go index a1a8f47816..c0b9f2e16d 100644 --- a/pkg/github/granular_issue_types.go +++ b/pkg/github/granular_issue_types.go @@ -535,7 +535,7 @@ func normalizeGranularUpdateIssueAssigneesArguments(raw json.RawMessage) (json.R } } - return marshalGranularIssueArguments(args, GranularIssueAssigneesInput{GranularIssueCoordinate: GranularIssueCoordinate{Owner: owner, Repo: repo, IssueNumber: issueNumber}, Assignees: payload}) + return marshalGranularIssueArguments(args, GranularIssueAssigneesInput{Owner: owner, Repo: repo, IssueNumber: issueNumber, Assignees: payload}) } func normalizeGranularUpdateIssueLabelsArguments(raw json.RawMessage) (json.RawMessage, error) { @@ -615,7 +615,7 @@ func normalizeGranularUpdateIssueLabelsArguments(raw json.RawMessage) (json.RawM } } - return marshalGranularIssueArguments(args, GranularIssueLabelsInput{GranularIssueCoordinate: GranularIssueCoordinate{Owner: owner, Repo: repo, IssueNumber: issueNumber}, Labels: payload}) + return marshalGranularIssueArguments(args, GranularIssueLabelsInput{Owner: owner, Repo: repo, IssueNumber: issueNumber, Labels: payload}) } func normalizeGranularUpdateIssueTypeArguments(raw json.RawMessage) (json.RawMessage, error) { @@ -666,7 +666,7 @@ func normalizeGranularUpdateIssueTypeArguments(raw json.RawMessage) (json.RawMes if issueType == nil && (rationale != "" || confidence != "" || isSuggestion) { return nil, fmt.Errorf("suggestion metadata is not supported when removing an issue type; omit rationale, confidence, and is_suggestion") } - return marshalGranularIssueArguments(args, GranularIssueTypeInput{GranularIssueCoordinate: GranularIssueCoordinate{Owner: owner, Repo: repo, IssueNumber: issueNumber}, IssueType: issueType, Rationale: rationale, Confidence: confidence, IsSuggestion: isSuggestion}) + return marshalGranularIssueArguments(args, GranularIssueTypeInput{Owner: owner, Repo: repo, IssueNumber: issueNumber, IssueType: issueType, Rationale: rationale, Confidence: confidence, IsSuggestion: isSuggestion}) } func normalizeGranularUpdateIssueStateArguments(raw json.RawMessage) (json.RawMessage, error) { @@ -732,7 +732,7 @@ func normalizeGranularUpdateIssueStateArguments(raw json.RawMessage) (json.RawMe delete(args, "duplicate_of") } - return marshalGranularIssueArguments(args, GranularIssueStateInput{GranularIssueCoordinate: GranularIssueCoordinate{Owner: owner, Repo: repo, IssueNumber: issueNumber}, State: state, StateReason: stateReason, Rationale: rationale, Confidence: confidence, IsSuggestion: isSuggestion, DuplicateOf: duplicateOf}) + return marshalGranularIssueArguments(args, GranularIssueStateInput{Owner: owner, Repo: repo, IssueNumber: issueNumber, State: state, StateReason: stateReason, Rationale: rationale, Confidence: confidence, IsSuggestion: isSuggestion, DuplicateOf: duplicateOf}) } func normalizeGranularAddSubIssueArguments(raw json.RawMessage) (json.RawMessage, error) { @@ -763,7 +763,7 @@ func normalizeGranularAddSubIssueArguments(raw json.RawMessage) (json.RawMessage args["replace_parent"] = replaceParent } - return marshalGranularIssueArguments(args, GranularAddSubIssueInput{GranularIssueCoordinate: GranularIssueCoordinate{Owner: owner, Repo: repo, IssueNumber: issueNumber}, SubIssueID: subIssueID, ReplaceParent: replaceParent}) + return marshalGranularIssueArguments(args, GranularAddSubIssueInput{Owner: owner, Repo: repo, IssueNumber: issueNumber, SubIssueID: subIssueID, ReplaceParent: replaceParent}) } func normalizeGranularRemoveSubIssueArguments(raw json.RawMessage) (json.RawMessage, error) { @@ -789,7 +789,7 @@ func normalizeGranularRemoveSubIssueArguments(raw json.RawMessage) (json.RawMess return nil, err } - return marshalGranularIssueArguments(args, GranularRemoveSubIssueInput{GranularIssueCoordinate: GranularIssueCoordinate{Owner: owner, Repo: repo, IssueNumber: issueNumber}, SubIssueID: subIssueID}) + return marshalGranularIssueArguments(args, GranularRemoveSubIssueInput{Owner: owner, Repo: repo, IssueNumber: issueNumber, SubIssueID: subIssueID}) } func normalizeGranularReprioritizeSubIssueArguments(raw json.RawMessage) (json.RawMessage, error) { @@ -829,7 +829,7 @@ func normalizeGranularReprioritizeSubIssueArguments(raw json.RawMessage) (json.R delete(args, "before_id") } - return marshalGranularIssueArguments(args, GranularReprioritizeSubIssueInput{GranularIssueCoordinate: GranularIssueCoordinate{Owner: owner, Repo: repo, IssueNumber: issueNumber}, SubIssueID: subIssueID, AfterID: afterID, BeforeID: beforeID}) + return marshalGranularIssueArguments(args, GranularReprioritizeSubIssueInput{Owner: owner, Repo: repo, IssueNumber: issueNumber, SubIssueID: subIssueID, AfterID: afterID, BeforeID: beforeID}) } func granularIssueInputNormalizer(normalize inventory.InputNormalizer) inventory.InputNormalizer { @@ -974,7 +974,7 @@ func normalizeGranularSetIssueFieldsArguments(raw json.RawMessage) (json.RawMess issueFields = append(issueFields, input) } - return marshalGranularIssueArguments(args, GranularSetIssueFieldsInput{GranularIssueCoordinate: GranularIssueCoordinate{Owner: owner, Repo: repo, IssueNumber: issueNumber}, Fields: granularIssueFieldsFromMutation(issueFields)}) + return marshalGranularIssueArguments(args, GranularSetIssueFieldsInput{Owner: owner, Repo: repo, IssueNumber: issueNumber, Fields: granularIssueFieldsFromMutation(issueFields)}) } func normalizeGranularAddIssueReactionArguments(raw json.RawMessage) (json.RawMessage, error) { @@ -1000,7 +1000,7 @@ func normalizeGranularAddIssueReactionArguments(raw json.RawMessage) (json.RawMe return nil, err } - return marshalGranularIssueArguments(args, GranularAddIssueReactionInput{GranularIssueCoordinate: GranularIssueCoordinate{Owner: owner, Repo: repo, IssueNumber: issueNumber}, Content: content}) + return marshalGranularIssueArguments(args, GranularAddIssueReactionInput{Owner: owner, Repo: repo, IssueNumber: issueNumber, Content: content}) } func normalizeGranularRemoveIssueReactionArguments(raw json.RawMessage) (json.RawMessage, error) { @@ -1026,7 +1026,7 @@ func normalizeGranularRemoveIssueReactionArguments(raw json.RawMessage) (json.Ra return nil, err } - return marshalGranularIssueArguments(args, GranularRemoveIssueReactionInput{GranularIssueCoordinate: GranularIssueCoordinate{Owner: owner, Repo: repo, IssueNumber: issueNumber}, ReactionID: reactionID}) + return marshalGranularIssueArguments(args, GranularRemoveIssueReactionInput{Owner: owner, Repo: repo, IssueNumber: issueNumber, ReactionID: reactionID}) } func normalizeGranularAddIssueCommentReactionArguments(raw json.RawMessage) (json.RawMessage, error) { diff --git a/pkg/github/issues.go b/pkg/github/issues.go index e8df57a54d..30005854aa 100644 --- a/pkg/github/issues.go +++ b/pkg/github/issues.go @@ -1026,10 +1026,8 @@ func getIssueComments(ctx context.Context, client *github.Client, deps ToolDepen flags := deps.GetFlags(ctx) opts := &github.IssueListCommentsOptions{ - ListOptions: github.ListOptions{ - Page: pagination.Page, - PerPage: pagination.PerPage, - }, + Page: pagination.Page, + PerPage: pagination.PerPage, } comments, resp, err := client.Issues.ListComments(ctx, owner, repo, issueNumber, opts) @@ -2117,11 +2115,11 @@ func parseRepositoryURL(repoURL string) (string, string, bool) { return "", "", false } const marker = "/repos/" - idx := strings.LastIndex(repoURL, marker) - if idx < 0 { + _, after, ok := strings.CutLast(repoURL, marker) + if !ok { return "", "", false } - parts := strings.Split(strings.Trim(repoURL[idx+len(marker):], "/"), "/") + parts := strings.Split(strings.Trim(after, "/"), "/") if len(parts) < 2 || parts[0] == "" || parts[1] == "" { return "", "", false } diff --git a/pkg/github/notifications.go b/pkg/github/notifications.go index 7558b07edf..332d2ffd3b 100644 --- a/pkg/github/notifications.go +++ b/pkg/github/notifications.go @@ -108,10 +108,8 @@ func ListNotifications(t translations.TranslationHelperFunc) inventory.ServerToo opts := &github.NotificationListOptions{ All: filter == FilterIncludeRead, Participating: filter == FilterOnlyParticipating, - ListOptions: github.ListOptions{ - Page: paginationParams.Page, - PerPage: paginationParams.PerPage, - }, + Page: paginationParams.Page, + PerPage: paginationParams.PerPage, } // Parse time parameters if provided diff --git a/pkg/github/projects.go b/pkg/github/projects.go index 436364c7ba..e55b2a29d6 100644 --- a/pkg/github/projects.go +++ b/pkg/github/projects.go @@ -1275,11 +1275,9 @@ func listProjectItems(ctx context.Context, client *github.Client, gqlClient *git var projectItems []*github.ProjectV2Item opts := &github.ListProjectItemsOptions{ - Fields: fields, - ListProjectsOptions: github.ListProjectsOptions{ - ListProjectsPaginationOptions: pagination, - Query: queryStr, - }, + Fields: fields, + ListProjectsPaginationOptions: pagination, + Query: queryStr, } if ownerType == "org" { diff --git a/pkg/github/pullrequests.go b/pkg/github/pullrequests.go index 5545d43964..70fdfa197a 100644 --- a/pkg/github/pullrequests.go +++ b/pkg/github/pullrequests.go @@ -357,10 +357,8 @@ func getPullRequestCheckRuns(ctx context.Context, client *github.Client, owner, // Get check runs for the head SHA opts := &github.ListCheckRunsOptions{ - ListOptions: github.ListOptions{ - PerPage: pagination.PerPage, - Page: pagination.Page, - }, + PerPage: pagination.PerPage, + Page: pagination.Page, } checkRuns, resp, err := client.Checks.ListCheckRunsForRef(ctx, owner, repo, *pr.Head.SHA, opts) @@ -1608,10 +1606,8 @@ func ListPullRequests(t translations.TranslationHelperFunc) inventory.ServerTool Base: input.Base, Sort: input.Sort, Direction: input.Direction, - ListOptions: github.ListOptions{ - PerPage: pagination.PerPage, - Page: pagination.Page, - }, + PerPage: pagination.PerPage, + Page: pagination.Page, } client, err := deps.GetClient(ctx) diff --git a/pkg/github/repositories.go b/pkg/github/repositories.go index 5db5880917..b884f4888d 100644 --- a/pkg/github/repositories.go +++ b/pkg/github/repositories.go @@ -266,13 +266,11 @@ func ListCommits(t translations.TranslationHelperFunc) inventory.ServerTool { perPage = 30 } opts := &github.CommitsListOptions{ - SHA: input.SHA, - Path: input.Path, - Author: input.Author, - ListOptions: github.ListOptions{ - Page: pagination.Page, - PerPage: perPage, - }, + SHA: input.SHA, + Path: input.Path, + Author: input.Author, + Page: pagination.Page, + PerPage: perPage, } if input.Since != "" { sinceTime, err := parseISOTimestamp(input.Since) @@ -397,10 +395,8 @@ func ListBranches(t translations.TranslationHelperFunc) inventory.ServerTool { } opts := &github.BranchListOptions{ - ListOptions: github.ListOptions{ - Page: pagination.Page, - PerPage: pagination.PerPage, - }, + Page: pagination.Page, + PerPage: pagination.PerPage, } client, err := deps.GetClient(ctx) @@ -2420,10 +2416,8 @@ func ListStarredRepositories(t translations.TranslationHelperFunc) inventory.Ser pagination := repositoryPagination(input.Page, input.PerPage) opts := &github.ActivityListStarredOptions{ - ListOptions: github.ListOptions{ - Page: pagination.Page, - PerPage: pagination.PerPage, - }, + Page: pagination.Page, + PerPage: pagination.PerPage, } if sort != "" { opts.Sort = sort @@ -3116,10 +3110,8 @@ func ListRepositoryCollaborators(t translations.TranslationHelperFunc) inventory opts := &github.ListCollaboratorsOptions{ Affiliation: affiliation, - ListOptions: github.ListOptions{ - Page: pagination.Page, - PerPage: pagination.PerPage, - }, + Page: pagination.Page, + PerPage: pagination.PerPage, } collaborators, resp, err := client.Repositories.ListCollaborators(ctx, owner, repo, opts) diff --git a/pkg/github/repositories_test.go b/pkg/github/repositories_test.go index 966390b920..9b40c932ff 100644 --- a/pkg/github/repositories_test.go +++ b/pkg/github/repositories_test.go @@ -2155,16 +2155,14 @@ func Test_CreateOrUpdateFile(t *testing.T) { HTMLURL: new("https://github.com/owner/repo/blob/main/docs/example.md"), DownloadURL: new("https://raw.githubusercontent.com/owner/repo/main/docs/example.md"), }, - Commit: github.Commit{ - SHA: new("def456abc789"), - Message: new("Add example file"), - Author: &github.CommitAuthor{ - Name: new("Test User"), - Email: new("test@example.com"), - Date: &github.Timestamp{Time: time.Now()}, - }, - HTMLURL: new("https://github.com/owner/repo/commit/def456abc789"), - }, + SHA: new("def456abc789"), + Message: new("Add example file"), + Author: &github.CommitAuthor{ + Name: new("Test User"), + Email: new("test@example.com"), + Date: &github.Timestamp{Time: time.Now()}, + }, + HTMLURL: new("https://github.com/owner/repo/commit/def456abc789"), } symlinkTarget := []byte("other.md") symlinkSHA := gitBlobSHA(symlinkTarget) @@ -3333,7 +3331,7 @@ func Test_PushFiles(t *testing.T) { require.Equal(t, "main", body["branch"]) w.WriteHeader(http.StatusCreated) response := &github.RepositoryContentResponse{ - Commit: github.Commit{SHA: new("abc123")}, + SHA: new("abc123"), } b, _ := json.Marshal(response) _, _ = w.Write(b) @@ -3429,11 +3427,9 @@ func Test_PushFiles(t *testing.T) { Content: &github.RepositoryContent{ SHA: new("readme123"), }, - Commit: github.Commit{ - SHA: new("init456"), - Tree: &github.Tree{ - SHA: new("tree456"), - }, + SHA: new("init456"), + Tree: &github.Tree{ + SHA: new("tree456"), }, } b, _ := json.Marshal(response) @@ -3609,7 +3605,7 @@ func Test_PushFiles(t *testing.T) { PutReposContentsByOwnerByRepoByPath, &github.RepositoryContentResponse{ Content: &github.RepositoryContent{SHA: new("readme123")}, - Commit: github.Commit{SHA: new("init456")}, + SHA: new("init456"), }, ), ), @@ -3655,7 +3651,7 @@ func Test_PushFiles(t *testing.T) { PutReposContentsByOwnerByRepoByPath, &github.RepositoryContentResponse{ Content: &github.RepositoryContent{SHA: new("readme123")}, - Commit: github.Commit{SHA: new("init456")}, + SHA: new("init456"), }, ), // Fail to get commit diff --git a/pkg/github/repository_resource_completions.go b/pkg/github/repository_resource_completions.go index deb4b738dc..9f4edc7b40 100644 --- a/pkg/github/repository_resource_completions.go +++ b/pkg/github/repository_resource_completions.go @@ -106,7 +106,7 @@ func completeOwner(ctx context.Context, client *github.Client, _ map[string]stri if argValue == "" { return values, nil // No need to search if no argValue } - users, _, err := client.Search.Users(ctx, argValue, &github.SearchOptions{ListOptions: github.ListOptions{PerPage: 100 - len(values)}}) + users, _, err := client.Search.Users(ctx, argValue, &github.SearchOptions{PerPage: 100 - len(values)}) if err != nil || users == nil { return nil, err } @@ -132,7 +132,7 @@ func completeRepo(ctx context.Context, client *github.Client, resolved map[strin if argValue != "" { query = fmt.Sprintf("%s %s", query, argValue) } - repos, _, err := client.Search.Repositories(ctx, query, &github.SearchOptions{ListOptions: github.ListOptions{PerPage: 100}}) + repos, _, err := client.Search.Repositories(ctx, query, &github.SearchOptions{PerPage: 100}) if err != nil || repos == nil { return values, errors.New("failed to get repositories") } @@ -215,7 +215,7 @@ func completePRNumber(ctx context.Context, client *github.Client, resolved map[s return values, errors.New("owner or repo not specified") } - prs, _, err := client.Search.Issues(ctx, fmt.Sprintf("repo:%s/%s is:open is:pr", owner, repo), &github.SearchOptions{ListOptions: github.ListOptions{PerPage: 100}}) + prs, _, err := client.Search.Issues(ctx, fmt.Sprintf("repo:%s/%s is:open is:pr", owner, repo), &github.SearchOptions{PerPage: 100}) if err != nil { return values, err } @@ -293,8 +293,8 @@ func completePath(ctx context.Context, client *github.Client, resolved map[strin // Optionally filter by argValue (if user is typing after last slash) var filter string if argValue != "" { - if lastSlash := strings.LastIndex(argValue, "/"); lastSlash >= 0 { - filter = argValue[lastSlash+1:] + if _, after, ok := strings.CutLast(argValue, "/"); ok { + filter = after } else { filter = argValue } @@ -321,8 +321,8 @@ func completePath(ctx context.Context, client *github.Client, resolved map[strin values = append(values, file) } else { last := file - if idx := strings.LastIndex(file, "/"); idx >= 0 { - last = file[idx+1:] + if _, after, ok := strings.CutLast(file, "/"); ok { + last = after } if strings.HasPrefix(last, filter) { values = append(values, file) diff --git a/pkg/github/rulesets.go b/pkg/github/rulesets.go index af0ce1b3c2..d0854ea896 100644 --- a/pkg/github/rulesets.go +++ b/pkg/github/rulesets.go @@ -382,10 +382,8 @@ func GetRepositoryRuleset(ctx context.Context, client *github.Client, owner, rep // includesParents is nil GitHub's default behaviour (include parents) is used. func ListRepositoryRulesets(ctx context.Context, client *github.Client, owner, repo string, includesParents *bool, pagination PaginationParams) (*mcp.CallToolResult, error) { opts := &github.RepositoryListRulesetsOptions{ - ListOptions: github.ListOptions{ - Page: pagination.Page, - PerPage: pagination.PerPage, - }, + Page: pagination.Page, + PerPage: pagination.PerPage, IncludesParents: includesParents, } diff --git a/pkg/github/sanitize_coverage_test.go b/pkg/github/sanitize_coverage_test.go index f8f612cfe2..c50a237896 100644 --- a/pkg/github/sanitize_coverage_test.go +++ b/pkg/github/sanitize_coverage_test.go @@ -143,7 +143,7 @@ func Test_MinimalConverters_SanitizeUserAuthoredText(t *testing.T) { content: true, got: func() string { resp := convertToMinimalFileContentResponse(&github.RepositoryContentResponse{ - Commit: github.Commit{Message: new(maliciousText)}, + Message: new(maliciousText), }) require.NotNil(t, resp.Commit) return resp.Commit.Message diff --git a/pkg/github/search.go b/pkg/github/search.go index 368357c4ed..6caaf389d5 100644 --- a/pkg/github/search.go +++ b/pkg/github/search.go @@ -70,12 +70,10 @@ func SearchRepositories(t translations.TranslationHelperFunc) inventory.ServerTo pagination := repositoryPagination(input.Page, input.PerPage) minimalOutput := input.MinimalOutput == nil || *input.MinimalOutput opts := &github.SearchOptions{ - Sort: input.Sort, - Order: input.Order, - ListOptions: github.ListOptions{ - Page: pagination.Page, - PerPage: pagination.PerPage, - }, + Sort: input.Sort, + Order: input.Order, + Page: pagination.Page, + PerPage: pagination.PerPage, } client, err := deps.GetClient(ctx) @@ -315,10 +313,8 @@ func SearchCode(t translations.TranslationHelperFunc) inventory.ServerTool { Sort: input.Sort, Order: input.Order, TextMatch: true, - ListOptions: github.ListOptions{ - PerPage: pagination.PerPage, - Page: pagination.Page, - }, + PerPage: pagination.PerPage, + Page: pagination.Page, } client, err := deps.GetClient(ctx) @@ -418,12 +414,10 @@ func userOrOrgHandler(ctx context.Context, accountType string, deps ToolDependen pagination := repositoryPagination(input.Page, input.PerPage) opts := &github.SearchOptions{ - Sort: input.Sort, - Order: input.Order, - ListOptions: github.ListOptions{ - PerPage: pagination.PerPage, - Page: pagination.Page, - }, + Sort: input.Sort, + Order: input.Order, + PerPage: pagination.PerPage, + Page: pagination.Page, } client, err := deps.GetClient(ctx) @@ -619,12 +613,10 @@ func SearchCommits(t translations.TranslationHelperFunc) inventory.ServerTool { pagination := repositoryPagination(input.Page, input.PerPage) opts := &github.SearchOptions{ - Sort: input.Sort, - Order: input.Order, - ListOptions: github.ListOptions{ - Page: pagination.Page, - PerPage: pagination.PerPage, - }, + Sort: input.Sort, + Order: input.Order, + Page: pagination.Page, + PerPage: pagination.PerPage, } client, err := deps.GetClient(ctx) diff --git a/pkg/github/search_utils.go b/pkg/github/search_utils.go index b05bf1c21b..0f62e8b26e 100644 --- a/pkg/github/search_utils.go +++ b/pkg/github/search_utils.go @@ -121,12 +121,10 @@ func prepareSearchArgs(input SearchIssuesInput, targetType string, mode searchMo } opts := &github.SearchOptions{ - Sort: input.Sort, - Order: input.Order, - ListOptions: github.ListOptions{ - Page: pagination.Page, - PerPage: pagination.PerPage, - }, + Sort: input.Sort, + Order: input.Order, + Page: pagination.Page, + PerPage: pagination.PerPage, } // field.: qualifiers require the advanced search API. diff --git a/pkg/github/security_advisories_test.go b/pkg/github/security_advisories_test.go index a398729acc..70186e0ccf 100644 --- a/pkg/github/security_advisories_test.go +++ b/pkg/github/security_advisories_test.go @@ -31,12 +31,10 @@ func Test_ListGlobalSecurityAdvisories(t *testing.T) { // Setup mock advisory for success case mockAdvisory := &github.GlobalSecurityAdvisory{ - SecurityAdvisory: github.SecurityAdvisory{ - GHSAID: new("GHSA-xxxx-xxxx-xxxx"), - Summary: new("Test advisory"), - Description: new("This is a test advisory."), - Severity: new("high"), - }, + GHSAID: new("GHSA-xxxx-xxxx-xxxx"), + Summary: new("Test advisory"), + Description: new("This is a test advisory."), + Severity: new("high"), } tests := []struct { @@ -144,12 +142,10 @@ func Test_GetGlobalSecurityAdvisory(t *testing.T) { // Setup mock advisory for success case mockAdvisory := &github.GlobalSecurityAdvisory{ - SecurityAdvisory: github.SecurityAdvisory{ - GHSAID: new("GHSA-xxxx-xxxx-xxxx"), - Summary: new("Test advisory"), - Description: new("This is a test advisory."), - Severity: new("high"), - }, + GHSAID: new("GHSA-xxxx-xxxx-xxxx"), + Summary: new("Test advisory"), + Description: new("This is a test advisory."), + Severity: new("high"), } tests := []struct { diff --git a/pkg/github/typed_actions_outputs_test.go b/pkg/github/typed_actions_outputs_test.go index 7e7a8dbab4..cc99ae3370 100644 --- a/pkg/github/typed_actions_outputs_test.go +++ b/pkg/github/typed_actions_outputs_test.go @@ -381,7 +381,7 @@ func TestTypedActionsMinimalProjection(t *testing.T) { projected string }{ { - actionsWireCase: actionsWireCase{name: "actions_get", method: "get_workflow", args: map[string]any{"resource_id": "ci.yml"}, path: "/repos/owner/repo/actions/workflows/ci.yml", status: 200}, + name: "actions_get", method: "get_workflow", args: map[string]any{"resource_id": "ci.yml"}, path: "/repos/owner/repo/actions/workflows/ci.yml", status: 200, raw: &github.Workflow{ ID: new(int64(2)), Name: new("CI"), State: new("active"), Path: new(".github/workflows/ci.yml"), NodeID: new("node"), URL: new("https://api.github.com/workflows/2"), @@ -390,14 +390,14 @@ func TestTypedActionsMinimalProjection(t *testing.T) { projected: `{"id":2,"name":"CI","state":"active","path":".github/workflows/ci.yml","html_url":"https://github.com/owner/repo/actions/workflows/ci.yml"}`, }, { - actionsWireCase: actionsWireCase{name: "actions_list", method: "list_workflows", path: "/repos/owner/repo/actions/workflows", query: "page=1&per_page=30", status: 200}, + name: "actions_list", method: "list_workflows", path: "/repos/owner/repo/actions/workflows", query: "page=1&per_page=30", status: 200, raw: &github.Workflows{TotalCount: new(1), Workflows: []*github.Workflow{{ ID: new(int64(2)), Name: new("CI"), URL: new("https://api.github.com/workflows/2"), BadgeURL: new("https://badge"), }}}, projected: `{"total_count":1,"workflows":[{"id":2,"name":"CI"}]}`, }, { - actionsWireCase: actionsWireCase{name: "actions_list", method: "list_workflow_run_artifacts", args: map[string]any{"resource_id": "7"}, path: "/repos/owner/repo/actions/runs/7/artifacts", query: "page=1&per_page=30", status: 200}, + name: "actions_list", method: "list_workflow_run_artifacts", args: map[string]any{"resource_id": "7"}, path: "/repos/owner/repo/actions/runs/7/artifacts", query: "page=1&per_page=30", status: 200, raw: &github.ArtifactList{TotalCount: new(int64(1)), Artifacts: []*github.Artifact{{ ID: new(int64(9)), Name: new("build"), SizeInBytes: new(int64(0)), Expired: new(false), Digest: new("sha256:abc"), NodeID: new("node"), URL: new("https://api.github.com/artifacts/9"), @@ -407,7 +407,7 @@ func TestTypedActionsMinimalProjection(t *testing.T) { projected: `{"total_count":1,"artifacts":[{"id":9,"name":"build","size_in_bytes":0,"expired":false,"digest":"sha256:abc","workflow_run":{"id":7,"head_branch":"main","head_sha":"abc"}}]}`, }, { - actionsWireCase: actionsWireCase{name: "actions_get", method: "get_workflow_job", args: map[string]any{"resource_id": "8"}, path: "/repos/owner/repo/actions/jobs/8", status: 200}, + name: "actions_get", method: "get_workflow_job", args: map[string]any{"resource_id": "8"}, path: "/repos/owner/repo/actions/jobs/8", status: 200, raw: &github.WorkflowJob{ ID: new(int64(8)), RunID: new(int64(7)), Name: new("test"), Status: new("completed"), Conclusion: new("failure"), NodeID: new("node"), URL: new("https://api.github.com/jobs/8"), RunURL: new("https://api.github.com/runs/7"), @@ -416,7 +416,7 @@ func TestTypedActionsMinimalProjection(t *testing.T) { projected: `{"id":8,"run_id":7,"name":"test","status":"completed","conclusion":"failure","html_url":"https://github.com/owner/repo/actions/runs/7/job/8"}`, }, { - actionsWireCase: actionsWireCase{name: "actions_get", method: "get_workflow_run_usage", args: map[string]any{"resource_id": "7"}, path: "/repos/owner/repo/actions/runs/7/timing", status: 200}, + name: "actions_get", method: "get_workflow_run_usage", args: map[string]any{"resource_id": "7"}, path: "/repos/owner/repo/actions/runs/7/timing", status: 200, raw: &github.WorkflowRunUsage{RunDurationMS: new(int64(42)), Billable: &github.WorkflowRunBillMap{ "CUSTOM": {TotalMS: new(int64(42)), Jobs: new(1), JobRuns: []*github.WorkflowRunJobRun{{JobID: new(8), DurationMS: new(int64(42))}}}, "ANOTHER": nil, diff --git a/pkg/github/typed_security_outputs_test.go b/pkg/github/typed_security_outputs_test.go index 414e8cb7a8..e793fcbbd2 100644 --- a/pkg/github/typed_security_outputs_test.go +++ b/pkg/github/typed_security_outputs_test.go @@ -326,7 +326,7 @@ func TestGlobalSecurityAdvisoryCWEIDs(t *testing.T) { } { t.Run(tc.name, func(t *testing.T) { advisory := github.GlobalSecurityAdvisory{ - SecurityAdvisory: github.SecurityAdvisory{CWEIDs: tc.cweIDs, CWEs: tc.cwes}, + CWEIDs: tc.cweIDs, CWEs: tc.cwes, } assert.Equal(t, tc.expected, globalSecurityAdvisoryOutput(&advisory).CWEIDs) assert.Equal(t, tc.cweIDs, advisory.CWEIDs, "projection must not mutate the API model") diff --git a/pkg/github/ui_tools.go b/pkg/github/ui_tools.go index 84c6aae81f..03673efd62 100644 --- a/pkg/github/ui_tools.go +++ b/pkg/github/ui_tools.go @@ -247,8 +247,8 @@ func uiGetMilestones(ctx context.Context, deps ToolDependencies, args map[string } opts := &github.MilestoneListOptions{ - State: "open", - ListOptions: github.ListOptions{PerPage: 100}, + State: "open", + PerPage: 100, } var allMilestones []*github.Milestone @@ -340,7 +340,7 @@ func uiGetBranches(ctx context.Context, deps ToolDependencies, args map[string]a } opts := &github.BranchListOptions{ - ListOptions: github.ListOptions{PerPage: 100}, + PerPage: 100, } var allBranches []*github.Branch @@ -479,7 +479,7 @@ func uiGetReviewers(ctx context.Context, deps ToolDependencies, args map[string] collaboratorOpts := &github.ListCollaboratorsOptions{ Affiliation: "all", - ListOptions: github.ListOptions{PerPage: 100}, + PerPage: 100, } var allCollaborators []*github.User hasMore := false diff --git a/pkg/http/transport/etag_test.go b/pkg/http/transport/etag_test.go index 36b6613f09..a89b42db82 100644 --- a/pkg/http/transport/etag_test.go +++ b/pkg/http/transport/etag_test.go @@ -62,7 +62,7 @@ func TestETagTransport_ServesCachedBodyOn304(t *testing.T) { })) defer server.Close() - rt := &ETagTransport{Transport: http.DefaultTransport} + rt := &ETagTransport{Transport: newIsolatedTransport(t)} do := func() (int, string) { req, err := http.NewRequestWithContext(context.Background(), http.MethodGet, server.URL, nil) @@ -110,7 +110,7 @@ func TestETagTransport_UpdatesRateLimitHeadersFrom304(t *testing.T) { })) defer server.Close() - rt := &ETagTransport{Transport: http.DefaultTransport} + rt := &ETagTransport{Transport: newIsolatedTransport(t)} do := func() http.Header { req, err := http.NewRequestWithContext(context.Background(), http.MethodGet, server.URL, nil) @@ -147,7 +147,7 @@ func TestETagTransport_ScopesCacheByAuthorization(t *testing.T) { })) defer server.Close() - rt := &ETagTransport{Transport: http.DefaultTransport} + rt := &ETagTransport{Transport: newIsolatedTransport(t)} get := func(auth string) string { req, err := http.NewRequestWithContext(context.Background(), http.MethodGet, server.URL, nil) @@ -181,7 +181,7 @@ func TestETagTransport_OnlyCachesGET(t *testing.T) { })) defer server.Close() - rt := &ETagTransport{Transport: http.DefaultTransport} + rt := &ETagTransport{Transport: newIsolatedTransport(t)} do := func() { req, err := http.NewRequestWithContext(context.Background(), http.MethodPost, server.URL, nil) @@ -209,7 +209,7 @@ func TestETagTransport_DoesNotOverrideCallerConditional(t *testing.T) { })) defer server.Close() - rt := &ETagTransport{Transport: http.DefaultTransport} + rt := &ETagTransport{Transport: newIsolatedTransport(t)} req, err := http.NewRequestWithContext(context.Background(), http.MethodGet, server.URL, nil) require.NoError(t, err) @@ -240,7 +240,7 @@ func TestETagTransport_SkipsBodiesOverEntryByteBudget(t *testing.T) { })) defer server.Close() - rt := &ETagTransport{Transport: http.DefaultTransport, MaxEntryBytes: 16} + rt := &ETagTransport{Transport: newIsolatedTransport(t), MaxEntryBytes: 16} do := func() []byte { req, err := http.NewRequestWithContext(context.Background(), http.MethodGet, server.URL, nil) @@ -316,7 +316,7 @@ func TestETagTransport_EvictsByTotalByteBudget(t *testing.T) { defer server.Close() // Budget holds a single 10-byte entry; a second entry evicts the first. - rt := &ETagTransport{Transport: http.DefaultTransport, MaxTotalBytes: 15} + rt := &ETagTransport{Transport: newIsolatedTransport(t), MaxTotalBytes: 15} get := func(path string) { req, err := http.NewRequestWithContext(context.Background(), http.MethodGet, server.URL+path, nil) @@ -349,7 +349,7 @@ func TestETagTransport_DoesNotCacheNoStoreResponse(t *testing.T) { })) defer server.Close() - rt := &ETagTransport{Transport: http.DefaultTransport} + rt := &ETagTransport{Transport: newIsolatedTransport(t)} do := func() { req, err := http.NewRequestWithContext(context.Background(), http.MethodGet, server.URL, nil) @@ -380,7 +380,7 @@ func TestETagTransport_DoesNotCacheVaryStar(t *testing.T) { })) defer server.Close() - rt := &ETagTransport{Transport: http.DefaultTransport} + rt := &ETagTransport{Transport: newIsolatedTransport(t)} do := func() { req, err := http.NewRequestWithContext(context.Background(), http.MethodGet, server.URL, nil) @@ -411,7 +411,7 @@ func TestETagTransport_RequestNoStoreBypassesCache(t *testing.T) { })) defer server.Close() - rt := &ETagTransport{Transport: http.DefaultTransport} + rt := &ETagTransport{Transport: newIsolatedTransport(t)} // Prime the cache with a normal GET. req, err := http.NewRequestWithContext(context.Background(), http.MethodGet, server.URL, nil) diff --git a/pkg/http/transport/user_agent_test.go b/pkg/http/transport/user_agent_test.go index 9757b4937f..b2da10e6d5 100644 --- a/pkg/http/transport/user_agent_test.go +++ b/pkg/http/transport/user_agent_test.go @@ -18,7 +18,7 @@ func TestUserAgentTransportRequestIsolation(t *testing.T) { })) t.Cleanup(server.Close) transport := &UserAgentTransport{ - Transport: http.DefaultTransport, + Transport: newIsolatedTransport(t), Agent: "github-mcp-server/remote-abcdef", } client := &http.Client{Transport: transport}