Skip to content
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 31 additions & 34 deletions pkg/github/actions_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,14 @@
"github.com/github/github-mcp-server/pkg/translations"
"github.com/google/go-github/v79/github"
"github.com/google/jsonschema-go/jsonschema"
"github.com/migueleliasweb/go-github-mock/src/mock"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)

func newMockedHTTPClient(handlers map[string]http.HandlerFunc) *http.Client {

Check failure on line 25 in pkg/github/actions_test.go

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest)

other declaration of newMockedHTTPClient

Check failure on line 25 in pkg/github/actions_test.go

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest)

other declaration of newMockedHTTPClient

Check failure on line 25 in pkg/github/actions_test.go

View workflow job for this annotation

GitHub Actions / build (macos-latest)

other declaration of newMockedHTTPClient

Check failure on line 25 in pkg/github/actions_test.go

View workflow job for this annotation

GitHub Actions / build (macos-latest)

other declaration of newMockedHTTPClient

Check failure on line 25 in pkg/github/actions_test.go

View workflow job for this annotation

GitHub Actions / lint

other declaration of newMockedHTTPClient

Check failure on line 25 in pkg/github/actions_test.go

View workflow job for this annotation

GitHub Actions / lint

other declaration of newMockedHTTPClient

Check failure on line 25 in pkg/github/actions_test.go

View workflow job for this annotation

GitHub Actions / build (macos-latest)

other declaration of newMockedHTTPClient

Check failure on line 25 in pkg/github/actions_test.go

View workflow job for this annotation

GitHub Actions / build (macos-latest)

other declaration of newMockedHTTPClient

Check failure on line 25 in pkg/github/actions_test.go

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest)

other declaration of newMockedHTTPClient

Check failure on line 25 in pkg/github/actions_test.go

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest)

other declaration of newMockedHTTPClient
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot remove it, create new MockHTTPClientWithHandlers by creating a new instance just as other tests do

return MockHTTPClientWithHandlers(handlers)
}

func Test_ListWorkflows(t *testing.T) {
// Verify tool definition once
toolDef := ListWorkflows(translations.NullTranslationHelper)
Expand Down Expand Up @@ -1394,17 +1397,11 @@
}{
{
name: "successful rerun of failed jobs",
mockedClient: mock.NewMockedHTTPClient(
mock.WithRequestMatchHandler(
mock.EndpointPattern{
Pattern: "/repos/owner/repo/actions/runs/12345/rerun-failed-jobs",
Method: "POST",
},
http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) {
w.WriteHeader(http.StatusCreated)
}),
),
),
mockedClient: newMockedHTTPClient(map[string]http.HandlerFunc{
"POST /repos/owner/repo/actions/runs/12345/rerun-failed-jobs": http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) {
w.WriteHeader(http.StatusCreated)
}),
}),
requestArgs: map[string]any{
"owner": "owner",
"repo": "repo",
Expand All @@ -1414,7 +1411,7 @@
},
{
name: "missing required parameter run_id",
mockedClient: mock.NewMockedHTTPClient(),
mockedClient: MockHTTPClientWithHandlers(map[string]http.HandlerFunc{}),
requestArgs: map[string]any{
"owner": "owner",
"repo": "repo",
Expand Down Expand Up @@ -1466,9 +1463,9 @@
}{
{
name: "successful rerun of workflow run",
mockedClient: mock.NewMockedHTTPClient(

Check failure on line 1466 in pkg/github/actions_test.go

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest)

undefined: mock

Check failure on line 1466 in pkg/github/actions_test.go

View workflow job for this annotation

GitHub Actions / build (macos-latest)

undefined: mock

Check failure on line 1466 in pkg/github/actions_test.go

View workflow job for this annotation

GitHub Actions / lint

undefined: mock

Check failure on line 1466 in pkg/github/actions_test.go

View workflow job for this annotation

GitHub Actions / build (macos-latest)

undefined: mock

Check failure on line 1466 in pkg/github/actions_test.go

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest)

undefined: mock
mock.WithRequestMatchHandler(

Check failure on line 1467 in pkg/github/actions_test.go

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest)

undefined: mock

Check failure on line 1467 in pkg/github/actions_test.go

View workflow job for this annotation

GitHub Actions / build (macos-latest)

undefined: mock

Check failure on line 1467 in pkg/github/actions_test.go

View workflow job for this annotation

GitHub Actions / lint

undefined: mock

Check failure on line 1467 in pkg/github/actions_test.go

View workflow job for this annotation

GitHub Actions / build (macos-latest)

undefined: mock

Check failure on line 1467 in pkg/github/actions_test.go

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest)

undefined: mock
mock.EndpointPattern{

Check failure on line 1468 in pkg/github/actions_test.go

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest)

undefined: mock

Check failure on line 1468 in pkg/github/actions_test.go

View workflow job for this annotation

GitHub Actions / build (macos-latest)

undefined: mock

Check failure on line 1468 in pkg/github/actions_test.go

View workflow job for this annotation

GitHub Actions / lint

undefined: mock

Check failure on line 1468 in pkg/github/actions_test.go

View workflow job for this annotation

GitHub Actions / build (macos-latest)

undefined: mock

Check failure on line 1468 in pkg/github/actions_test.go

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest)

