Slice 10: create_pr (open a pull request)
forge CreatePullRequest (Gitea; empty base resolves to the repo default branch). Service CreatePR records a pr-created event. HTTP POST /api/repo/pr/create; MCP tool create_pr; <pr-list> New pull request button (head = selected repo current branch, base = default). Live-tested end-to-end: app create_pr opened a real PR (base auto-resolved), listed, then cleaned up; main untouched. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@@ -81,6 +81,15 @@ type mergePRInput struct {
|
||||
Number int64 `json:"number" jsonschema:"the pull request number to merge and clean up"`
|
||||
}
|
||||
|
||||
// createPRInput describes a pull request to open.
|
||||
type createPRInput struct {
|
||||
Path string `json:"path" jsonschema:"absolute path of the repository, from list_repos"`
|
||||
Head string `json:"head" jsonschema:"the branch to merge from (must already exist on the remote)"`
|
||||
Base string `json:"base" jsonschema:"the branch to merge into; leave empty for the repo's default branch"`
|
||||
Title string `json:"title" jsonschema:"the pull request title"`
|
||||
Body string `json:"body" jsonschema:"the pull request description (optional)"`
|
||||
}
|
||||
|
||||
// gitCommitInput is the argument schema for git_commit.
|
||||
type gitCommitInput struct {
|
||||
Path string `json:"path" jsonschema:"absolute path of the repository, from list_repos"`
|
||||
@@ -196,6 +205,18 @@ func NewServer(svc *service.Service, version string) *mcpsdk.Server {
|
||||
return nil, prListOutput{PRs: prs}, nil
|
||||
})
|
||||
|
||||
// create_pr — open a pull request from a branch.
|
||||
mcpsdk.AddTool(s, &mcpsdk.Tool{
|
||||
Name: "create_pr",
|
||||
Description: "Open a pull request from head into base (leave base empty for the repo's default branch). The head branch must already exist on the remote — push it first. Path is from list_repos.",
|
||||
}, func(ctx context.Context, _ *mcpsdk.CallToolRequest, in createPRInput) (*mcpsdk.CallToolResult, forge.PullRequest, error) {
|
||||
pr, err := svc.CreatePR(ctx, activity.ActorClaude, in.Path, in.Head, in.Base, in.Title, in.Body)
|
||||
if err != nil {
|
||||
return nil, forge.PullRequest{}, err
|
||||
}
|
||||
return nil, pr, nil
|
||||
})
|
||||
|
||||
// merge_and_cleanup_pr — DESTRUCTIVE: merges a PR and deletes its branch.
|
||||
mcpsdk.AddTool(s, &mcpsdk.Tool{
|
||||
Name: "merge_and_cleanup_pr",
|
||||
|
||||
Reference in New Issue
Block a user