UpdatePullRequestBranch creates a tool to update a pull request branch with the latest changes from the base branch.
(t translations.TranslationHelperFunc)
| 1621 | |
| 1622 | // UpdatePullRequestBranch creates a tool to update a pull request branch with the latest changes from the base branch. |
| 1623 | func UpdatePullRequestBranch(t translations.TranslationHelperFunc) inventory.ServerTool { |
| 1624 | schema := &jsonschema.Schema{ |
| 1625 | Type: "object", |
| 1626 | Properties: map[string]*jsonschema.Schema{ |
| 1627 | "owner": { |
| 1628 | Type: "string", |
| 1629 | Description: "Repository owner", |
| 1630 | }, |
| 1631 | "repo": { |
| 1632 | Type: "string", |
| 1633 | Description: "Repository name", |
| 1634 | }, |
| 1635 | "pullNumber": { |
| 1636 | Type: "number", |
| 1637 | Description: "Pull request number", |
| 1638 | }, |
| 1639 | "expectedHeadSha": { |
| 1640 | Type: "string", |
| 1641 | Description: "The expected SHA of the pull request's HEAD ref", |
| 1642 | }, |
| 1643 | }, |
| 1644 | Required: []string{"owner", "repo", "pullNumber"}, |
| 1645 | } |
| 1646 | |
| 1647 | return NewTool( |
| 1648 | ToolsetMetadataPullRequests, |
| 1649 | mcp.Tool{ |
| 1650 | Name: "update_pull_request_branch", |
| 1651 | Description: t("TOOL_UPDATE_PULL_REQUEST_BRANCH_DESCRIPTION", "Update the branch of a pull request with the latest changes from the base branch."), |
| 1652 | Annotations: &mcp.ToolAnnotations{ |
| 1653 | Title: t("TOOL_UPDATE_PULL_REQUEST_BRANCH_USER_TITLE", "Update pull request branch"), |
| 1654 | ReadOnlyHint: false, |
| 1655 | }, |
| 1656 | InputSchema: schema, |
| 1657 | }, |
| 1658 | []scopes.Scope{scopes.Repo}, |
| 1659 | func(ctx context.Context, deps ToolDependencies, _ *mcp.CallToolRequest, args map[string]any) (*mcp.CallToolResult, any, error) { |
| 1660 | owner, err := RequiredParam[string](args, "owner") |
| 1661 | if err != nil { |
| 1662 | return utils.NewToolResultError(err.Error()), nil, nil |
| 1663 | } |
| 1664 | repo, err := RequiredParam[string](args, "repo") |
| 1665 | if err != nil { |
| 1666 | return utils.NewToolResultError(err.Error()), nil, nil |
| 1667 | } |
| 1668 | pullNumber, err := RequiredInt(args, "pullNumber") |
| 1669 | if err != nil { |
| 1670 | return utils.NewToolResultError(err.Error()), nil, nil |
| 1671 | } |
| 1672 | expectedHeadSHA, err := OptionalParam[string](args, "expectedHeadSha") |
| 1673 | if err != nil { |
| 1674 | return utils.NewToolResultError(err.Error()), nil, nil |
| 1675 | } |
| 1676 | opts := &github.PullRequestBranchUpdateOptions{} |
| 1677 | if expectedHeadSHA != "" { |
| 1678 | opts.ExpectedHeadSHA = github.Ptr(expectedHeadSHA) |
| 1679 | } |
| 1680 |