2020-08-05 18:59:52 +03:00
|
|
|
const { Octokit } = require('@octokit/rest');
|
2024-10-03 05:10:44 +03:00
|
|
|
const minimist = require('minimist');
|
|
|
|
|
|
|
|
const args = minimist(process.argv.slice(2));
|
|
|
|
|
2020-08-05 18:59:52 +03:00
|
|
|
const octokit = new Octokit();
|
2019-10-24 02:36:26 +03:00
|
|
|
|
|
|
|
async function checkIfDocOnlyChange () {
|
2023-05-30 19:38:41 +03:00
|
|
|
let { prNumber, prURL } = args;
|
|
|
|
|
|
|
|
if (prNumber || prURL) {
|
2019-10-24 02:36:26 +03:00
|
|
|
try {
|
2024-07-15 21:26:41 +03:00
|
|
|
// extract the PR number from the PR URL.
|
2023-05-30 19:38:41 +03:00
|
|
|
if (!prNumber || isNaN(prNumber)) {
|
2020-02-07 20:58:47 +03:00
|
|
|
if (args.prURL) {
|
2023-05-30 19:38:41 +03:00
|
|
|
prNumber = prURL.split('/').pop();
|
2019-10-24 02:36:26 +03:00
|
|
|
}
|
|
|
|
}
|
2023-05-30 19:38:41 +03:00
|
|
|
|
2021-04-20 03:00:28 +03:00
|
|
|
const filesChanged = await octokit.paginate(octokit.pulls.listFiles.endpoint.merge({
|
|
|
|
owner: 'electron',
|
|
|
|
repo: 'electron',
|
2023-05-30 19:38:41 +03:00
|
|
|
pull_number: prNumber,
|
2021-04-20 03:00:28 +03:00
|
|
|
per_page: 100
|
|
|
|
}));
|
2019-10-24 02:36:26 +03:00
|
|
|
|
2023-05-30 19:38:41 +03:00
|
|
|
console.log('Changed Files: ', filesChanged.map(fileInfo => fileInfo.filename));
|
2020-09-22 12:19:00 +03:00
|
|
|
|
2023-05-30 19:38:41 +03:00
|
|
|
const nonDocChange = filesChanged.length === 0 || filesChanged.find(({ filename }) => {
|
|
|
|
const fileDirs = filename.split('/');
|
|
|
|
if (fileDirs[0] !== 'docs') return true;
|
2024-09-26 10:12:11 +03:00
|
|
|
return false;
|
2019-10-24 02:36:26 +03:00
|
|
|
});
|
2023-05-30 19:38:41 +03:00
|
|
|
|
|
|
|
process.exit(nonDocChange ? 1 : 0);
|
|
|
|
} catch (error) {
|
|
|
|
console.error('Error getting list of files changed: ', error);
|
2019-10-24 02:36:26 +03:00
|
|
|
process.exit(-1);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
console.error(`Check if only the docs were changed for a commit.
|
2023-05-30 19:38:41 +03:00
|
|
|
Usage: doc-only-change.js --prNumber=PR_NUMBER || --prURL=PR_URL`);
|
2019-10-24 02:36:26 +03:00
|
|
|
process.exit(-1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
checkIfDocOnlyChange();
|