Skip to content

Commit

Permalink
fixup! fixup! fixup! fixup! fixup! ci: add pr number validation
Browse files Browse the repository at this point in the history
  • Loading branch information
Hotell committed Nov 8, 2024
1 parent 5273ac4 commit 15624d7
Showing 1 changed file with 13 additions and 6 deletions.
19 changes: 13 additions & 6 deletions .github/scripts/validate-pr-number.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
// @ts-check

const { readFileSync } = require('fs');
const { readFileSync, existsSync } = require('node:fs');

module.exports = main;

function main() {
return validatePrNumber('results/pr.txt');
/**
*
* @param {{filePath:string}} options
* @returns
*/
function main(options) {
return validatePrNumber(options.filePath);
}

/**
Expand All @@ -14,14 +19,16 @@ function main() {
* @returns {number}
*/
function validatePrNumber(filePath) {
// const filePath = join(/* __dirname, */ 'results/pr.txt');

try {
if (existsSync(filePath)) {
throw new Error(`'${filePath}' doesn't exists`);
}

const content = readFileSync(filePath, 'utf-8').trim();
const prNumber = Number(content);

if (isNaN(prNumber) || !Number.isInteger(prNumber)) {
throw new Error('The ID in pr.txt is not a PR number.');
throw new Error('The ID in pr.txt is not a valid PR number.');
}

console.info('✅ PR ID valid');
Expand Down

0 comments on commit 15624d7

Please sign in to comment.