Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitfcbc256

Browse files
committed
feat: convert mark_pr_ready_for_review to set_pr_status tool
- Replace mark_pr_ready_for_review with set_pr_status tool- Add bidirectional PR status changes (draft ↔ ready_for_review)- Use enum parameter for status: "draft", "ready_for_review"- Implement GraphQL mutations for both directions- Add comprehensive test suite with 8 test scenarios- Remove deprecated MarkPullRequestReadyForReview functionAddresses user feedback to provide enum-based PR status managementwith support for setting PRs to both draft and ready-for-review states.
1 parentc9cda90 commitfcbc256

File tree

3 files changed

+250
-49
lines changed

3 files changed

+250
-49
lines changed

‎pkg/github/pullrequests.go

Lines changed: 65 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1608,13 +1608,13 @@ func newGQLIntPtr(i *int32) *githubv4.Int {
16081608
return&gi
16091609
}
16101610

1611-
//MarkPullRequestReadyForReview creates a tool tomark a draftpull requestas ready forreview.
1612-
// This uses the GraphQL API because the REST API does not support changingaPRfromdraftto ready-for-review.
1613-
funcMarkPullRequestReadyForReview(getGQLClientGetGQLClientFn,t translations.TranslationHelperFunc) (mcp.Tool, server.ToolHandlerFunc) {
1614-
returnmcp.NewTool("mark_pr_ready_for_review",
1615-
mcp.WithDescription(t("TOOL_MARK_PR_READY_FOR_REVIEW_DESCRIPTION","Mark a draftpull requestas ready forreview. Use this to change a pull request from draftstateto readyforreview.")),
1611+
//SetPRStatus creates a tool tosetpull requeststatus between draft and ready-for-review states.
1612+
// This uses the GraphQL API because the REST API does not support changing PR draftstatus.
1613+
funcSetPRStatus(getGQLClientGetGQLClientFn,t translations.TranslationHelperFunc) (mcp.Tool, server.ToolHandlerFunc) {
1614+
returnmcp.NewTool("set_pr_status",
1615+
mcp.WithDescription(t("TOOL_SET_PR_STATUS_DESCRIPTION","Setpull requeststatus between draft and ready-for-review states. Use this to change a pull request from draft to ready-for-review or vice versa.")),
16161616
mcp.WithToolAnnotation(mcp.ToolAnnotation{
1617-
Title:t("TOOL_MARK_PR_READY_FOR_REVIEW_USER_TITLE","Mark pull requestready for review"),
1617+
Title:t("TOOL_SET_PR_STATUS_USER_TITLE","Set pull requeststatus"),
16181618
ReadOnlyHint:toBoolPtr(false),
16191619
}),
16201620
mcp.WithString("owner",
@@ -1629,24 +1629,35 @@ func MarkPullRequestReadyForReview(getGQLClient GetGQLClientFn, t translations.T
16291629
mcp.Required(),
16301630
mcp.Description("Pull request number"),
16311631
),
1632+
mcp.WithString("status",
1633+
mcp.Required(),
1634+
mcp.Description("Target status for the pull request"),
1635+
mcp.Enum("draft","ready_for_review"),
1636+
),
16321637
),
16331638
func(ctx context.Context,request mcp.CallToolRequest) (*mcp.CallToolResult,error) {
16341639
varparamsstruct {
16351640
Ownerstring
16361641
Repostring
16371642
PullNumberint32
1643+
Statusstring
16381644
}
16391645
iferr:=mapstructure.Decode(request.Params.Arguments,&params);err!=nil {
16401646
returnmcp.NewToolResultError(err.Error()),nil
16411647
}
16421648

1649+
// Validate status parameter
1650+
ifparams.Status!="draft"&&params.Status!="ready_for_review" {
1651+
returnmcp.NewToolResultError("status must be either 'draft' or 'ready_for_review'"),nil
1652+
}
1653+
16431654
// Get the GraphQL client
16441655
client,err:=getGQLClient(ctx)
16451656
iferr!=nil {
16461657
returnmcp.NewToolResultError(fmt.Sprintf("failed to get GitHub GraphQL client: %v",err)),nil
16471658
}
16481659

1649-
// First, we need to get the GraphQL ID of the pull request
1660+
// First, we need to get the GraphQL ID of the pull request and its current status
16501661
vargetPullRequestQuerystruct {
16511662
Repositorystruct {
16521663
PullRequeststruct {
@@ -1666,28 +1677,57 @@ func MarkPullRequestReadyForReview(getGQLClient GetGQLClientFn, t translations.T
16661677
returnmcp.NewToolResultError(fmt.Sprintf("failed to get pull request: %v",err)),nil
16671678
}
16681679

1669-
// Check if the PR is already in non-draft state
1670-
if!getPullRequestQuery.Repository.PullRequest.IsDraft {
1671-
returnmcp.NewToolResultText("Pull request is already marked as ready for review"),nil
1672-
}
1680+
currentIsDraft:=bool(getPullRequestQuery.Repository.PullRequest.IsDraft)
1681+
targetIsDraft:=params.Status=="draft"
16731682

1674-
//Now we can markthe PRas ready for review usingtheGraphQL mutation
1675-
varmarkReadyForReviewMutationstruct {
1676-
MarkPullRequestReadyForReviewstruct {
1677-
PullRequeststruct {
1678-
ID githubv4.ID// Required by GraphQL schema, but not used in response
1679-
}
1680-
}`graphql:"markPullRequestReadyForReview(input: $input)"`
1683+
//Check ifthe PRis already inthetarget state
1684+
ifcurrentIsDraft==targetIsDraft {
1685+
iftargetIsDraft {
1686+
returnmcp.NewToolResultText("Pull request is already in draft state"),nil
1687+
}else {
1688+
returnmcp.NewToolResultText("Pull request is already marked as ready for review"),nil
1689+
}
16811690
}
16821691

1683-
input:= githubv4.MarkPullRequestReadyForReviewInput{
1684-
PullRequestID:getPullRequestQuery.Repository.PullRequest.ID,
1685-
}
1692+
// Perform the appropriate mutation based on target status
1693+
iftargetIsDraft {
1694+
// Convert to draft
1695+
varconvertToDraftMutationstruct {
1696+
ConvertPullRequestToDraftstruct {
1697+
PullRequeststruct {
1698+
ID githubv4.ID// Required by GraphQL schema, but not used in response
1699+
}
1700+
}`graphql:"convertPullRequestToDraft(input: $input)"`
1701+
}
16861702

1687-
iferr:=client.Mutate(ctx,&markReadyForReviewMutation,input,nil);err!=nil {
1688-
returnmcp.NewToolResultError(fmt.Sprintf("failed to mark pull request as ready for review: %v",err)),nil
1689-
}
1703+
input:= githubv4.ConvertPullRequestToDraftInput{
1704+
PullRequestID:getPullRequestQuery.Repository.PullRequest.ID,
1705+
}
1706+
1707+
iferr:=client.Mutate(ctx,&convertToDraftMutation,input,nil);err!=nil {
1708+
returnmcp.NewToolResultError(fmt.Sprintf("failed to convert pull request to draft: %v",err)),nil
1709+
}
16901710

1691-
returnmcp.NewToolResultText("Pull request successfully marked as ready for review"),nil
1711+
returnmcp.NewToolResultText("Pull request successfully converted to draft"),nil
1712+
}else {
1713+
// Mark as ready for review
1714+
varmarkReadyForReviewMutationstruct {
1715+
MarkPullRequestReadyForReviewstruct {
1716+
PullRequeststruct {
1717+
ID githubv4.ID// Required by GraphQL schema, but not used in response
1718+
}
1719+
}`graphql:"markPullRequestReadyForReview(input: $input)"`
1720+
}
1721+
1722+
input:= githubv4.MarkPullRequestReadyForReviewInput{
1723+
PullRequestID:getPullRequestQuery.Repository.PullRequest.ID,
1724+
}
1725+
1726+
iferr:=client.Mutate(ctx,&markReadyForReviewMutation,input,nil);err!=nil {
1727+
returnmcp.NewToolResultError(fmt.Sprintf("failed to mark pull request as ready for review: %v",err)),nil
1728+
}
1729+
1730+
returnmcp.NewToolResultText("Pull request successfully marked as ready for review"),nil
1731+
}
16921732
}
16931733
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp