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();
|
2019-10-23 23:36:26 +00:00
|
|
|
|
|
|
|
async function checkIfDocOnlyChange () {
|
2023-05-30 16:38:41 +00:00
|
|
|
let { prNumber, prURL } = args;
|
|
|
|
|
|
|
|
if (prNumber || prURL) {
|
2019-10-23 23:36:26 +00:00
|
|
|
try {
|
2023-05-30 16:38:41 +00:00
|
|
|
// CircleCI doesn't provide the PR number except on forked PRs,
|
|
|
|
// so to cover all cases we just extract it from the PR URL.
|
|
|
|
if (!prNumber || isNaN(prNumber)) {
|
2020-02-07 17:58:47 +00:00
|
|
|
if (args.prURL) {
|
2023-05-30 16:38:41 +00:00
|
|
|
prNumber = prURL.split('/').pop();
|
2019-10-23 23:36:26 +00:00
|
|
|
}
|
|
|
|
}
|
2023-05-30 16:38:41 +00:00
|
|
|
|
2021-04-20 00:00:28 +00:00
|
|
|
const filesChanged = await octokit.paginate(octokit.pulls.listFiles.endpoint.merge({
|
|
|
|
owner: 'electron',
|
|
|
|
repo: 'electron',
|
2023-05-30 16:38:41 +00:00
|
|
|
pull_number: prNumber,
|
2021-04-20 00:00:28 +00:00
|
|
|
per_page: 100
|
|
|
|
}));
|
2019-10-23 23:36:26 +00:00
|
|
|
|
2023-05-30 16:38:41 +00:00
|
|
|
console.log('Changed Files: ', filesChanged.map(fileInfo => fileInfo.filename));
|
2020-09-22 09:19:00 +00:00
|
|
|
|
2023-05-30 16:38:41 +00:00
|
|
|
const nonDocChange = filesChanged.length === 0 || filesChanged.find(({ filename }) => {
|
|
|
|
const fileDirs = filename.split('/');
|
|
|
|
if (fileDirs[0] !== 'docs') return true;
|
2020-03-20 20:28:31 +00:00
|
|
|
});
|
2023-05-30 16:38:41 +00:00
|
|
|
|
|
|
|
process.exit(nonDocChange ? 1 : 0);
|
|
|
|
} catch (error) {
|
|
|
|
console.error('Error getting list of files changed: ', error);
|
2020-03-20 20:28:31 +00:00
|
|
|
process.exit(-1);
|
2019-10-23 23:36:26 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
console.error(`Check if only the docs were changed for a commit.
|
2023-05-30 16:38:41 +00:00
|
|
|
Usage: doc-only-change.js --prNumber=PR_NUMBER || --prURL=PR_URL`);
|
2020-03-20 20:28:31 +00:00
|
|
|
process.exit(-1);
|
2019-10-23 23:36:26 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-03-20 20:28:31 +00:00
|
|
|
checkIfDocOnlyChange();
|