-
Notifications
You must be signed in to change notification settings - Fork 2k
feat: add reviewers parameter to create_pull_request #814
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 our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -120,6 +120,12 @@ func CreatePullRequest(getClient GetClientFn, t translations.TranslationHelperFu | |||||||||||||
mcp.WithBoolean("maintainer_can_modify", | ||||||||||||||
mcp.Description("Allow maintainer edits"), | ||||||||||||||
), | ||||||||||||||
mcp.WithArray("reviewers", | ||||||||||||||
mcp.Description("GitHub usernames to request reviews from"), | ||||||||||||||
mcp.Items(map[string]interface{}{ | ||||||||||||||
"type": "string", | ||||||||||||||
}), | ||||||||||||||
), | ||||||||||||||
), | ||||||||||||||
func(ctx context.Context, request mcp.CallToolRequest) (*mcp.CallToolResult, error) { | ||||||||||||||
owner, err := RequiredParam[string](request, "owner") | ||||||||||||||
|
@@ -158,6 +164,12 @@ func CreatePullRequest(getClient GetClientFn, t translations.TranslationHelperFu | |||||||||||||
return mcp.NewToolResultError(err.Error()), nil | ||||||||||||||
} | ||||||||||||||
|
||||||||||||||
// Handle reviewers parameter | ||||||||||||||
reviewers, err := OptionalStringArrayParam(request, "reviewers") | ||||||||||||||
if err != nil { | ||||||||||||||
return mcp.NewToolResultError(err.Error()), nil | ||||||||||||||
} | ||||||||||||||
|
||||||||||||||
newPR := &github.NewPullRequest{ | ||||||||||||||
Title: github.Ptr(title), | ||||||||||||||
Head: github.Ptr(head), | ||||||||||||||
|
@@ -193,6 +205,46 @@ func CreatePullRequest(getClient GetClientFn, t translations.TranslationHelperFu | |||||||||||||
return mcp.NewToolResultError(fmt.Sprintf("failed to create pull request: %s", string(body))), nil | ||||||||||||||
} | ||||||||||||||
|
||||||||||||||
// Request reviewers if provided | ||||||||||||||
if len(reviewers) > 0 { | ||||||||||||||
reviewersRequest := github.ReviewersRequest{ | ||||||||||||||
Reviewers: reviewers, | ||||||||||||||
} | ||||||||||||||
|
||||||||||||||
_, reviewResp, err := client.PullRequests.RequestReviewers(ctx, owner, repo, *pr.Number, reviewersRequest) | ||||||||||||||
if err != nil { | ||||||||||||||
return ghErrors.NewGitHubAPIErrorResponse(ctx, | ||||||||||||||
"failed to request reviewers", | ||||||||||||||
reviewResp, | ||||||||||||||
err, | ||||||||||||||
), nil | ||||||||||||||
} | ||||||||||||||
defer func() { | ||||||||||||||
if reviewResp != nil && reviewResp.Body != nil { | ||||||||||||||
_ = reviewResp.Body.Close() | ||||||||||||||
} | ||||||||||||||
}() | ||||||||||||||
|
||||||||||||||
if reviewResp.StatusCode != http.StatusCreated && reviewResp.StatusCode != http.StatusOK { | ||||||||||||||
body, err := io.ReadAll(reviewResp.Body) | ||||||||||||||
if err != nil { | ||||||||||||||
return nil, fmt.Errorf("failed to read response body: %w", err) | ||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This return statement returns a nil *mcp.CallToolResult and an error, which is inconsistent with the function signature that expects (*mcp.CallToolResult, error). This should return an mcp.NewToolResultError instead of returning nil and an error.
Suggested change
Copilot uses AI. Check for mistakes. Positive FeedbackNegative Feedback |
||||||||||||||
} | ||||||||||||||
return mcp.NewToolResultError(fmt.Sprintf("failed to request reviewers: %s", string(body))), nil | ||||||||||||||
} | ||||||||||||||
|
||||||||||||||
// Refresh PR data to include reviewers | ||||||||||||||
pr, resp, err = client.PullRequests.Get(ctx, owner, repo, *pr.Number) | ||||||||||||||
if err != nil { | ||||||||||||||
return ghErrors.NewGitHubAPIErrorResponse(ctx, | ||||||||||||||
"failed to get updated pull request", | ||||||||||||||
resp, | ||||||||||||||
err, | ||||||||||||||
), nil | ||||||||||||||
} | ||||||||||||||
defer func() { _ = resp.Body.Close() }() | ||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The defer statement for closing resp.Body should include a nil check for resp to avoid potential panics. This should be:
Suggested change
Copilot uses AI. Check for mistakes. Positive FeedbackNegative Feedback |
||||||||||||||
} | ||||||||||||||
|
||||||||||||||
r, err := json.Marshal(pr) | ||||||||||||||
if err != nil { | ||||||||||||||
return nil, fmt.Errorf("failed to marshal response: %w", err) | ||||||||||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This return statement is inconsistent with the pattern used elsewhere in the function. It should return
mcp.NewToolResultError(err.Error()), nil
to match the error handling pattern used in lines 165, 170, 189, 205, and 233.Copilot uses AI. Check for mistakes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@copilot It seems that the other functions also use this pattern when failing to read response body