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