2020-03-20 20:28:31 +00:00
|
|
|
const args = require('minimist')(process.argv.slice(2));
|
2020-08-05 15:59:52 +00:00
|
|
|
const { Octokit } = require('@octokit/rest');
|
|
|
|
const octokit = new Octokit();
|
2020-03-20 20:28:31 +00:00
|
|
|
const path = require('path');
|
2019-10-23 23:36:26 +00:00
|
|
|
|
2020-03-20 20:28:31 +00:00
|
|
|
const SOURCE_ROOT = path.normalize(path.dirname(__dirname));
|
2019-10-23 23:36:26 +00:00
|
|
|
|
|
|
|
async function checkIfDocOnlyChange () {
|
|
|
|
if (args.prNumber || args.prBranch || args.prURL) {
|
|
|
|
try {
|
2020-03-20 20:28:31 +00:00
|
|
|
let pullRequestNumber = args.prNumber;
|
2019-10-23 23:36:26 +00:00
|
|
|
if (!pullRequestNumber || isNaN(pullRequestNumber)) {
|
2020-02-07 17:58:47 +00:00
|
|
|
if (args.prURL) {
|
|
|
|
// CircleCI doesn't provide the PR number for branch builds, but it does provide the PR URL
|
2020-03-20 20:28:31 +00:00
|
|
|
const pullRequestParts = args.prURL.split('/');
|
|
|
|
pullRequestNumber = pullRequestParts[pullRequestParts.length - 1];
|
2020-02-07 17:58:47 +00:00
|
|
|
} else if (args.prBranch) {
|
2019-10-23 23:36:26 +00:00
|
|
|
// AppVeyor doesn't provide a PR number for branch builds - figure it out from the branch
|
|
|
|
const prsForBranch = await octokit.pulls.list({
|
|
|
|
owner: 'electron',
|
|
|
|
repo: 'electron',
|
|
|
|
state: 'open',
|
|
|
|
head: `electron:${args.prBranch}`
|
2020-03-20 20:28:31 +00:00
|
|
|
});
|
2019-10-23 23:36:26 +00:00
|
|
|
if (prsForBranch.data.length === 1) {
|
2020-03-20 20:28:31 +00:00
|
|
|
pullRequestNumber = prsForBranch.data[0].number;
|
2019-10-23 23:36:26 +00:00
|
|
|
} else {
|
2019-10-28 13:40:21 +00:00
|
|
|
// If there are 0 PRs or more than one PR on a branch, just assume that this is more than a doc change
|
2020-03-20 20:28:31 +00:00
|
|
|
process.exit(1);
|
2019-10-23 23:36:26 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
const filesChanged = await octokit.pulls.listFiles({
|
|
|
|
owner: 'electron', repo: 'electron', pull_number: pullRequestNumber
|
2020-03-20 20:28:31 +00:00
|
|
|
});
|
2019-10-23 23:36:26 +00:00
|
|
|
|
|
|
|
const nonDocChange = filesChanged.data.find((fileInfo) => {
|
2020-03-20 20:28:31 +00:00
|
|
|
const fileDirs = fileInfo.filename.split('/');
|
2019-10-23 23:36:26 +00:00
|
|
|
if (fileDirs[0] !== 'docs') {
|
2020-03-20 20:28:31 +00:00
|
|
|
return true;
|
2019-10-23 23:36:26 +00:00
|
|
|
}
|
2020-03-20 20:28:31 +00:00
|
|
|
});
|
2020-04-23 15:01:30 +00:00
|
|
|
if (nonDocChange || filesChanged.data.length === 0) {
|
2020-03-20 20:28:31 +00:00
|
|
|
process.exit(1);
|
2019-10-23 23:36:26 +00:00
|
|
|
} else {
|
2020-03-20 20:28:31 +00:00
|
|
|
process.exit(0);
|
2019-10-23 23:36:26 +00:00
|
|
|
}
|
|
|
|
} catch (ex) {
|
2020-03-20 20:28:31 +00:00
|
|
|
console.error('Error getting list of files changed: ', ex);
|
|
|
|
process.exit(-1);
|
2019-10-23 23:36:26 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
console.error(`Check if only the docs were changed for a commit.
|
2020-03-20 20:28:31 +00:00
|
|
|
Usage: doc-only-change.js --prNumber=PR_NUMBER || --prBranch=PR_BRANCH || --prURL=PR_URL`);
|
|
|
|
process.exit(-1);
|
2019-10-23 23:36:26 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-03-20 20:28:31 +00:00
|
|
|
checkIfDocOnlyChange();
|