|
| 1 | +import github from "../../github.app.mjs"; |
| 2 | + |
| 3 | +export default { |
| 4 | + key: "github-update-pull-request", |
| 5 | + name: "Update Pull Request", |
| 6 | + description: "Updates an existing pull request with new title, body, state, or base branch. [See the documentation](https://docs.github.com/en/rest/pulls/pulls#update-a-pull-request)", |
| 7 | + version: "0.0.1", |
| 8 | + type: "action", |
| 9 | + annotations: { |
| 10 | + destructiveHint: true, |
| 11 | + openWorldHint: true, |
| 12 | + readOnlyHint: false, |
| 13 | + }, |
| 14 | + props: { |
| 15 | + github, |
| 16 | + repoFullname: { |
| 17 | + propDefinition: [ |
| 18 | + github, |
| 19 | + "repoFullname", |
| 20 | + ], |
| 21 | + label: "Repository", |
| 22 | + description: "The repository where the pull request exists.", |
| 23 | + }, |
| 24 | + pullNumber: { |
| 25 | + propDefinition: [ |
| 26 | + github, |
| 27 | + "pullNumber", |
| 28 | + (c) => ({ |
| 29 | + repoFullname: c.repoFullname, |
| 30 | + }), |
| 31 | + ], |
| 32 | + label: "Pull Request Number", |
| 33 | + description: "The number of the pull request to update.", |
| 34 | + }, |
| 35 | + title: { |
| 36 | + label: "Title", |
| 37 | + description: "The title of the pull request.", |
| 38 | + type: "string", |
| 39 | + optional: true, |
| 40 | + }, |
| 41 | + body: { |
| 42 | + label: "Body", |
| 43 | + description: "The contents of the pull request body. Supports markdown.", |
| 44 | + type: "string", |
| 45 | + optional: true, |
| 46 | + }, |
| 47 | + state: { |
| 48 | + label: "State", |
| 49 | + description: "The desired state of the pull request.", |
| 50 | + type: "string", |
| 51 | + optional: true, |
| 52 | + options: [ |
| 53 | + "open", |
| 54 | + "closed", |
| 55 | + ], |
| 56 | + }, |
| 57 | + base: { |
| 58 | + propDefinition: [ |
| 59 | + github, |
| 60 | + "branch", |
| 61 | + (c) => ({ |
| 62 | + repoFullname: c.repoFullname, |
| 63 | + }), |
| 64 | + ], |
| 65 | + label: "Base Branch", |
| 66 | + description: "The name of the branch you want your changes pulled into. This should be an existing branch on the current repository.", |
| 67 | + optional: true, |
| 68 | + }, |
| 69 | + maintainerCanModify: { |
| 70 | + label: "Maintainers Can Modify", |
| 71 | + description: "Indicates whether [maintainers can modify](https://docs.github.com/articles/allowing-changes-to-a-pull-request-branch-created-from-a-fork/) the pull request.", |
| 72 | + type: "boolean", |
| 73 | + optional: true, |
| 74 | + }, |
| 75 | + }, |
| 76 | + async run({ $ }) { |
| 77 | + const { |
| 78 | + github, |
| 79 | + repoFullname, |
| 80 | + pullNumber, |
| 81 | + title, |
| 82 | + body, |
| 83 | + state, |
| 84 | + base, |
| 85 | + maintainerCanModify, |
| 86 | + } = this; |
| 87 | + |
| 88 | + const data = {}; |
| 89 | + |
| 90 | + if (title) { |
| 91 | + data.title = title; |
| 92 | + } |
| 93 | + |
| 94 | + if (body) { |
| 95 | + data.body = body; |
| 96 | + } |
| 97 | + |
| 98 | + if (state) { |
| 99 | + data.state = state; |
| 100 | + } |
| 101 | + |
| 102 | + if (base) { |
| 103 | + // Extract branch name from the branch prop format (sha/branchname) |
| 104 | + data.base = base.split("/")[1]; |
| 105 | + } |
| 106 | + |
| 107 | + // Only include maintainer_can_modify if explicitly set to true |
| 108 | + // This field only applies to cross-repo pull requests (from forks) |
| 109 | + if (maintainerCanModify === true) { |
| 110 | + data.maintainer_can_modify = maintainerCanModify; |
| 111 | + } |
| 112 | + |
| 113 | + const response = await github.updatePullRequest({ |
| 114 | + repoFullname, |
| 115 | + pullNumber, |
| 116 | + data, |
| 117 | + }); |
| 118 | + |
| 119 | + $.export("$summary", `Successfully updated pull request with ID \`${response.id}\``); |
| 120 | + |
| 121 | + return response; |
| 122 | + }, |
| 123 | +}; |
0 commit comments