2019-10-23 23:36:26 +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 {
|
2024-07-15 21:56:53 +00:00
|
|
|
// extract the PR number from the PR URL.
|
2023-05-30 16:38:41 +00:00
|
|
|
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;
|
2019-10-23 23:36:26 +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);
|
2019-10-23 23:36:26 +00:00
|
|
|
process.exit(-1);
|
|
|
|
}
|
|
|
|
} 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`);
|
2019-10-23 23:36:26 +00:00
|
|
|
process.exit(-1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
checkIfDocOnlyChange();
|