- Notifications
You must be signed in to change notification settings - Fork943
Add ability to request Copilot reviews via MCP#387
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Merged
Uh oh!
There was an error while loading.Please reload this page.
Merged
Changes fromall commits
Commits
Show all changes
5 commits Select commitHold shift + click to select a range
25200cc
Add request_copilot_review tool with placeholder implementation
aryasoni98476fc57
Support requesting copilot as a reviewer
williammartina06ca21
Update README.md
williammartin6fcf81e
Update pkg/github/pullrequests.go
williammartinf85af64
Update pkg/github/tools.go
williammartinFile filter
Filter by extension
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -458,6 +458,13 @@ export GITHUB_MCP_TOOL_ADD_ISSUE_COMMENT_DESCRIPTION="an alternative description | ||
- `base`: New base branch name (string, optional) | ||
- `maintainer_can_modify`: Allow maintainer edits (boolean, optional) | ||
- **request_copilot_review** - Request a GitHub Copilot review for a pull request (experimental; subject to GitHub API support) | ||
- `owner`: Repository owner (string, required) | ||
- `repo`: Repository name (string, required) | ||
- `pullNumber`: Pull request number (number, required) | ||
SamMorrowDrums marked this conversation as resolved. Show resolvedHide resolvedUh oh!There was an error while loading.Please reload this page. | ||
- _Note_: Currently, this tool will only work for github.com | ||
### Repositories | ||
- **create_or_update_file** - Create or update a single file in a repository | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1246,3 +1246,75 @@ func CreatePullRequest(getClient GetClientFn, t translations.TranslationHelperFu | ||
return mcp.NewToolResultText(string(r)), nil | ||
} | ||
} | ||
// RequestCopilotReview creates a tool to request a Copilot review for a pull request. | ||
// Note that this tool will not work on GHES where this feature is unsupported. In future, we should not expose this | ||
// tool if the configured host does not support it. | ||
func RequestCopilotReview(getClient GetClientFn, t translations.TranslationHelperFunc) (mcp.Tool, server.ToolHandlerFunc) { | ||
return mcp.NewTool("request_copilot_review", | ||
mcp.WithDescription(t("TOOL_REQUEST_COPILOT_REVIEW_DESCRIPTION", "Request a GitHub Copilot code review for a pull request. Use this for automated feedback on pull requests, usually before requesting a human reviewer.")), | ||
mcp.WithToolAnnotation(mcp.ToolAnnotation{ | ||
Title: t("TOOL_REQUEST_COPILOT_REVIEW_USER_TITLE", "Request Copilot review"), | ||
ReadOnlyHint: toBoolPtr(false), | ||
}), | ||
mcp.WithString("owner", | ||
mcp.Required(), | ||
mcp.Description("Repository owner"), | ||
), | ||
mcp.WithString("repo", | ||
mcp.Required(), | ||
mcp.Description("Repository name"), | ||
), | ||
mcp.WithNumber("pullNumber", | ||
SamMorrowDrums marked this conversation as resolved. Show resolvedHide resolvedUh oh!There was an error while loading.Please reload this page. | ||
mcp.Required(), | ||
mcp.Description("Pull request number"), | ||
), | ||
), | ||
func(ctx context.Context, request mcp.CallToolRequest) (*mcp.CallToolResult, error) { | ||
owner, err := requiredParam[string](request, "owner") | ||
if err != nil { | ||
return mcp.NewToolResultError(err.Error()), nil | ||
} | ||
repo, err := requiredParam[string](request, "repo") | ||
if err != nil { | ||
return mcp.NewToolResultError(err.Error()), nil | ||
} | ||
pullNumber, err := RequiredInt(request, "pullNumber") | ||
if err != nil { | ||
return mcp.NewToolResultError(err.Error()), nil | ||
} | ||
client, err := getClient(ctx) | ||
if err != nil { | ||
return mcp.NewToolResultError(err.Error()), nil | ||
} | ||
_, resp, err := client.PullRequests.RequestReviewers( | ||
ctx, | ||
owner, | ||
repo, | ||
pullNumber, | ||
github.ReviewersRequest{ | ||
// The login name of the copilot reviewer bot | ||
Reviewers: []string{"copilot-pull-request-reviewer[bot]"}, | ||
}, | ||
) | ||
if err != nil { | ||
return nil, fmt.Errorf("failed to request copilot review: %w", err) | ||
} | ||
defer func() { _ = resp.Body.Close() }() | ||
if resp.StatusCode != http.StatusCreated { | ||
williammartin marked this conversation as resolved. Show resolvedHide resolvedUh oh!There was an error while loading.Please reload this page. | ||
body, err := io.ReadAll(resp.Body) | ||
if err != nil { | ||
return nil, fmt.Errorf("failed to read response body: %w", err) | ||
} | ||
return mcp.NewToolResultError(fmt.Sprintf("failed to request copilot review: %s", string(body))), nil | ||
} | ||
// Return nothing on success, as there's not much value in returning the Pull Request itself | ||
return mcp.NewToolResultText(""), nil | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1916,3 +1916,112 @@ func Test_AddPullRequestReviewComment(t *testing.T) { | ||
}) | ||
} | ||
} | ||
func Test_RequestCopilotReview(t *testing.T) { | ||
t.Parallel() | ||
mockClient := github.NewClient(nil) | ||
tool, _ := RequestCopilotReview(stubGetClientFn(mockClient), translations.NullTranslationHelper) | ||
assert.Equal(t, "request_copilot_review", tool.Name) | ||
assert.NotEmpty(t, tool.Description) | ||
assert.Contains(t, tool.InputSchema.Properties, "owner") | ||
assert.Contains(t, tool.InputSchema.Properties, "repo") | ||
assert.Contains(t, tool.InputSchema.Properties, "pullNumber") | ||
assert.ElementsMatch(t, tool.InputSchema.Required, []string{"owner", "repo", "pullNumber"}) | ||
SamMorrowDrums marked this conversation as resolved. Show resolvedHide resolvedUh oh!There was an error while loading.Please reload this page. | ||
// Setup mock PR for success case | ||
mockPR := &github.PullRequest{ | ||
Number: github.Ptr(42), | ||
Title: github.Ptr("Test PR"), | ||
State: github.Ptr("open"), | ||
HTMLURL: github.Ptr("https://github.com/owner/repo/pull/42"), | ||
Head: &github.PullRequestBranch{ | ||
SHA: github.Ptr("abcd1234"), | ||
Ref: github.Ptr("feature-branch"), | ||
}, | ||
Base: &github.PullRequestBranch{ | ||
Ref: github.Ptr("main"), | ||
}, | ||
Body: github.Ptr("This is a test PR"), | ||
User: &github.User{ | ||
Login: github.Ptr("testuser"), | ||
}, | ||
} | ||
tests := []struct { | ||
name string | ||
mockedClient *http.Client | ||
requestArgs map[string]any | ||
expectError bool | ||
expectedErrMsg string | ||
}{ | ||
{ | ||
name: "successful request", | ||
mockedClient: mock.NewMockedHTTPClient( | ||
mock.WithRequestMatchHandler( | ||
mock.PostReposPullsRequestedReviewersByOwnerByRepoByPullNumber, | ||
expect(t, expectations{ | ||
path: "/repos/owner/repo/pulls/1/requested_reviewers", | ||
requestBody: map[string]any{ | ||
"reviewers": []any{"copilot-pull-request-reviewer[bot]"}, | ||
}, | ||
}).andThen( | ||
mockResponse(t, http.StatusCreated, mockPR), | ||
), | ||
), | ||
), | ||
requestArgs: map[string]any{ | ||
"owner": "owner", | ||
"repo": "repo", | ||
"pullNumber": float64(1), | ||
}, | ||
expectError: false, | ||
}, | ||
{ | ||
name: "request fails", | ||
mockedClient: mock.NewMockedHTTPClient( | ||
mock.WithRequestMatchHandler( | ||
mock.PostReposPullsRequestedReviewersByOwnerByRepoByPullNumber, | ||
http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) { | ||
w.WriteHeader(http.StatusNotFound) | ||
_, _ = w.Write([]byte(`{"message": "Not Found"}`)) | ||
}), | ||
), | ||
), | ||
requestArgs: map[string]any{ | ||
"owner": "owner", | ||
"repo": "repo", | ||
"pullNumber": float64(999), | ||
}, | ||
expectError: true, | ||
expectedErrMsg: "failed to request copilot review", | ||
}, | ||
} | ||
for _, tc := range tests { | ||
t.Run(tc.name, func(t *testing.T) { | ||
t.Parallel() | ||
client := github.NewClient(tc.mockedClient) | ||
_, handler := RequestCopilotReview(stubGetClientFn(client), translations.NullTranslationHelper) | ||
request := createMCPRequest(tc.requestArgs) | ||
result, err := handler(context.Background(), request) | ||
if tc.expectError { | ||
require.Error(t, err) | ||
assert.Contains(t, err.Error(), tc.expectedErrMsg) | ||
return | ||
} | ||
require.NoError(t, err) | ||
assert.NotNil(t, result) | ||
assert.Len(t, result.Content, 1) | ||
textContent := getTextResult(t, result) | ||
require.Equal(t, "", textContent.Text) | ||
}) | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.