Skip to content

Commit 4809bcf

Browse files
Merge branch 'main' into SamMorrowDrums/server-tool-refactor
2 parents 911bd20 + f32af95 commit 4809bcf

File tree

6 files changed

+276
-81
lines changed

6 files changed

+276
-81
lines changed

.github/workflows/docker-publish.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ jobs:
8787
type=raw,value=latest,enable=${{ github.ref_type == 'tag' && startsWith(github.ref, 'refs/tags/v') && !contains(github.ref, '-') }}
8888
8989
- name: Go Build Cache for Docker
90-
uses: actions/cache@v4
90+
uses: actions/cache@v5
9191
with:
9292
path: go-build-cache
9393
key: ${{ runner.os }}-go-build-cache-${{ hashFiles('**/go.sum') }}

go.mod

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ require (
2323
github.com/gorilla/mux v1.8.0 // indirect
2424
github.com/josharian/intern v1.0.0 // indirect
2525
github.com/mailru/easyjson v0.7.7 // indirect
26+
github.com/stretchr/objx v0.5.2 // indirect
2627
github.com/yudai/golcs v0.0.0-20170316035057-ecda9a501e82 // indirect
2728
go.yaml.in/yaml/v3 v3.0.4 // indirect
2829
golang.org/x/exp v0.0.0-20240719175910-8a7402abbf56 // indirect

go.sum

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,8 @@ github.com/spf13/pflag v1.0.10/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3A
8888
github.com/spf13/viper v1.21.0 h1:x5S+0EU27Lbphp4UKm1C+1oQO+rKx36vfCoaVebLFSU=
8989
github.com/spf13/viper v1.21.0/go.mod h1:P0lhsswPGWD/1lZJ9ny3fYnVqxiegrlNrEmgLjbTCAY=
9090
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
91+
github.com/stretchr/objx v0.5.2 h1:xuMeJ0Sdp5ZMRXx/aWO6RZxdr3beISkG5/G/aIRr3pY=
92+
github.com/stretchr/objx v0.5.2/go.mod h1:FRsXN1f5AsAjCGJKqEizvkpNtU+EGNCLh3NxZ/8L+MA=
9193
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
9294
github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
9395
github.com/stretchr/testify v1.11.1 h1:7s2iGBzp5EwR7/aIZr8ao5+dra3wiQyKjjFuvgVKu7U=

pkg/github/code_scanning_test.go

Lines changed: 24 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import (
1010
"github.com/github/github-mcp-server/pkg/translations"
1111
"github.com/google/go-github/v79/github"
1212
"github.com/google/jsonschema-go/jsonschema"
13-
"github.com/migueleliasweb/go-github-mock/src/mock"
1413
"github.com/stretchr/testify/assert"
1514
"github.com/stretchr/testify/require"
1615
)
@@ -49,12 +48,9 @@ func Test_GetCodeScanningAlert(t *testing.T) {
4948
}{
5049
{
5150
name: "successful alert fetch",
52-
mockedClient: mock.NewMockedHTTPClient(
53-
mock.WithRequestMatch(
54-
mock.GetReposCodeScanningAlertsByOwnerByRepoByAlertNumber,
55-
mockAlert,
56-
),
57-
),
51+
mockedClient: MockHTTPClientWithHandlers(map[string]http.HandlerFunc{
52+
GetReposCodeScanningAlertsByOwnerByRepoByAlertNumber: mockResponse(t, http.StatusOK, mockAlert),
53+
}),
5854
requestArgs: map[string]interface{}{
5955
"owner": "owner",
6056
"repo": "repo",
@@ -65,15 +61,12 @@ func Test_GetCodeScanningAlert(t *testing.T) {
6561
},
6662
{
6763
name: "alert fetch fails",
68-
mockedClient: mock.NewMockedHTTPClient(
69-
mock.WithRequestMatchHandler(
70-
mock.GetReposCodeScanningAlertsByOwnerByRepoByAlertNumber,
71-
http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) {
72-
w.WriteHeader(http.StatusNotFound)
73-
_, _ = w.Write([]byte(`{"message": "Not Found"}`))
74-
}),
75-
),
76-
),
64+
mockedClient: MockHTTPClientWithHandlers(map[string]http.HandlerFunc{
65+
GetReposCodeScanningAlertsByOwnerByRepoByAlertNumber: http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) {
66+
w.WriteHeader(http.StatusNotFound)
67+
_, _ = w.Write([]byte(`{"message": "Not Found"}`))
68+
}),
69+
}),
7770
requestArgs: map[string]interface{}{
7871
"owner": "owner",
7972
"repo": "repo",
@@ -172,19 +165,16 @@ func Test_ListCodeScanningAlerts(t *testing.T) {
172165
}{
173166
{
174167
name: "successful alerts listing",
175-
mockedClient: mock.NewMockedHTTPClient(
176-
mock.WithRequestMatchHandler(
177-
mock.GetReposCodeScanningAlertsByOwnerByRepo,
178-
expectQueryParams(t, map[string]string{
179-
"ref": "main",
180-
"state": "open",
181-
"severity": "high",
182-
"tool_name": "codeql",
183-
}).andThen(
184-
mockResponse(t, http.StatusOK, mockAlerts),
185-
),
168+
mockedClient: MockHTTPClientWithHandlers(map[string]http.HandlerFunc{
169+
GetReposCodeScanningAlertsByOwnerByRepo: expectQueryParams(t, map[string]string{
170+
"ref": "main",
171+
"state": "open",
172+
"severity": "high",
173+
"tool_name": "codeql",
174+
}).andThen(
175+
mockResponse(t, http.StatusOK, mockAlerts),
186176
),
187-
),
177+
}),
188178
requestArgs: map[string]interface{}{
189179
"owner": "owner",
190180
"repo": "repo",
@@ -198,15 +188,12 @@ func Test_ListCodeScanningAlerts(t *testing.T) {
198188
},
199189
{
200190
name: "alerts listing fails",
201-
mockedClient: mock.NewMockedHTTPClient(
202-
mock.WithRequestMatchHandler(
203-
mock.GetReposCodeScanningAlertsByOwnerByRepo,
204-
http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) {
205-
w.WriteHeader(http.StatusUnauthorized)
206-
_, _ = w.Write([]byte(`{"message": "Unauthorized access"}`))
207-
}),
208-
),
209-
),
191+
mockedClient: MockHTTPClientWithHandlers(map[string]http.HandlerFunc{
192+
GetReposCodeScanningAlertsByOwnerByRepo: http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) {
193+
w.WriteHeader(http.StatusUnauthorized)
194+
_, _ = w.Write([]byte(`{"message": "Unauthorized access"}`))
195+
}),
196+
}),
210197
requestArgs: map[string]interface{}{
211198
"owner": "owner",
212199
"repo": "repo",

pkg/github/git_test.go

Lines changed: 21 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ import (
1111
"github.com/github/github-mcp-server/pkg/translations"
1212
"github.com/google/go-github/v79/github"
1313
"github.com/google/jsonschema-go/jsonschema"
14-
"github.com/migueleliasweb/go-github-mock/src/mock"
1514
"github.com/stretchr/testify/assert"
1615
"github.com/stretchr/testify/require"
1716
)
@@ -70,33 +69,21 @@ func Test_GetRepositoryTree(t *testing.T) {
7069
}{
7170
{
7271
name: "successfully get repository tree",
73-
mockedClient: mock.NewMockedHTTPClient(
74-
mock.WithRequestMatchHandler(
75-
mock.GetReposByOwnerByRepo,
76-
mockResponse(t, http.StatusOK, mockRepo),
77-
),
78-
mock.WithRequestMatchHandler(
79-
mock.GetReposGitTreesByOwnerByRepoByTreeSha,
80-
mockResponse(t, http.StatusOK, mockTree),
81-
),
82-
),
72+
mockedClient: MockHTTPClientWithHandlers(map[string]http.HandlerFunc{
73+
GetReposByOwnerByRepo: mockResponse(t, http.StatusOK, mockRepo),
74+
GetReposGitTreesByOwnerByRepoByTree: mockResponse(t, http.StatusOK, mockTree),
75+
}),
8376
requestArgs: map[string]interface{}{
8477
"owner": "owner",
8578
"repo": "repo",
8679
},
8780
},
8881
{
8982
name: "successfully get repository tree with path filter",
90-
mockedClient: mock.NewMockedHTTPClient(
91-
mock.WithRequestMatchHandler(
92-
mock.GetReposByOwnerByRepo,
93-
mockResponse(t, http.StatusOK, mockRepo),
94-
),
95-
mock.WithRequestMatchHandler(
96-
mock.GetReposGitTreesByOwnerByRepoByTreeSha,
97-
mockResponse(t, http.StatusOK, mockTree),
98-
),
99-
),
83+
mockedClient: MockHTTPClientWithHandlers(map[string]http.HandlerFunc{
84+
GetReposByOwnerByRepo: mockResponse(t, http.StatusOK, mockRepo),
85+
GetReposGitTreesByOwnerByRepoByTree: mockResponse(t, http.StatusOK, mockTree),
86+
}),
10087
requestArgs: map[string]interface{}{
10188
"owner": "owner",
10289
"repo": "repo",
@@ -105,15 +92,12 @@ func Test_GetRepositoryTree(t *testing.T) {
10592
},
10693
{
10794
name: "repository not found",
108-
mockedClient: mock.NewMockedHTTPClient(
109-
mock.WithRequestMatchHandler(
110-
mock.GetReposByOwnerByRepo,
111-
http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) {
112-
w.WriteHeader(http.StatusNotFound)
113-
_, _ = w.Write([]byte(`{"message": "Not Found"}`))
114-
}),
115-
),
116-
),
95+
mockedClient: MockHTTPClientWithHandlers(map[string]http.HandlerFunc{
96+
GetReposByOwnerByRepo: http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) {
97+
w.WriteHeader(http.StatusNotFound)
98+
_, _ = w.Write([]byte(`{"message": "Not Found"}`))
99+
}),
100+
}),
117101
requestArgs: map[string]interface{}{
118102
"owner": "owner",
119103
"repo": "nonexistent",
@@ -123,19 +107,13 @@ func Test_GetRepositoryTree(t *testing.T) {
123107
},
124108
{
125109
name: "tree not found",
126-
mockedClient: mock.NewMockedHTTPClient(
127-
mock.WithRequestMatchHandler(
128-
mock.GetReposByOwnerByRepo,
129-
mockResponse(t, http.StatusOK, mockRepo),
130-
),
131-
mock.WithRequestMatchHandler(
132-
mock.GetReposGitTreesByOwnerByRepoByTreeSha,
133-
http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) {
134-
w.WriteHeader(http.StatusNotFound)
135-
_, _ = w.Write([]byte(`{"message": "Not Found"}`))
136-
}),
137-
),
138-
),
110+
mockedClient: MockHTTPClientWithHandlers(map[string]http.HandlerFunc{
111+
GetReposByOwnerByRepo: mockResponse(t, http.StatusOK, mockRepo),
112+
GetReposGitTreesByOwnerByRepoByTree: http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) {
113+
w.WriteHeader(http.StatusNotFound)
114+
_, _ = w.Write([]byte(`{"message": "Not Found"}`))
115+
}),
116+
}),
139117
requestArgs: map[string]interface{}{
140118
"owner": "owner",
141119
"repo": "repo",

0 commit comments

Comments
 (0)