-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.js
67 lines (53 loc) · 1.77 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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
// -*- javascript -*-
const core = require('@actions/core');
const github = require('@actions/github');
const { execSync } = require('child_process');
const url = require('url');
const fs = require('fs');
function myExecSync(cmd) {
console.log(`+ ${cmd}`);
const output = execSync(cmd, { encoding: 'utf-8' });
console.log(`${output}`);
return output;
}
async function run() {
try {
const token = core.getInput('token');
const checkUnmergedPr = core.getBooleanInput('check-unmerged-pr');
const context = github.context;
if (!context.payload.pull_request) {
console.log('Not a pull request. Skipping');
return;
}
const prNumber = context.payload.pull_request.number;
console.log(`Pull Request number: ${prNumber} checkUnmergedPr=${checkUnmergedPr}`);
myExecSync('pwd');
const octokit = github.getOctokit(token);
// Get details of the main PR
const { data: mainPR } = await octokit.rest.pulls.get({
owner: context.repo.owner,
repo: context.repo.repo,
pull_number: prNumber
});
const description = mainPR.body;
console.log(`description: ${description}`);
if (!description) {
return
}
const changeJson = {
fork_url: mainPR.head.repo.clone_url,
branch: mainPR.head.ref,
description: description
};
fs.writeFileSync('.depends-on.json', JSON.stringify(changeJson));
console.log(`writing .depends-on.json: ${JSON.stringify(changeJson)}`);
// export token as the GITHUB_TOKEN env variable
core.exportVariable('GITHUB_TOKEN', token);
// the bundle is in the dist sub-directory
execSync(`${__dirname}/../stage1.py ${checkUnmergedPr}`, { encoding: 'utf-8' });
} catch (error) {
console.log(error);
core.setFailed(error.message);
}
}
run();