undefined: mock
Pattern: "/repos/owner/repo/actions/runs/12345/rerun",
Method: "POST",
},
Expand All @@ -1486,7 +1483,7 @@
},
{
name: "missing required parameter run_id",
mockedClient: mock.NewMockedHTTPClient(),
mockedClient: MockHTTPClientWithHandlers(map[string]http.HandlerFunc{}),
requestArgs: map[string]any{
"owner": "owner",
"repo": "repo",
Expand Down Expand Up @@ -1538,9 +1535,9 @@
}{
{
name: "successful workflow runs listing",
mockedClient: mock.NewMockedHTTPClient(

Check failure on line 1538 in pkg/github/actions_test.go

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest)

undefined: mock

Check failure on line 1538 in pkg/github/actions_test.go

View workflow job for this annotation

GitHub Actions / build (macos-latest)

undefined: mock

Check failure on line 1538 in pkg/github/actions_test.go

View workflow job for this annotation

GitHub Actions / lint

undefined: mock

Check failure on line 1538 in pkg/github/actions_test.go

View workflow job for this annotation

GitHub Actions / build (macos-latest)

undefined: mock

Check failure on line 1538 in pkg/github/actions_test.go

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest)

undefined: mock
mock.WithRequestMatchHandler(

Check failure on line 1539 in pkg/github/actions_test.go

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest)

undefined: mock

Check failure on line 1539 in pkg/github/actions_test.go

View workflow job for this annotation

GitHub Actions / build (macos-latest)

undefined: mock

Check failure on line 1539 in pkg/github/actions_test.go

View workflow job for this annotation

GitHub Actions / lint

undefined: mock

Check failure on line 1539 in pkg/github/actions_test.go

View workflow job for this annotation

GitHub Actions / build (macos-latest)

undefined: mock

Check failure on line 1539 in pkg/github/actions_test.go

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest)

undefined: mock
mock.GetReposActionsWorkflowsRunsByOwnerByRepoByWorkflowId,
mock.GetReposActionsWorkflowsRunsByOwnerByRepoByWorkflowID,

Check failure on line 1540 in pkg/github/actions_test.go

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest)

undefined: mock

Check failure on line 1540 in pkg/github/actions_test.go

View workflow job for this annotation

GitHub Actions / build (macos-latest)

undefined: mock

Check failure on line 1540 in pkg/github/actions_test.go

View workflow job for this annotation

GitHub Actions / lint

undefined: mock

Check failure on line 1540 in pkg/github/actions_test.go

View workflow job for this annotation

GitHub Actions / build (macos-latest)

undefined: mock

Check failure on line 1540 in pkg/github/actions_test.go

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest)

