Skip to content
Closed
Show file tree
Hide file tree
Changes from all 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
123 changes: 61 additions & 62 deletions pkg/github/actions_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import (
"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"
)
Expand Down Expand Up @@ -1394,9 +1393,9 @@ func Test_RerunFailedJobs(t *testing.T) {
}{
{
name: "successful rerun of failed jobs",
mockedClient: mock.NewMockedHTTPClient(
mock.WithRequestMatchHandler(
mock.EndpointPattern{
mockedClient: NewMockedHTTPClient(
WithRequestMatchHandler(
EndpointPattern{
Pattern: "/repos/owner/repo/actions/runs/12345/rerun-failed-jobs",
Method: "POST",
},
Expand All @@ -1414,7 +1413,7 @@ func Test_RerunFailedJobs(t *testing.T) {
},
{
name: "missing required parameter run_id",
mockedClient: mock.NewMockedHTTPClient(),
mockedClient: NewMockedHTTPClient(),
requestArgs: map[string]any{
"owner": "owner",
"repo": "repo",
Expand Down Expand Up @@ -1466,9 +1465,9 @@ func Test_RerunWorkflowRun_Behavioral(t *testing.T) {
}{
{
name: "successful rerun of workflow run",
mockedClient: mock.NewMockedHTTPClient(
mock.WithRequestMatchHandler(
mock.EndpointPattern{
mockedClient: NewMockedHTTPClient(
WithRequestMatchHandler(
EndpointPattern{
Pattern: "/repos/owner/repo/actions/runs/12345/rerun",
Method: "POST",
},
Expand All @@ -1486,7 +1485,7 @@ func Test_RerunWorkflowRun_Behavioral(t *testing.T) {
},
{
name: "missing required parameter run_id",
mockedClient: mock.NewMockedHTTPClient(),
mockedClient: NewMockedHTTPClient(),
requestArgs: map[string]any{
"owner": "owner",
"repo": "repo",
Expand Down Expand Up @@ -1538,9 +1537,9 @@ func Test_ListWorkflowRuns_Behavioral(t *testing.T) {
}{
{
name: "successful workflow runs listing",
mockedClient: mock.NewMockedHTTPClient(
mock.WithRequestMatchHandler(
mock.GetReposActionsWorkflowsRunsByOwnerByRepoByWorkflowId,
mockedClient: NewMockedHTTPClient(
WithRequestMatchHandler(
GetReposActionsWorkflowsRunsByOwnerByRepoByWorkflowID,
http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) {
runs := &github.WorkflowRuns{
TotalCount: github.Ptr(2),
Expand Down Expand Up @@ -1573,7 +1572,7 @@ func Test_ListWorkflowRuns_Behavioral(t *testing.T) {
},
{
name: "missing required parameter workflow_id",
mockedClient: mock.NewMockedHTTPClient(),
mockedClient: NewMockedHTTPClient(),
requestArgs: map[string]any{
"owner": "owner",
"repo": "repo",
Expand Down Expand Up @@ -1625,9 +1624,9 @@ func Test_GetWorkflowRun_Behavioral(t *testing.T) {
}{
{
name: "successful get workflow run",
mockedClient: mock.NewMockedHTTPClient(
mock.WithRequestMatchHandler(
mock.GetReposActionsRunsByOwnerByRepoByRunId,
mockedClient: NewMockedHTTPClient(
WithRequestMatchHandler(
GetReposActionsRunsByOwnerByRepoByRunID,
http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) {
run := &github.WorkflowRun{
ID: github.Ptr(int64(12345)),
Expand All @@ -1649,7 +1648,7 @@ func Test_GetWorkflowRun_Behavioral(t *testing.T) {
},
{
name: "missing required parameter run_id",
mockedClient: mock.NewMockedHTTPClient(),
mockedClient: NewMockedHTTPClient(),
requestArgs: map[string]any{
"owner": "owner",
"repo": "repo",
Expand Down Expand Up @@ -1701,9 +1700,9 @@ func Test_GetWorkflowRunLogs_Behavioral(t *testing.T) {
}{
{
name: "successful get workflow run logs",
mockedClient: mock.NewMockedHTTPClient(
mock.WithRequestMatchHandler(
mock.GetReposActionsRunsLogsByOwnerByRepoByRunId,
mockedClient: NewMockedHTTPClient(
WithRequestMatchHandler(
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 +1718,7 @@ func Test_GetWorkflowRunLogs_Behavioral(t *testing.T) {
},
{
name: "missing required parameter run_id",
mockedClient: mock.NewMockedHTTPClient(),
mockedClient: NewMockedHTTPClient(),
requestArgs: map[string]any{
"owner": "owner",
"repo": "repo",
Expand Down Expand Up @@ -1771,9 +1770,9 @@ func Test_ListWorkflowJobs_Behavioral(t *testing.T) {
}{
{
name: "successful list workflow jobs",
mockedClient: mock.NewMockedHTTPClient(
mock.WithRequestMatchHandler(
mock.GetReposActionsRunsJobsByOwnerByRepoByRunId,
mockedClient: NewMockedHTTPClient(
WithRequestMatchHandler(
GetReposActionsRunsJobsByOwnerByRepoByRunID,
http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) {
jobs := &github.Jobs{
TotalCount: github.Ptr(2),
Expand Down Expand Up @@ -1806,7 +1805,7 @@ func Test_ListWorkflowJobs_Behavioral(t *testing.T) {
},
{
name: "missing required parameter run_id",
mockedClient: mock.NewMockedHTTPClient(),
mockedClient: NewMockedHTTPClient(),
requestArgs: map[string]any{
"owner": "owner",
"repo": "repo",
Expand Down Expand Up @@ -1873,9 +1872,9 @@ func Test_ActionsList_ListWorkflows(t *testing.T) {
}{
{
name: "successful workflow list",
mockedClient: mock.NewMockedHTTPClient(
mock.WithRequestMatchHandler(
mock.GetReposActionsWorkflowsByOwnerByRepo,
mockedClient: NewMockedHTTPClient(
WithRequestMatchHandler(
GetReposActionsWorkflowsByOwnerByRepo,
http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) {
workflows := &github.Workflows{
TotalCount: github.Ptr(2),
Expand Down Expand Up @@ -1908,7 +1907,7 @@ func Test_ActionsList_ListWorkflows(t *testing.T) {
},
{
name: "missing required parameter method",
mockedClient: mock.NewMockedHTTPClient(),
mockedClient: NewMockedHTTPClient(),
requestArgs: map[string]any{
"owner": "owner",
"repo": "repo",
Expand Down Expand Up @@ -1952,9 +1951,9 @@ func Test_ActionsList_ListWorkflowRuns(t *testing.T) {
toolDef := ActionsList(translations.NullTranslationHelper)

t.Run("successful workflow runs list", func(t *testing.T) {
mockedClient := mock.NewMockedHTTPClient(
mock.WithRequestMatchHandler(
mock.GetReposActionsWorkflowsRunsByOwnerByRepoByWorkflowId,
mockedClient := NewMockedHTTPClient(
WithRequestMatchHandler(
GetReposActionsWorkflowsRunsByOwnerByRepoByWorkflowID,
http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) {
runs := &github.WorkflowRuns{
TotalCount: github.Ptr(1),
Expand Down Expand Up @@ -1998,7 +1997,7 @@ func Test_ActionsList_ListWorkflowRuns(t *testing.T) {
})

t.Run("missing resource_id for list_workflow_runs", func(t *testing.T) {
mockedClient := mock.NewMockedHTTPClient()
mockedClient := NewMockedHTTPClient()

client := github.NewClient(mockedClient)
deps := BaseDeps{
Expand Down Expand Up @@ -2040,9 +2039,9 @@ func Test_ActionsGet_GetWorkflow(t *testing.T) {
toolDef := ActionsGet(translations.NullTranslationHelper)

t.Run("successful workflow get", func(t *testing.T) {
mockedClient := mock.NewMockedHTTPClient(
mock.WithRequestMatchHandler(
mock.GetReposActionsWorkflowsByOwnerByRepoByWorkflowId,
mockedClient := NewMockedHTTPClient(
WithRequestMatchHandler(
GetReposActionsWorkflowsByOwnerByRepoByWorkflowID,
http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) {
workflow := &github.Workflow{
ID: github.Ptr(int64(1)),
Expand Down Expand Up @@ -2086,9 +2085,9 @@ func Test_ActionsGet_GetWorkflowRun(t *testing.T) {
toolDef := ActionsGet(translations.NullTranslationHelper)

t.Run("successful workflow run get", func(t *testing.T) {
mockedClient := mock.NewMockedHTTPClient(
mock.WithRequestMatchHandler(
mock.GetReposActionsRunsByOwnerByRepoByRunId,
mockedClient := NewMockedHTTPClient(
WithRequestMatchHandler(
GetReposActionsRunsByOwnerByRepoByRunID,
http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) {
run := &github.WorkflowRun{
ID: github.Ptr(int64(12345)),
Expand Down Expand Up @@ -2157,9 +2156,9 @@ func Test_ActionsRunTrigger_RunWorkflow(t *testing.T) {
}{
{
name: "successful workflow run",
mockedClient: mock.NewMockedHTTPClient(
mock.WithRequestMatchHandler(
mock.PostReposActionsWorkflowsDispatchesByOwnerByRepoByWorkflowId,
mockedClient: NewMockedHTTPClient(
WithRequestMatchHandler(
PostReposActionsWorkflowsDispatchesByOwnerByRepoByWorkflowID,
http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) {
w.WriteHeader(http.StatusNoContent)
}),
Expand All @@ -2176,7 +2175,7 @@ func Test_ActionsRunTrigger_RunWorkflow(t *testing.T) {
},
{
name: "missing required parameter workflow_id",
mockedClient: mock.NewMockedHTTPClient(),
mockedClient: NewMockedHTTPClient(),
requestArgs: map[string]any{
"method": "run_workflow",
"owner": "owner",
Expand All @@ -2188,7 +2187,7 @@ func Test_ActionsRunTrigger_RunWorkflow(t *testing.T) {
},
{
name: "missing required parameter ref",
mockedClient: mock.NewMockedHTTPClient(),
mockedClient: NewMockedHTTPClient(),
requestArgs: map[string]any{
"method": "run_workflow",
"owner": "owner",
Expand Down Expand Up @@ -2233,9 +2232,9 @@ func Test_ActionsRunTrigger_CancelWorkflowRun(t *testing.T) {
toolDef := ActionsRunTrigger(translations.NullTranslationHelper)

t.Run("successful workflow run cancellation", func(t *testing.T) {
mockedClient := mock.NewMockedHTTPClient(
mock.WithRequestMatchHandler(
mock.EndpointPattern{
mockedClient := NewMockedHTTPClient(
WithRequestMatchHandler(
EndpointPattern{
Pattern: "/repos/owner/repo/actions/runs/12345/cancel",
Method: "POST",
},
Expand Down Expand Up @@ -2270,9 +2269,9 @@ func Test_ActionsRunTrigger_CancelWorkflowRun(t *testing.T) {
})

t.Run("conflict when cancelling a workflow run", func(t *testing.T) {
mockedClient := mock.NewMockedHTTPClient(
mock.WithRequestMatchHandler(
mock.EndpointPattern{
mockedClient := NewMockedHTTPClient(
WithRequestMatchHandler(
EndpointPattern{
Pattern: "/repos/owner/repo/actions/runs/12345/cancel",
Method: "POST",
},
Expand Down Expand Up @@ -2304,7 +2303,7 @@ func Test_ActionsRunTrigger_CancelWorkflowRun(t *testing.T) {
})

t.Run("missing run_id for non-run_workflow methods", func(t *testing.T) {
mockedClient := mock.NewMockedHTTPClient()
mockedClient := NewMockedHTTPClient()

client := github.NewClient(mockedClient)
deps := BaseDeps{
Expand Down Expand Up @@ -2351,9 +2350,9 @@ func Test_ActionsGetJobLogs_SingleJob(t *testing.T) {
toolDef := ActionsGetJobLogs(translations.NullTranslationHelper)

t.Run("successful single job logs with URL", func(t *testing.T) {
mockedClient := mock.NewMockedHTTPClient(
mock.WithRequestMatchHandler(
mock.GetReposActionsJobsLogsByOwnerByRepoByJobId,
mockedClient := NewMockedHTTPClient(
WithRequestMatchHandler(
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 @@ -2392,9 +2391,9 @@ func Test_ActionsGetJobLogs_FailedJobs(t *testing.T) {
toolDef := ActionsGetJobLogs(translations.NullTranslationHelper)

t.Run("successful failed jobs logs", func(t *testing.T) {
mockedClient := mock.NewMockedHTTPClient(
mock.WithRequestMatchHandler(
mock.GetReposActionsRunsJobsByOwnerByRepoByRunId,
mockedClient := NewMockedHTTPClient(
WithRequestMatchHandler(
GetReposActionsRunsJobsByOwnerByRepoByRunID,
http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) {
jobs := &github.Jobs{
TotalCount: github.Ptr(3),
Expand All @@ -2420,8 +2419,8 @@ func Test_ActionsGetJobLogs_FailedJobs(t *testing.T) {
_ = json.NewEncoder(w).Encode(jobs)
}),
),
mock.WithRequestMatchHandler(
mock.GetReposActionsJobsLogsByOwnerByRepoByJobId,
WithRequestMatchHandler(
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 @@ -2457,9 +2456,9 @@ func Test_ActionsGetJobLogs_FailedJobs(t *testing.T) {
})

t.Run("no failed jobs found", func(t *testing.T) {
mockedClient := mock.NewMockedHTTPClient(
mock.WithRequestMatchHandler(
mock.GetReposActionsRunsJobsByOwnerByRepoByRunId,
mockedClient := NewMockedHTTPClient(
WithRequestMatchHandler(
GetReposActionsRunsJobsByOwnerByRepoByRunID,
http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) {
jobs := &github.Jobs{
TotalCount: github.Ptr(2),
Expand Down
Loading