Skip to content

Commit

Permalink
allow git-node land to work with full PR url (#213) (#219)
Browse files Browse the repository at this point in the history
* allow git-node land to work with full PR url (#213)
* replace is-url module with regex validation
* land $URL: change help text
  • Loading branch information
aks- authored and joyeecheung committed Mar 23, 2018
1 parent 704547d commit 598a3a2
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 3 deletions.
1 change: 1 addition & 0 deletions components/git/epilogue.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ $ ncu-config set branch master # Assuming you are landing commits on master
$ git checkout master
$ git node land --abort # Abort a landing session, just in case
$ git node land $PRID # Start a new landing session
$ git node land $URL # Start a new landing session using the PR URL
$ git rebase -i upstream/master # Put "edit" on every commit that's gonna stay
Expand Down
15 changes: 12 additions & 3 deletions components/git/land.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,11 @@ const landOptions = {
function builder(yargs) {
return yargs
.options(landOptions).positional('prid', {
describe: 'ID of the Pull Request',
type: 'number'
describe: 'ID or URL of the Pull Request'
})
.epilogue(epilogue)
.example('git node land https://github.com/nodejs/node/pull/12344',
'Land https://github.com/nodejs/node/pull/12344 in the current directory')
.example('git node land 12344',
'Land https://github.com/nodejs/node/pull/12344 in the current directory')
.example('git node land --abort',
Expand All @@ -58,8 +59,12 @@ const FINAL = 'final';
const CONTINUE = 'continue';
const ABORT = 'abort';

const GITHUB_PULL_REQUEST_URL = /github.com\/[^/]+\/[^/]+\/pull\/(\d+)/;

function handler(argv) {
if (argv.prid && Number.isInteger(argv.prid)) {
if (argv.prid &&
(Number.isInteger(argv.prid) || argv.prid.match(GITHUB_PULL_REQUEST_URL))
) {
return land(START, argv);
}
const provided = [];
Expand Down Expand Up @@ -124,6 +129,10 @@ async function main(state, argv, cli, req, dir) {
}

if (state === START) {
if (argv.prid.match && argv.prid.match(GITHUB_PULL_REQUEST_URL)) {
argv.prid = Number(argv.prid.split('/').pop());
}

if (session.hasStarted()) {
cli.warn(
'Previous `git node land` session for ' +
Expand Down
1 change: 1 addition & 0 deletions docs/git-node.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ $ ncu-config set branch master # Assuming you are landing commits on master
$ git checkout master
$ git node land --abort # Abort a landing session, just in case
$ git node land $PRID # Start a new landing session
$ git node land $URL # Start a new landing session using the PR URL
$ git rebase -i upstream/master # Put "edit" on every commit that's gonna stay
Expand Down

0 comments on commit 598a3a2

Please sign in to comment.