-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathindex.js
More file actions
64 lines (51 loc) · 1.47 KB
/
index.js
File metadata and controls
64 lines (51 loc) · 1.47 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
const core = require('@actions/core');
const github = require('@actions/github');
const auth = core.getInput('auth');
const repo = core.getInput('repo');
const owner = core.getInput('owner');
const pr = core.getInput('pr');
const url = core.getInput('url');
const message = core.getInput('message');
if (!auth || !repo || !owner || !pr || !url) {
core.setFailed('Please provide all arguments');
return 1;
}
const octokit = github.getOctokit(auth);
async function main() {
const data = await octokit
.request('GET /repos/{owner}/{repo}/pulls/{pull_number}', {
owner,
repo,
pull_number: pr,
})
.then(({ data }) => data)
.catch((error) => core.error(error));
if (!data) {
core.setFailed(`Error while getting PR ${pr}`);
return 1;
}
let { body } = data;
if (!body) {
core.info('Pull request has no description, setting it to an empty string');
body = '';
}
if (body.includes(url)) {
core.info('Decription already includes deployed url');
return 0;
}
const displayedMessage = message ? message : 'Deployed to:';
const updatedBody = `${body} \n\n ----- \n${displayedMessage} ${url}`;
const updateResponse = await octokit
.request('PATCH /repos/{owner}/{repo}/pulls/{pull_number}', {
owner,
repo,
pull_number: pr,
body: updatedBody,
})
.catch((error) => core.error(error));
if (!updateResponse) {
core.setFailed(`Error while updating PR ${pr}`);
return 1;
}
}
main();