Skip to content

Commit 5904a03

Browse files
JoannaaKLCopilot
andauthored
Fix linting flow (#614)
* Add issues type filter * Add e2e test * Update e2e/e2e_test.go Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Add lint script and update golangci config * Add lint script * Install if not installed * Pass lint config * Use action and rename workflow * Back to reparate config * Migrate config to v2 * Update config * Lint code --------- Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
1 parent 05456fb commit 5904a03

File tree

15 files changed

+89
-107
lines changed

15 files changed

+89
-107
lines changed

.github/workflows/go.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: Unit Tests
1+
name: Build and Test Go Project
22
on: [push, pull_request]
33

44
permissions:

.github/workflows/lint.yaml

Lines changed: 0 additions & 45 deletions
This file was deleted.

.github/workflows/lint.yml

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
name: golangci-lint
2+
on:
3+
push:
4+
branches:
5+
- main
6+
pull_request:
7+
8+
permissions:
9+
contents: read
10+
11+
jobs:
12+
golangci:
13+
name: lint
14+
runs-on: ubuntu-latest
15+
steps:
16+
- uses: actions/checkout@v4
17+
- uses: actions/setup-go@v5
18+
with:
19+
go-version: stable
20+
- name: golangci-lint
21+
uses: golangci/golangci-lint-action@v8
22+
with:
23+
version: v2.1

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,4 @@ __debug_bin*
1111

1212
# Go
1313
vendor
14+
bin/

.golangci.yml

Lines changed: 25 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,47 +1,37 @@
1-
# https://golangci-lint.run/usage/configuration
21
version: "2"
3-
42
run:
5-
timeout: 5m
6-
tests: true
73
concurrency: 4
8-
4+
tests: true
95
linters:
106
enable:
11-
- govet
12-
- errcheck
13-
- staticcheck
14-
- revive
15-
- ineffassign
16-
- unused
17-
- misspell
18-
- nakedret
197
- bodyclose
208
- gocritic
21-
- makezero
229
- gosec
10+
- makezero
11+
- misspell
12+
- nakedret
13+
- revive
14+
exclusions:
15+
generated: lax
16+
presets:
17+
- comments
18+
- common-false-positives
19+
- legacy
20+
- std-error-handling
21+
paths:
22+
- third_party$
23+
- builtin$
24+
- examples$
2325
settings:
2426
staticcheck:
2527
checks:
26-
- all
27-
- '-QF1008' # Allow embedded structs to be referenced by field
28-
- '-ST1000' # Do not require package comments
29-
revive:
30-
rules:
31-
- name: exported
32-
disabled: true
33-
- name: exported
34-
disabled: true
35-
- name: package-comments
36-
disabled: true
37-
28+
- "all"
29+
- -QF1008
30+
- -ST1000
3831
formatters:
39-
enable:
40-
- gofmt
41-
- goimports
42-
43-
output:
44-
formats:
45-
text:
46-
print-linter-name: true
47-
print-issued-lines: true
32+
exclusions:
33+
generated: lax
34+
paths:
35+
- third_party$
36+
- builtin$
37+
- examples$

cmd/github-mcp-server/generate_docs.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ var generateDocsCmd = &cobra.Command{
2323
Use: "generate-docs",
2424
Short: "Generate documentation for tools and toolsets",
2525
Long: `Generate the automated sections of README.md and docs/remote-server.md with current tool and toolset information.`,
26-
RunE: func(cmd *cobra.Command, args []string) error {
26+
RunE: func(_ *cobra.Command, _ []string) error {
2727
return generateAllDocs()
2828
},
2929
}
@@ -33,17 +33,17 @@ func init() {
3333
}
3434

3535
// mockGetClient returns a mock GitHub client for documentation generation
36-
func mockGetClient(ctx context.Context) (*gogithub.Client, error) {
36+
func mockGetClient(_ context.Context) (*gogithub.Client, error) {
3737
return gogithub.NewClient(nil), nil
3838
}
3939

4040
// mockGetGQLClient returns a mock GraphQL client for documentation generation
41-
func mockGetGQLClient(ctx context.Context) (*githubv4.Client, error) {
41+
func mockGetGQLClient(_ context.Context) (*githubv4.Client, error) {
4242
return githubv4.NewClient(nil), nil
4343
}
4444

4545
// mockGetRawClient returns a mock raw client for documentation generation
46-
func mockGetRawClient(ctx context.Context) (*raw.Client, error) {
46+
func mockGetRawClient(_ context.Context) (*raw.Client, error) {
4747
return nil, nil
4848
}
4949

cmd/github-mcp-server/main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ func main() {
103103
}
104104
}
105105

106-
func wordSepNormalizeFunc(f *pflag.FlagSet, name string) pflag.NormalizedName {
106+
func wordSepNormalizeFunc(_ *pflag.FlagSet, name string) pflag.NormalizedName {
107107
from := []string{"_"}
108108
to := "-"
109109
for _, sep := range from {

pkg/errors/error_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,7 @@ func TestGitHubErrorContext(t *testing.T) {
260260

261261
t.Run("NewGitHubAPIErrorToCtx with nil context does not error", func(t *testing.T) {
262262
// Given a nil context
263-
var ctx context.Context = nil
263+
var ctx context.Context
264264

265265
// Create a mock GitHub response
266266
resp := &github.Response{

pkg/github/actions_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -538,7 +538,7 @@ func Test_DownloadWorkflowRunArtifact(t *testing.T) {
538538
Pattern: "/repos/owner/repo/actions/artifacts/123/zip",
539539
Method: "GET",
540540
},
541-
http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
541+
http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) {
542542
// GitHub returns a 302 redirect to the download URL
543543
w.Header().Set("Location", "https://api.github.com/repos/owner/repo/actions/artifacts/123/download")
544544
w.WriteHeader(http.StatusFound)
@@ -1055,7 +1055,7 @@ func Test_GetJobLogs_WithContentReturn(t *testing.T) {
10551055
logContent := "2023-01-01T10:00:00.000Z Starting job...\n2023-01-01T10:00:01.000Z Running tests...\n2023-01-01T10:00:02.000Z Job completed successfully"
10561056

10571057
// Create a test server to serve log content
1058-
testServer := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
1058+
testServer := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) {
10591059
w.WriteHeader(http.StatusOK)
10601060
_, _ = w.Write([]byte(logContent))
10611061
}))

pkg/github/issues.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -893,7 +893,7 @@ func AssignCodingAgentPrompt(t translations.TranslationHelperFunc) (tool mcp.Pro
893893
return mcp.NewPrompt("AssignCodingAgent",
894894
mcp.WithPromptDescription(t("PROMPT_ASSIGN_CODING_AGENT_DESCRIPTION", "Assign GitHub Coding Agent to multiple tasks in a GitHub repository.")),
895895
mcp.WithArgument("repo", mcp.ArgumentDescription("The repository to assign tasks in (owner/repo)."), mcp.RequiredArgument()),
896-
), func(ctx context.Context, request mcp.GetPromptRequest) (*mcp.GetPromptResult, error) {
896+
), func(_ context.Context, request mcp.GetPromptRequest) (*mcp.GetPromptResult, error) {
897897
repo := request.Params.Arguments["repo"]
898898

899899
messages := []mcp.PromptMessage{

pkg/github/repositories.go

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -491,7 +491,7 @@ func GetFileContents(getClient GetClientFn, getRawClient raw.GetRawClientFn, t t
491491
return mcp.NewToolResultError(err.Error()), nil
492492
}
493493

494-
rawOpts := &raw.RawContentOpts{}
494+
rawOpts := &raw.ContentOpts{}
495495

496496
if strings.HasPrefix(ref, "refs/pull/") {
497497
prNumber := strings.TrimSuffix(strings.TrimPrefix(ref, "refs/pull/"), "/head")
@@ -532,9 +532,7 @@ func GetFileContents(getClient GetClientFn, getRawClient raw.GetRawClientFn, t t
532532
_ = resp.Body.Close()
533533
}()
534534

535-
if resp.StatusCode != http.StatusOK {
536-
// If the raw content is not found, we will fall back to the GitHub API (in case it is a directory)
537-
} else {
535+
if resp.StatusCode == http.StatusOK {
538536
// If the raw content is found, return it directly
539537
body, err := io.ReadAll(resp.Body)
540538
if err != nil {

pkg/github/repository_resource.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ func RepositoryResourceContentsHandler(getClient GetClientFn, getRawClient raw.G
8989
}
9090

9191
opts := &github.RepositoryContentGetOptions{}
92-
rawOpts := &raw.RawContentOpts{}
92+
rawOpts := &raw.ContentOpts{}
9393

9494
sha, ok := request.Params.Arguments["sha"].([]string)
9595
if ok && len(sha) > 0 {

pkg/raw/raw.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,9 @@ func (c *Client) refURL(owner, repo, ref, path string) string {
4141
return c.url.JoinPath(owner, repo, ref, path).String()
4242
}
4343

44-
func (c *Client) URLFromOpts(opts *RawContentOpts, owner, repo, path string) string {
44+
func (c *Client) URLFromOpts(opts *ContentOpts, owner, repo, path string) string {
4545
if opts == nil {
46-
opts = &RawContentOpts{}
46+
opts = &ContentOpts{}
4747
}
4848
if opts.SHA != "" {
4949
return c.commitURL(owner, repo, opts.SHA, path)
@@ -56,13 +56,13 @@ func (c *Client) commitURL(owner, repo, sha, path string) string {
5656
return c.url.JoinPath(owner, repo, sha, path).String()
5757
}
5858

59-
type RawContentOpts struct {
59+
type ContentOpts struct {
6060
Ref string
6161
SHA string
6262
}
6363

6464
// GetRawContent fetches the raw content of a file from a GitHub repository.
65-
func (c *Client) GetRawContent(ctx context.Context, owner, repo, path string, opts *RawContentOpts) (*http.Response, error) {
65+
func (c *Client) GetRawContent(ctx context.Context, owner, repo, path string, opts *ContentOpts) (*http.Response, error) {
6666
url := c.URLFromOpts(opts, owner, repo, path)
6767
req, err := c.newRequest(ctx, "GET", url, nil)
6868
if err != nil {

pkg/raw/raw_test.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ func TestGetRawContent(t *testing.T) {
1717
tests := []struct {
1818
name string
1919
pattern mock.EndpointPattern
20-
opts *RawContentOpts
20+
opts *ContentOpts
2121
owner, repo, path string
2222
statusCode int
2323
contentType string
@@ -36,7 +36,7 @@ func TestGetRawContent(t *testing.T) {
3636
{
3737
name: "branch fetch success",
3838
pattern: GetRawReposContentsByOwnerByRepoByBranchByPath,
39-
opts: &RawContentOpts{Ref: "refs/heads/main"},
39+
opts: &ContentOpts{Ref: "refs/heads/main"},
4040
owner: "octocat", repo: "hello", path: "README.md",
4141
statusCode: 200,
4242
contentType: "text/plain",
@@ -45,7 +45,7 @@ func TestGetRawContent(t *testing.T) {
4545
{
4646
name: "tag fetch success",
4747
pattern: GetRawReposContentsByOwnerByRepoByTagByPath,
48-
opts: &RawContentOpts{Ref: "refs/tags/v1.0.0"},
48+
opts: &ContentOpts{Ref: "refs/tags/v1.0.0"},
4949
owner: "octocat", repo: "hello", path: "README.md",
5050
statusCode: 200,
5151
contentType: "text/plain",
@@ -54,7 +54,7 @@ func TestGetRawContent(t *testing.T) {
5454
{
5555
name: "sha fetch success",
5656
pattern: GetRawReposContentsByOwnerByRepoBySHAByPath,
57-
opts: &RawContentOpts{SHA: "abc123"},
57+
opts: &ContentOpts{SHA: "abc123"},
5858
owner: "octocat", repo: "hello", path: "README.md",
5959
statusCode: 200,
6060
contentType: "text/plain",
@@ -107,7 +107,7 @@ func TestUrlFromOpts(t *testing.T) {
107107

108108
tests := []struct {
109109
name string
110-
opts *RawContentOpts
110+
opts *ContentOpts
111111
owner string
112112
repo string
113113
path string
@@ -121,19 +121,19 @@ func TestUrlFromOpts(t *testing.T) {
121121
},
122122
{
123123
name: "ref branch",
124-
opts: &RawContentOpts{Ref: "refs/heads/main"},
124+
opts: &ContentOpts{Ref: "refs/heads/main"},
125125
owner: "octocat", repo: "hello", path: "README.md",
126126
want: "https://raw.example.com/octocat/hello/refs/heads/main/README.md",
127127
},
128128
{
129129
name: "ref tag",
130-
opts: &RawContentOpts{Ref: "refs/tags/v1.0.0"},
130+
opts: &ContentOpts{Ref: "refs/tags/v1.0.0"},
131131
owner: "octocat", repo: "hello", path: "README.md",
132132
want: "https://raw.example.com/octocat/hello/refs/tags/v1.0.0/README.md",
133133
},
134134
{
135135
name: "sha",
136-
opts: &RawContentOpts{SHA: "abc123"},
136+
opts: &ContentOpts{SHA: "abc123"},
137137
owner: "octocat", repo: "hello", path: "README.md",
138138
want: "https://raw.example.com/octocat/hello/abc123/README.md",
139139
},

script/lint

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
set -eu
2+
3+
# first run go fmt
4+
gofmt -s -w .
5+
6+
BINDIR="$(git rev-parse --show-toplevel)"/bin
7+
BINARY=$BINDIR/golangci-lint
8+
GOLANGCI_LINT_VERSION=v2.2.1
9+
10+
11+
if [ ! -f "$BINARY" ]; then
12+
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s "$GOLANGCI_LINT_VERSION"
13+
fi
14+
15+
$BINARY run

0 commit comments

Comments
 (0)