Skip to content

Commit

Permalink
allow passing full URLs on the command line
Browse files Browse the repository at this point in the history
  • Loading branch information
addaleax committed Oct 26, 2017
1 parent 6f5e018 commit 04a5792
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]);

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:.*\/pull\/([0-9]+)(?:\/(?:files)?)?$/);
if (match !== null)
return +match[1];
throw new Error(`Could not understand PR id format: ${id}`);
}

0 comments on commit 04a5792

Please sign in to comment.