- Notifications
You must be signed in to change notification settings - Fork937
feat: add reviewers parameter to UpdatePullRequest#285
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
Open
MayorFaj wants to merge9 commits intogithub:mainChoose a base branch fromMayorFaj:feat/259/assign-reviewers
base:main
Could not load branches
Branch not found:{{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline, and old review comments may become outdated.
Uh oh!
There was an error while loading.Please reload this page.
Open
Changes fromall commits
Commits
Show all changes
9 commits Select commitHold shift + click to select a range
3234755
feat: add reviewers parameter to UpdatePullRequest and update tests
MayorFaj9db748b
Merge branch 'main' into feat/259/assign-reviewers
MayorFaja84ede9
Merge branch 'main' into feat/259/assign-reviewers
MayorFaj276ac8d
Merge branch 'main' into feat/259/assign-reviewers
MayorFaj53d0833
Merge branch 'main' into feat/259/assign-reviewers
MayorFajc4de80b
Merge branch 'main' into feat/259/assign-reviewers
MayorFaj0e51a09
Merge branch 'main' into feat/259/assign-reviewers
MayorFajb9d2e28
Merge branch 'main' into feat/259/assign-reviewers
MayorFaj9ac7250
Merge branch 'main' into feat/259/assign-reviewers
MayorFajFile 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
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 |
---|---|---|
@@ -111,6 +111,12 @@ func UpdatePullRequest(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") | ||
@@ -165,26 +171,101 @@ func UpdatePullRequest(getClient GetClientFn, t translations.TranslationHelperFu | ||
updateNeeded = true | ||
} | ||
// Handle reviewers separately | ||
var reviewers []string | ||
if reviewersArr, ok := request.Params.Arguments["reviewers"].([]interface{}); ok && len(reviewersArr) > 0 { | ||
for _, reviewer := range reviewersArr { | ||
if reviewerStr, ok := reviewer.(string); ok { | ||
reviewers = append(reviewers, reviewerStr) | ||
} | ||
} | ||
} | ||
// Create the GitHub client | ||
client, err := getClient(ctx) | ||
if err != nil { | ||
return nil, fmt.Errorf("failed to get GitHub client: %w", err) | ||
} | ||
var pr *github.PullRequest | ||
var resp *http.Response | ||
// First, update the PR if needed | ||
if updateNeeded { | ||
var ghResp *github.Response | ||
pr, ghResp, err = client.PullRequests.Edit(ctx, owner, repo, pullNumber, update) | ||
if err != nil { | ||
return nil, fmt.Errorf("failed to update pull request: %w", err) | ||
} | ||
resp = ghResp.Response | ||
defer func() { | ||
if resp != nil && resp.Body != nil { | ||
_ = resp.Body.Close() | ||
} | ||
}() | ||
if resp.StatusCode != http.StatusOK { | ||
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 update pull request: %s", string(body))), nil | ||
} | ||
} else { | ||
// If no update needed, just get the current PR | ||
var ghResp *github.Response | ||
pr, ghResp, err = client.PullRequests.Get(ctx, owner, repo, pullNumber) | ||
if err != nil { | ||
return nil, fmt.Errorf("failed to get pull request: %w", err) | ||
} | ||
resp = ghResp.Response | ||
defer func() { | ||
if resp != nil && resp.Body != nil { | ||
_ = resp.Body.Close() | ||
} | ||
}() | ||
if resp.StatusCode != http.StatusOK { | ||
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 get pull request: %s", string(body))), nil | ||
} | ||
MayorFaj marked this conversation as resolved. Show resolvedHide resolvedUh oh!There was an error while loading.Please reload this page. | ||
} | ||
// Add reviewers if specified | ||
if len(reviewers) > 0 { | ||
reviewersRequest := github.ReviewersRequest{ | ||
Reviewers: reviewers, | ||
} | ||
// Use the direct result of RequestReviewers which includes the requested reviewers | ||
updatedPR, resp, err := client.PullRequests.RequestReviewers(ctx, owner, repo, pullNumber, reviewersRequest) | ||
if err != nil { | ||
return nil, fmt.Errorf("failed torequest reviewers: %w", err) | ||
} | ||
defer func() { | ||
if resp != nil && resp.Body != nil { | ||
_ = resp.Body.Close() | ||
} | ||
}() | ||
if resp.StatusCode != http.StatusCreated && resp.StatusCode != http.StatusOK { | ||
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 reviewers: %s", string(body))), nil | ||
} | ||
// Use the updated PR with reviewers | ||
pr = updatedPR | ||
} | ||
// If no updates and no reviewers, return error | ||
if !updateNeeded && len(reviewers) == 0 { | ||
return mcp.NewToolResultError("No update parameters provided"), nil | ||
} | ||
r, err := json.Marshal(pr) | ||
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.