forked from kt3k/update-pr-description
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
51 lines (42 loc) · 1.36 KB
/
index.js
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
const github = require("@actions/github");
const core = require("@actions/core");
async function run() {
const inputs = {
githubToken: core.getInput("github_token", { required: true }),
prTitle: core.getInput("pr_title"),
prBody: core.getInput("pr_body"),
destinationBranch: core.getInput("destination_branch"),
sourceBranch: core.getInput("source_branch")
};
const base = inputs.destinationBranch;
const source = inputs.sourceBranch;
const octokit = new github.GitHub(inputs.githubToken);
core.info(`Look up a pull request with source=${source} base=${base}`);
const { data: pulls } = await octokit.pulls.list({
owner: github.context.repo.owner,
repo: github.context.repo.repo,
base,
head: `${github.context.repo.owner}:${source}`
});
if (pulls.length == 0) {
core.info(`No such pull request: source=${source} base=${base}`);
return;
}
const { number } = pulls[0];
core.info(`Found pull request #${number}`);
const params = {
owner: github.context.repo.owner,
repo: github.context.repo.repo,
pull_number: number
};
if (inputs.prBody) {
core.info(`Updating with body=${inputs.prBody}`);
params.body = inputs.prBody;
}
if (inputs.prTitle) {
core.info(`Updating with title=#${inputs.prTitle}`);
params.title = inputs.prTitle;
}
await octokit.pulls.update(params);
}
run();