- Notifications
You must be signed in to change notification settings - Fork3.1k
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
Uh oh!
There was an error while loading.Please reload this page.
Changes fromall commits
32347559db748ba84ede9276ac8d53d0833c4de80b0e51a09b9d2e289ac725071dcedf5c85a09b09f58953e27087676eae9209f5c6f21c3f8a6cabf4e28ee7432907e047436520bfead5650e1d0674183046f99490eb11a033f61394cef70d89e5225ea322bbe359ea1934e2ac1b9a46File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -241,6 +241,12 @@ func UpdatePullRequest(getClient GetClientFn, getGQLClient GetGQLClientFn, t tra | ||
| 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") | ||
| @@ -256,15 +262,17 @@ func UpdatePullRequest(getClient GetClientFn, getGQLClient GetGQLClientFn, t tra | ||
| return mcp.NewToolResultError(err.Error()), nil | ||
| } | ||
| // Check if draft parameter is provided | ||
| draftProvided := request.GetArguments()["draft"] != nil | ||
| var draftValue bool | ||
| if draftProvided { | ||
| draftValue, err = OptionalParam[bool](request, "draft") | ||
| if err != nil { | ||
| returnmcp.NewToolResultError(err.Error()), nil | ||
| } | ||
| } | ||
| // Build the update struct only with provided fields | ||
| update := &github.PullRequest{} | ||
| restUpdateNeeded := false | ||
| @@ -303,10 +311,18 @@ func UpdatePullRequest(getClient GetClientFn, getGQLClient GetGQLClientFn, t tra | ||
| restUpdateNeeded = true | ||
| } | ||
| // Handle reviewers separately | ||
| reviewers, err := OptionalStringArrayParam(request, "reviewers") | ||
| if err != nil { | ||
| return mcp.NewToolResultError(err.Error()), nil | ||
| } | ||
| // If no updates, no draft change, and no reviewers, return error early | ||
| if !restUpdateNeeded && !draftProvided && len(reviewers) == 0 { | ||
Contributor 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. We could simplify it to | ||
| return mcp.NewToolResultError("No update parameters provided."), nil | ||
| } | ||
| // Handle REST API updates (title, body, state, base, maintainer_can_modify) | ||
| if restUpdateNeeded { | ||
| client, err := getClient(ctx) | ||
| if err != nil { | ||
| @@ -332,6 +348,7 @@ func UpdatePullRequest(getClient GetClientFn, getGQLClient GetGQLClientFn, t tra | ||
| } | ||
| } | ||
| // Handle draft status changes using GraphQL | ||
| if draftProvided { | ||
| gqlClient, err := getGQLClient(ctx) | ||
| if err != nil { | ||
| @@ -397,6 +414,41 @@ func UpdatePullRequest(getClient GetClientFn, getGQLClient GetGQLClientFn, t tra | ||
| } | ||
| } | ||
| // Handle reviewer requests | ||
| if len(reviewers) > 0 { | ||
| client, err := getClient(ctx) | ||
| if err != nil { | ||
| return nil, fmt.Errorf("failed to get GitHub client: %w", err) | ||
| } | ||
| reviewersRequest := github.ReviewersRequest{ | ||
| Reviewers: reviewers, | ||
| } | ||
| _, resp, err := client.PullRequests.RequestReviewers(ctx, owner, repo, pullNumber, reviewersRequest) | ||
| if err != nil { | ||
| return ghErrors.NewGitHubAPIErrorResponse(ctx, | ||
| "failed to request reviewers", | ||
| resp, | ||
| err, | ||
| ), nil | ||
| } | ||
| 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 | ||
| } | ||
| } | ||
| // Get the final state of the PR to return | ||
| client, err := getClient(ctx) | ||
| if err != nil { | ||
| return nil, err | ||
Uh oh!
There was an error while loading.Please reload this page.