From 864ba9ab530eb04520e269e708ec52d4f0b81dd5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=97=B2=E8=80=98=E2=84=A2?= Date: Sun, 9 Aug 2015 17:16:59 +0800 Subject: [PATCH] feat(gitopen commit): Open git diff page with hash. --- README.md | 5 +++++ bin/gitopen | 8 ++++---- bin/open-commander.js | 21 +++++++++++++++------ lib/gitremote.js | 4 ++-- lib/index.js | 8 ++++++-- lib/scheme/bitbucket.js | 2 +- lib/scheme/coding.js | 2 +- lib/scheme/gitcafe.js | 2 +- lib/scheme/github.js | 2 +- lib/scheme/gitlab.js | 2 +- lib/scheme/oschina.js | 2 +- test/gitopen.test.js | 30 +++++++++++++++++++++--------- 12 files changed, 59 insertions(+), 29 deletions(-) diff --git a/README.md b/README.md index f5850bf..7bd95ac 100644 --- a/README.md +++ b/README.md @@ -67,6 +67,7 @@ $ gitopen wiki # Open wiki pages. $ gitopen release # Open releases page. $ gitopen tags # Open tags page. $ gitopen commits # Open commits pages. +$ gitopen {hash} # Open commit page by hash code. $ gitopen README.md # Open remote blob url. default use current working branch. $ gitopen README.md -b branch # Open remote blob url by given branch. @@ -184,6 +185,10 @@ alias: * `$ gitopen commit` * `$ gitopen ci` +### $ gitopen {hash} + +Open commit page by hash code. + ### $ gitopen wiki Open git repository wiki home page. diff --git a/bin/gitopen b/bin/gitopen index 883b4fd..8168749 100755 --- a/bin/gitopen +++ b/bin/gitopen @@ -21,9 +21,9 @@ var command = commander(process.argv, { if (command.category === 'profile') { var username = command.args.username; var reponame = command.args.reponame; - var url = 'https://github.com/' + username + (reponame? '/'+reponame : ''); + var url = 'https://github.com/' + username + (reponame ? '/' + reponame : ''); if (command.verbose) { - console.log("URL:", url); + console.log('URL:', url); process.exit(0); return 0; } @@ -53,8 +53,8 @@ command.protocol = config.protocol; var url = gitresolve(uri, command); // 7. open if (command.verbose) { - console.log("Option:", command) - console.log("URL:", url); + console.log('Option:', command); + console.log('URL:', url); } else { xopen(url); } diff --git a/bin/open-commander.js b/bin/open-commander.js index a93e91f..675ed74 100644 --- a/bin/open-commander.js +++ b/bin/open-commander.js @@ -89,7 +89,7 @@ module.exports = function(argv, option) { }; // prepare processing branch alias like `:branch-name` - for (var i=commander.args.length-1; i>=0; i--) { + for (var i = commander.args.length - 1; i >= 0; i--) { if (commander.args[i].indexOf(':') === 0) { var br = commander.args[i].substring(1); options.hash = br; @@ -106,6 +106,7 @@ module.exports = function(argv, option) { // branch-a:branch-b // branch-a...branch-b var RE_BRANCH_COMPARE = /^(.*?)(?::|\.{3})(.*)$/; + var RE_HASH = /^[0-9a-fA-F]{6,40}$/; var category = commander.args[0]; var match; @@ -166,7 +167,7 @@ module.exports = function(argv, option) { options.category = 'milestones/new'; options.args = { title: commander.args.slice(1).join(' ') - } + }; break; case 'milestones': options.category = 'milestones'; @@ -194,6 +195,11 @@ module.exports = function(argv, option) { break; case 'ci': case 'commit': + //options.category = 'commit'; + //if (commander.args[2] && commander.args[2] !== '.') { + //options.hash = commander.args[2]; + //} + //break; case 'commits': options.category = 'commits'; if (commander.branch) { @@ -230,12 +236,12 @@ module.exports = function(argv, option) { options.args = { issue_id: category.substring(1), }; - } else if (m = RE_PR_ID.exec(category)) { + } else if ((m = RE_PR_ID.exec(category))) { options.category = 'pulls/id'; options.args = { pull_id: m[1], }; - } else if (m = RE_PROFILE.exec(category)) { + } else if ((m = RE_PROFILE.exec(category))) { var username = m[1]; var reponame = m[2]; options.category = 'profile'; @@ -243,16 +249,19 @@ module.exports = function(argv, option) { username: username, reponame: reponame, }; - } else if (m = RE_MILESTONE.exec(category)) { + } else if ((m = RE_MILESTONE.exec(category))) { options.category = 'milestones/id'; options.args = { milestone_id: m[1], }; - } else if (m = RE_GIST.exec(category)) { + } else if ((m = RE_GIST.exec(category))) { options.category = 'snippets/new'; options.args = { type: m[1], }; + } else if (RE_HASH.test(category)) { + options.category = 'commit'; + options.hash = category; } else { // FILE/DIR PATH if (!parseFilePath(options, category)) { diff --git a/lib/gitremote.js b/lib/gitremote.js index 9b1f230..d3ff315 100644 --- a/lib/gitremote.js +++ b/lib/gitremote.js @@ -24,7 +24,7 @@ exports.getCurrentBranch = function getCurrentBranch(cwd) { 'git symbolic-ref --short HEAD', 'git rev-parse --abbrev-ref HEAD', ]; - for (var i=0, l=cmds.length; i