undefined: mock
http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) {
runs := &github.WorkflowRuns{
TotalCount: github.Ptr(2),
Expand Down Expand Up @@ -1573,7 +1570,7 @@
},
{
name: "missing required parameter workflow_id",
mockedClient: mock.NewMockedHTTPClient(),
mockedClient: MockHTTPClientWithHandlers(map[string]http.HandlerFunc{}),
requestArgs: map[string]any{
"owner": "owner",
"repo": "repo",
Expand Down Expand Up @@ -1627,7 +1624,7 @@
name: "successful get workflow run",
mockedClient: mock.NewMockedHTTPClient(
mock.WithRequestMatchHandler(
mock.GetReposActionsRunsByOwnerByRepoByRunId,
mock.GetReposActionsRunsByOwnerByRepoByRunID,
http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) {
run := &github.WorkflowRun{
ID: github.Ptr(int64(12345)),
Expand All @@ -1649,7 +1646,7 @@
},
{
name: "missing required parameter run_id",
mockedClient: mock.NewMockedHTTPClient(),
mockedClient: MockHTTPClientWithHandlers(map[string]http.HandlerFunc{}),
requestArgs: map[string]any{
"owner": "owner",
"repo": "repo",
Expand Down Expand Up @@ -1703,7 +1700,7 @@
name: "successful get workflow run logs",
mockedClient: mock.NewMockedHTTPClient(
mock.WithRequestMatchHandler(
mock.GetReposActionsRunsLogsByOwnerByRepoByRunId,
mock.GetReposActionsRunsLogsByOwnerByRepoByRunID,
http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) {
w.Header().Set("Location", "https://github.com/logs/run/12345")
w.WriteHeader(http.StatusFound)
Expand All @@ -1719,7 +1716,7 @@
},
{
name: "missing required parameter run_id",
mockedClient: mock.NewMockedHTTPClient(),
mockedClient: MockHTTPClientWithHandlers(map[string]http.HandlerFunc{}),
requestArgs: map[string]any{
"owner": "owner",
"repo": "repo",
Expand Down Expand Up @@ -1773,7 +1770,7 @@
name: "successful list workflow jobs",
mockedClient: mock.NewMockedHTTPClient(
mock.WithRequestMatchHandler(
mock.GetReposActionsRunsJobsByOwnerByRepoByRunId,
mock.GetReposActionsRunsJobsByOwnerByRepoByRunID,
http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) {
jobs := &github.Jobs{
TotalCount: github.Ptr(2),
Expand Down Expand Up @@ -1806,7 +1803,7 @@
},
{
name: "missing required parameter run_id",
mockedClient: mock.NewMockedHTTPClient(),
mockedClient: MockHTTPClientWithHandlers(map[string]http.HandlerFunc{}),
requestArgs: map[string]any{
"owner": "owner",
"repo": "repo",
Expand Down Expand Up @@ -1908,7 +1905,7 @@
},
{
name: "missing required parameter method",
mockedClient: mock.NewMockedHTTPClient(),
mockedClient: MockHTTPClientWithHandlers(map[string]http.HandlerFunc{}),
requestArgs: map[string]any{
"owner": "owner",
"repo": "repo",
Expand Down Expand Up @@ -1954,7 +1951,7 @@
t.Run("successful workflow runs list", func(t *testing.T) {
mockedClient := mock.NewMockedHTTPClient(
mock.WithRequestMatchHandler(
mock.GetReposActionsWorkflowsRunsByOwnerByRepoByWorkflowId,
mock.GetReposActionsWorkflowsRunsByOwnerByRepoByWorkflowID,
http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) {
runs := &github.WorkflowRuns{
TotalCount: github.Ptr(1),
Expand Down Expand Up @@ -2070,7 +2067,7 @@
t.Run("successful workflow get", func(t *testing.T) {
mockedClient := mock.NewMockedHTTPClient(
mock.WithRequestMatchHandler(
mock.GetReposActionsWorkflowsByOwnerByRepoByWorkflowId,
mock.GetReposActionsWorkflowsByOwnerByRepoByWorkflowID,
http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) {
workflow := &github.Workflow{
ID: github.Ptr(int64(1)),
Expand Down Expand Up @@ -2116,7 +2113,7 @@
t.Run("successful workflow run get", func(t *testing.T) {
mockedClient := mock.NewMockedHTTPClient(
mock.WithRequestMatchHandler(
mock.GetReposActionsRunsByOwnerByRepoByRunId,
mock.GetReposActionsRunsByOwnerByRepoByRunID,
http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) {
run := &github.WorkflowRun{
ID: github.Ptr(int64(12345)),
Expand Down Expand Up @@ -2187,7 +2184,7 @@
name: "successful workflow run",
mockedClient: mock.NewMockedHTTPClient(
mock.WithRequestMatchHandler(
mock.PostReposActionsWorkflowsDispatchesByOwnerByRepoByWorkflowId,
mock.PostReposActionsWorkflowsDispatchesByOwnerByRepoByWorkflowID,
http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) {
w.WriteHeader(http.StatusNoContent)
}),
Expand All @@ -2204,7 +2201,7 @@
},
{
name: "missing required parameter workflow_id",
mockedClient: mock.NewMockedHTTPClient(),
mockedClient: MockHTTPClientWithHandlers(map[string]http.HandlerFunc{}),
requestArgs: map[string]any{
"method": "run_workflow",
"owner": "owner",
Expand All @@ -2216,7 +2213,7 @@
},
{
name: "missing required parameter ref",
mockedClient: mock.NewMockedHTTPClient(),
mockedClient: MockHTTPClientWithHandlers(map[string]http.HandlerFunc{}),
requestArgs: map[string]any{
"method": "run_workflow",
"owner": "owner",
Expand Down Expand Up @@ -2332,7 +2329,7 @@
})

t.Run("missing run_id for non-run_workflow methods", func(t *testing.T) {
mockedClient := mock.NewMockedHTTPClient()
mockedClient := MockHTTPClientWithHandlers(map[string]http.HandlerFunc{})

client := github.NewClient(mockedClient)
deps := BaseDeps{
Expand Down Expand Up @@ -2381,7 +2378,7 @@
t.Run("successful single job logs with URL", func(t *testing.T) {
mockedClient := mock.NewMockedHTTPClient(
mock.WithRequestMatchHandler(
mock.GetReposActionsJobsLogsByOwnerByRepoByJobId,
mock.GetReposActionsJobsLogsByOwnerByRepoByJobID,
http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) {
w.Header().Set("Location", "https://github.com/logs/job/123")
w.WriteHeader(http.StatusFound)
Expand Down Expand Up @@ -2422,7 +2419,7 @@
t.Run("successful failed jobs logs", func(t *testing.T) {
mockedClient := mock.NewMockedHTTPClient(
mock.WithRequestMatchHandler(
mock.GetReposActionsRunsJobsByOwnerByRepoByRunId,
mock.GetReposActionsRunsJobsByOwnerByRepoByRunID,
http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) {
jobs := &github.Jobs{
TotalCount: github.Ptr(3),
Expand All @@ -2449,7 +2446,7 @@
}),
),
mock.WithRequestMatchHandler(
mock.GetReposActionsJobsLogsByOwnerByRepoByJobId,
mock.GetReposActionsJobsLogsByOwnerByRepoByJobID,
http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Location", "https://github.com/logs/job/"+r.URL.Path[len(r.URL.Path)-1:])
w.WriteHeader(http.StatusFound)
Expand Down Expand Up @@ -2487,7 +2484,7 @@
t.Run("no failed jobs found", func(t *testing.T) {
mockedClient := mock.NewMockedHTTPClient(
mock.WithRequestMatchHandler(
mock.GetReposActionsRunsJobsByOwnerByRepoByRunId,
mock.GetReposActionsRunsJobsByOwnerByRepoByRunID,
http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) {
jobs := &github.Jobs{
TotalCount: github.Ptr(2),
Expand Down
2 changes: 1 addition & 1 deletion pkg/github/helper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ const (
PatchReposIssuesByOwnerByRepoByIssueNumber = "PATCH /repos/{owner}/{repo}/issues/{issue_number}"
GetReposIssuesSubIssuesByOwnerByRepoByIssueNumber = "GET /repos/{owner}/{repo}/issues/{issue_number}/sub_issues"
PostReposIssuesSubIssuesByOwnerByRepoByIssueNumber = "POST /repos/{owner}/{repo}/issues/{issue_number}/sub_issues"
DeleteReposIssuesSubIssueByOwnerByRepoByIssueNumber = "DELETE /repos/{owner}/{repo}/issues/{issue_number}/sub_issues"
DeleteReposIssuesSubIssueByOwnerByRepoByIssueNumber = "DELETE /repos/{owner}/{repo}/issues/{issue_number}/sub_issue"
PatchReposIssuesSubIssuesPriorityByOwnerByRepoByIssueNumber = "PATCH /repos/{owner}/{repo}/issues/{issue_number}/sub_issues/priority"

// Pull request endpoints
Expand Down
13 changes: 8 additions & 5 deletions pkg/github/issues_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,15 @@
"github.com/github/github-mcp-server/pkg/translations"
"github.com/google/go-github/v79/github"
"github.com/google/jsonschema-go/jsonschema"
"github.com/migueleliasweb/go-github-mock/src/mock"
"github.com/shurcooL/githubv4"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)

func newMockedHTTPClient(handlers map[string]http.HandlerFunc) *http.Client {

Check failure on line 25 in pkg/github/issues_test.go

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest)

newMockedHTTPClient redeclared in this block

Check failure on line 25 in pkg/github/issues_test.go

View workflow job for this annotation

GitHub Actions / build (macos-latest)

newMockedHTTPClient redeclared in this block

Check failure on line 25 in pkg/github/issues_test.go

View workflow job for this annotation

GitHub Actions / lint

newMockedHTTPClient redeclared in this block

Check failure on line 25 in pkg/github/issues_test.go

View workflow job for this annotation

GitHub Actions / build (macos-latest)

newMockedHTTPClient redeclared in this block

Check failure on line 25 in pkg/github/issues_test.go

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest)

newMockedHTTPClient redeclared in this block
return MockHTTPClientWithHandlers(handlers)
}

var defaultGQLClient *githubv4.Client = githubv4.NewClient(newRepoAccessHTTPClient())
var repoAccessCache *lockdown.RepoAccessCache = stubRepoAccessCache(defaultGQLClient, 15*time.Minute)

Expand Down Expand Up @@ -1438,7 +1441,7 @@
),
),
),
mockedGQLClient: githubv4mock.NewMockedHTTPClient(),
mockedGQLClient: githubv4MockHTTPClientWithHandlers(map[string]http.HandlerFunc{}),
requestArgs: map[string]interface{}{
"method": "update",
"owner": "owner",
Expand All @@ -1461,7 +1464,7 @@
}),
),
),
mockedGQLClient: githubv4mock.NewMockedHTTPClient(),
mockedGQLClient: githubv4MockHTTPClientWithHandlers(map[string]http.HandlerFunc{}),
requestArgs: map[string]interface{}{
"method": "update",
"owner": "owner",
Expand Down Expand Up @@ -1748,8 +1751,8 @@
},
{
name: "duplicate_of without duplicate state_reason should fail",
mockedRESTClient: mock.NewMockedHTTPClient(),
mockedGQLClient: githubv4mock.NewMockedHTTPClient(),
mockedRESTClient: MockHTTPClientWithHandlers(map[string]http.HandlerFunc{}),
mockedGQLClient: githubv4MockHTTPClientWithHandlers(map[string]http.HandlerFunc{}),
requestArgs: map[string]interface{}{
"method": "update",
"owner": "owner",
Expand Down
Loading