Skip to content

Commit

Permalink
allow passing full URLs on the command line
Browse files Browse the repository at this point in the history
i.e. make `get-metadata nodejs/node#16489 work
  • Loading branch information
addaleax committed Oct 25, 2017
1 parent 6f5e018 commit c7d4668
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion bin/metadata.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ const MetadataGenerator = require('../lib/metadata_gen');
const OWNER = 'nodejs';
const REPO = 'node';

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

async function main(prid, owner, repo) {
logger.trace(`Getting collaborator contacts from README of ${owner}/${repo}`);
Expand Down Expand Up @@ -68,3 +68,13 @@ main(PR_ID, OWNER, REPO).catch((err) => {
logger.error(err);
process.exit(-1);
});

function parsePRId(id) {
// Fast path: numeric string
if (`${+id}` === id)
return +id;
const match = id.match(/^https:.*\/([0-9]+)$/);
if (match !== null)
return +match[1];
throw new Error(`Could not understand PR id format: ${id}`);
}

0 comments on commit c7d4668

Please sign in to comment.