Skip to content

Commit 04a5792

Browse files
committed
allow passing full URLs on the command line
i.e. make `get-metadata https://github.com/nodejs/node/pull/16489` work
1 parent 6f5e018 commit 04a5792

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

bin/metadata.js

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ const MetadataGenerator = require('../lib/metadata_gen');
2525
const OWNER = 'nodejs';
2626
const REPO = 'node';
2727

28-
const PR_ID = parseInt(process.argv[2]); // example
28+
const PR_ID = parsePRId(process.argv[2]);
2929

3030
async function main(prid, owner, repo) {
3131
logger.trace(`Getting collaborator contacts from README of ${owner}/${repo}`);
@@ -68,3 +68,13 @@ main(PR_ID, OWNER, REPO).catch((err) => {
6868
logger.error(err);
6969
process.exit(-1);
7070
});
71+
72+
function parsePRId(id) {
73+
// Fast path: numeric string
74+
if (`${+id}` === id)
75+
return +id;
76+
const match = id.match(/^https:.*\/pull\/([0-9]+)(?:\/(?:files)?)?$/);
77+
if (match !== null)
78+
return +match[1];
79+
throw new Error(`Could not understand PR id format: ${id}`);
80+
}

0 commit comments

Comments
 (0)