Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

allow passing full URLs on the command line #6

Merged
merged 1 commit into from
Oct 26, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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}`);
}