Skip to content

Commit ce17e79

Browse files
committed
[ACTION] Github - Update a Pull Request
1 parent 7ba3f2b commit ce17e79

File tree

3 files changed

+131
-1
lines changed

3 files changed

+131
-1
lines changed
Lines changed: 123 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
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+
};

components/github/github.app.mjs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -599,6 +599,13 @@ export default {
599599

600600
return response.data;
601601
},
602+
async updatePullRequest({
603+
repoFullname, pullNumber, data,
604+
}) {
605+
const response = await this._client().request(`PATCH /repos/${repoFullname}/pulls/${pullNumber}`, data);
606+
607+
return response.data;
608+
},
602609
async getIssue({
603610
repoFullname, issueNumber,
604611
}) {

components/github/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@pipedream/github",
3-
"version": "1.8.3",
3+
"version": "1.9.0",
44
"description": "Pipedream GitHub Components",
55
"main": "github.app.mjs",
66
"keywords": [

0 commit comments

Comments
 (0)