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

Commit650aac6

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 parent71b0916 commit650aac6

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
@@ -1607,13 +1607,13 @@ func newGQLIntPtr(i *int32) *githubv4.Int {
16071607
return&gi
16081608
}
16091609

1610-
//MarkPullRequestReadyForReview creates a tool tomark a draftpull requestas ready forreview.
1611-
// This uses the GraphQL API because the REST API does not support changingaPRfromdraftto ready-for-review.
1612-
funcMarkPullRequestReadyForReview(getGQLClientGetGQLClientFn,t translations.TranslationHelperFunc) (mcp.Tool, server.ToolHandlerFunc) {
1613-
returnmcp.NewTool("mark_pr_ready_for_review",
1614-
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.")),
1610+
//SetPRStatus creates a tool tosetpull requeststatus between draft and ready-for-review states.
1611+
// This uses the GraphQL API because the REST API does not support changing PR draftstatus.
1612+
funcSetPRStatus(getGQLClientGetGQLClientFn,t translations.TranslationHelperFunc) (mcp.Tool, server.ToolHandlerFunc) {
1613+
returnmcp.NewTool("set_pr_status",
1614+
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.")),
16151615
mcp.WithToolAnnotation(mcp.ToolAnnotation{
1616-
Title:t("TOOL_MARK_PR_READY_FOR_REVIEW_USER_TITLE","Mark pull requestready for review"),
1616+
Title:t("TOOL_SET_PR_STATUS_USER_TITLE","Set pull requeststatus"),
16171617
ReadOnlyHint:toBoolPtr(false),
16181618
}),
16191619
mcp.WithString("owner",
@@ -1628,24 +1628,35 @@ func MarkPullRequestReadyForReview(getGQLClient GetGQLClientFn, t translations.T
16281628
mcp.Required(),
16291629
mcp.Description("Pull request number"),
16301630
),
1631+
mcp.WithString("status",
1632+
mcp.Required(),
1633+
mcp.Description("Target status for the pull request"),
1634+
mcp.Enum("draft","ready_for_review"),
1635+
),
16311636
),
16321637
func(ctx context.Context,request mcp.CallToolRequest) (*mcp.CallToolResult,error) {
16331638
varparamsstruct {
16341639
Ownerstring
16351640
Repostring
16361641
PullNumberint32
1642+
Statusstring
16371643
}
16381644
iferr:=mapstructure.Decode(request.Params.Arguments,&params);err!=nil {
16391645
returnmcp.NewToolResultError(err.Error()),nil
16401646
}
16411647

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

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

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

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

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

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

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

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp