From aa7852317f1df316251024b5f57c9bef0e7eb8ea Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=97=B2=E8=80=98=E2=84=A2?= Date: Wed, 22 Jul 2015 06:19:51 +0800 Subject: [PATCH 1/5] feat(mr@1): alias for pr/mr --- bin/open-commander.js | 6 +++--- test/gitopen.test.js | 10 ++++++++++ 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/bin/open-commander.js b/bin/open-commander.js index 36e2285..cae2843 100644 --- a/bin/open-commander.js +++ b/bin/open-commander.js @@ -23,7 +23,7 @@ module.exports = function(argv) { }; var RE_ISSUE_ID = /^#\d+$/; - var RE_PR_ID = /^!\d+$/; + var RE_PR_ID = /^(?:!|(?:pr|mr)[\-:\/#@]?)(\d+)$/i; var RE_PROFILE = /^@([a-z0-9-_]+)(?:\/([a-z0-9-_]+)(?:#\d+|:\w+|\/\w+)?)?$/i; // branch-a:branch-b // branch-a...branch-b @@ -146,10 +146,10 @@ module.exports = function(argv) { options.args = { issue_id: category.substring(1), }; - } else if (RE_PR_ID.test(category)) { + } else if (m = RE_PR_ID.exec(category)) { options.category = 'pulls/id'; options.args = { - pull_id: category.substring(1), + pull_id: m[1], }; } else if (m = RE_PROFILE.exec(category)) { var username = m[1]; diff --git a/test/gitopen.test.js b/test/gitopen.test.js index a3e3e41..0f728bb 100644 --- a/test/gitopen.test.js +++ b/test/gitopen.test.js @@ -243,6 +243,16 @@ describe('$ gitopen', function () { ['pulls', '/hotoo/gitopen/pulls'], ['pulls new', '/hotoo/gitopen/compare'], ['!1', '/hotoo/gitopen/pulls/1'], + ['pr1', '/hotoo/gitopen/pulls/1'], + ['pr:1', '/hotoo/gitopen/pulls/1'], + ['pr-1', '/hotoo/gitopen/pulls/1'], + ['pr/1', '/hotoo/gitopen/pulls/1'], + ['pr@1', '/hotoo/gitopen/pulls/1'], + ['mr1', '/hotoo/gitopen/pulls/1'], + ['mr:1', '/hotoo/gitopen/pulls/1'], + ['mr-1', '/hotoo/gitopen/pulls/1'], + ['mr/1', '/hotoo/gitopen/pulls/1'], + ['mr@1', '/hotoo/gitopen/pulls/1'], ['ci', '/hotoo/gitopen/commits'], ['commit', '/hotoo/gitopen/commits'], ['commits', '/hotoo/gitopen/commits'], From cc20679f750a5f71c888b6a4e6cc22321cf92ad5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=97=B2=E8=80=98=E2=84=A2?= Date: Wed, 22 Jul 2015 06:22:23 +0800 Subject: [PATCH 2/5] doc(commands): completely command documents --- README.md | 133 ++++++++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 124 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index d5cb35e..526a479 100644 --- a/README.md +++ b/README.md @@ -64,17 +64,10 @@ $ gitopen wiki # Open wiki pages. $ gitopen release # Open releases page. $ gitopen tags # Open tags page. $ gitopen commits # Open commits pages. -$ gitopen network # global command. -$ gitopen @lizzie -$ gitopen @hotoo/gitopen - - -# Not Support Yet. -$ gitopen -p . # https://github.com/hotoo/gitopen/master/subdir -$ gitopen -p ../README.md # https://github.com/hotoo/gitopen/blob/master/README.md -$ gitopen -p ../../other-repo-dir # https://github.com/hotoo/other-repo-dir +$ gitopen @lizzie # https://github.com/lizzie +$ gitopen @hotoo/gitopen # https://github.com/hotoo/gitopen ``` ## Configuration @@ -121,6 +114,128 @@ Then you can use command like: $ git open ``` +## Commands + +### $ gitopen + +Open git repository homepage. + +### $ gitopen issues + +Open git repository issues list page. + +alias: + +* `$ gitopen issue` + +### $ gitopen issue new + +alias: + +* `$ gitopen issues new` + +### $ gitopen #1 + +Open git repository issue by id. + +### $ gitopen pulls + +Open git repository pulls list page. + +### $ gitopen pull [branch-name] + +Open pull request or merge request from given branch or current working branch +for git repository. + +alias: + +* `$ gitopen pr` +* `$ gitopen mr` + +for example: + +``` +$ gitopen pr # current working branch to compare default branch. +$ gitopen pr a # given branch(a) to compare default branch. +$ gitopen pr a b # branch b to compare branch a. +$ gitopen pr a...b # branch b to compare branch a. +``` + +### $ gitopen !1 + +Open git repository pull request or merge request by id. + +alias: + +* `$ gitopen pr1` +* `$ gitopen pr:1` +* `$ gitopen pr/1` +* `$ gitopen pr@1` +* `$ gitopen pr#1` +* `$ gitopen mr#1` +* ... + +### $ gitopen commits + +Open git repository commits list page. + +alias: + +* `$ gitopen commit` +* `$ gitopen ci` + +### $ gitopen wiki + +Open git repository wiki home page. + +alias: + +* `$ gitopen wikis` + +### $ gitopen tags + +Open git repository tags list page. + +alias: + +* `$ gitopen tag` + +### $ gitopen milestones + +Open git repository milestones list page. + +alias: + +* `$ gitopen milestone` + +### $ gitopen releases + +Open git repository releases list page. + +alias: + +* `$ gitopen release` + +### $ gitopen release new [tag-name] + +Open new release by tag name. + +### $ gitopen release edit + +Edit release by tag name. + +### $ gitopen network + +Open network page. + +### $ gitopen @profile + +Open profile page on GitHub. + +### $ gitopen @profile/repository-name + +Open given repository homepage on GitHub. + ## License [MIT](http://hotoo.mit-license.org/) From b014605bfc9330d2c7d87989da1e052c1b893d70 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=97=B2=E8=80=98=E2=84=A2?= Date: Wed, 22 Jul 2015 06:51:18 +0800 Subject: [PATCH 3/5] feat(issue): change 'gitopen issue' to open new issue, fixed #17. --- README.md | 10 ++-------- bin/open-commander.js | 14 +++++--------- lib/index.js | 9 +++++---- test/gitopen.test.js | 6 ++++-- 4 files changed, 16 insertions(+), 23 deletions(-) diff --git a/README.md b/README.md index 526a479..3e898e5 100644 --- a/README.md +++ b/README.md @@ -124,15 +124,9 @@ Open git repository homepage. Open git repository issues list page. -alias: - -* `$ gitopen issue` - -### $ gitopen issue new - -alias: +### $ gitopen issue [title] -* `$ gitopen issues new` +Open new issue with title (optional). ### $ gitopen #1 diff --git a/bin/open-commander.js b/bin/open-commander.js index cae2843..fa2efa4 100644 --- a/bin/open-commander.js +++ b/bin/open-commander.js @@ -34,17 +34,13 @@ module.exports = function(argv) { switch(category){ case 'issue': + options.category = 'issues/new'; + options.args = { + title: commander.args[1] + }; + break; case 'issues': options.category = 'issues'; - if (commander.args[1] === 'new') { - options.category = 'issues/new'; - if (commander.args[2]) { - options.category = 'issues/new-with-title'; - options.args = { - title: commander.args[2] - }; - } - } break; case 'pr': case 'mr': diff --git a/lib/index.js b/lib/index.js index 3e6d058..7abe2b7 100644 --- a/lib/index.js +++ b/lib/index.js @@ -65,10 +65,11 @@ module.exports = function(uri, options) { .replace('{issue-id}', options.args.issue_id); break; case 'issues/new': - path = scheme['issues/new']; - break; - case 'issues/new-with-title': - path = scheme['issues/new?title'].replace('{title}', options.args.title); + if (options.args && options.args.title) { + path = scheme['issues/new?title'].replace('{title}', encodeURIComponent(options.args.title)); + } else { + path = scheme['issues/new']; + } break; case 'pulls': path = scheme.pulls; diff --git a/test/gitopen.test.js b/test/gitopen.test.js index 0f728bb..4da5985 100644 --- a/test/gitopen.test.js +++ b/test/gitopen.test.js @@ -103,7 +103,7 @@ describe('gitresolve()', function () { it('gitresolve(' + test[0] + ', {issues/new?title})', function () { gitresolve(test[0], { - category: 'issues/new-with-title', + category: 'issues/new', args: {title: 'TEST'}, scheme: { base: '{protocol}://{hostname}/{username}/{reponame}', @@ -231,7 +231,9 @@ describe('$ gitopen', function () { ['wiki', '/hotoo/gitopen/wiki'], ['wikis', '/hotoo/gitopen/wiki'], ['issues', '/hotoo/gitopen/issues'], - ['issue', '/hotoo/gitopen/issues'], + ['issue', '/hotoo/gitopen/issues/new'], + ['issue TITLE', '/hotoo/gitopen/issues/new?title=TITLE'], + ['issue 标题', '/hotoo/gitopen/issues/new?title=%E6%A0%87%E9%A2%98'], ['pr', '/hotoo/gitopen/compare/' + cwb + '?expand=1'], ['pull', '/hotoo/gitopen/compare/' + cwb + '?expand=1'], ['pr compare-branch', '/hotoo/gitopen/compare/compare-branch?expand=1'], From d4603ee4260700cb1fca626696e091c725bb0a3d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=97=B2=E8=80=98=E2=84=A2?= Date: Wed, 22 Jul 2015 07:38:11 +0800 Subject: [PATCH 4/5] feat(milestone): 'gitopen milestone' for open new milestone, and support open milestone by id --- README.md | 19 +++++++++++++------ bin/open-commander.js | 13 ++++++++++++- lib/index.js | 6 ++++++ lib/scheme/bitbucket.js | 4 +++- lib/scheme/coding.js | 2 ++ lib/scheme/gitcafe.js | 4 +++- lib/scheme/github.js | 2 ++ lib/scheme/gitlab.js | 2 ++ lib/scheme/oschina.js | 2 ++ test/gitopen.test.js | 41 ++++++++++++++++++++++++++++++++++++++++- 10 files changed, 85 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index 3e898e5..551d35e 100644 --- a/README.md +++ b/README.md @@ -162,12 +162,9 @@ Open git repository pull request or merge request by id. alias: * `$ gitopen pr1` -* `$ gitopen pr:1` -* `$ gitopen pr/1` -* `$ gitopen pr@1` -* `$ gitopen pr#1` * `$ gitopen mr#1` -* ... + +support `@`, `/`, `#`, `:`, `-` or without sparator. ### $ gitopen commits @@ -198,9 +195,19 @@ alias: Open git repository milestones list page. +### $ gitopen milestones@id + +Open git repository milestones by given id. + alias: -* `$ gitopen milestone` +* `$ gitopen milestone@id` + +support `@`, `/`, `#`, `:`, `-` sparator. + +### $ gitopen milestone + +Open new milestone for git. ### $ gitopen releases diff --git a/bin/open-commander.js b/bin/open-commander.js index fa2efa4..d02b3e7 100644 --- a/bin/open-commander.js +++ b/bin/open-commander.js @@ -25,6 +25,7 @@ module.exports = function(argv) { var RE_ISSUE_ID = /^#\d+$/; var RE_PR_ID = /^(?:!|(?:pr|mr)[\-:\/#@]?)(\d+)$/i; var RE_PROFILE = /^@([a-z0-9-_]+)(?:\/([a-z0-9-_]+)(?:#\d+|:\w+|\/\w+)?)?$/i; + var RE_MILESTONE = /^milestones?[@\/:#\-](.+)$/i; // branch-a:branch-b // branch-a...branch-b var RE_BRANCH_COMPARE = /^(.*?)(?::|\.{3})(.*)$/; @@ -36,7 +37,7 @@ module.exports = function(argv) { case 'issue': options.category = 'issues/new'; options.args = { - title: commander.args[1] + title: commander.args.slice(1).join(' ') }; break; case 'issues': @@ -86,6 +87,11 @@ module.exports = function(argv) { options.category = 'tags'; break; case 'milestone': + options.category = 'milestones/new'; + options.args = { + title: commander.args.slice(1).join(' ') + } + break; case 'milestones': options.category = 'milestones'; break; @@ -155,6 +161,11 @@ module.exports = function(argv) { username: username, reponame: reponame, }; + } else if (m = RE_MILESTONE.exec(category)) { + options.category = 'milestones/id'; + options.args = { + milestone_id: m[1], + }; } else { // FILE/DIR PATH if (fs.existsSync(category)) { diff --git a/lib/index.js b/lib/index.js index 7abe2b7..9b18a3a 100644 --- a/lib/index.js +++ b/lib/index.js @@ -96,6 +96,12 @@ module.exports = function(uri, options) { case 'wiki': path = scheme.wiki; break; + case 'milestones/new': + path = scheme['milestones/new']; + break; + case 'milestones/id': + path = scheme['milestones/id'].replace('{milestone-id}', encodeURIComponent(options.args.milestone_id)); + break; case 'milestones': path = scheme.milestones; break; diff --git a/lib/scheme/bitbucket.js b/lib/scheme/bitbucket.js index 9510301..7b2f03c 100644 --- a/lib/scheme/bitbucket.js +++ b/lib/scheme/bitbucket.js @@ -12,7 +12,9 @@ module.exports = { 'blob': '/src/{hash}', 'commits': '/commits', 'commits-with-branch': '/commits/{branch-name}', - 'milestones': '/milestones', + 'milestones': '/admin/issues/milestones', + 'milestones/new': '/admin/issues/milestones', + 'milestones/id': '/issues?milestone={milestone-id}&status=open&status=new', 'tags': '/tags', 'releases': '/releases', 'releases/new': '/releases/new', diff --git a/lib/scheme/coding.js b/lib/scheme/coding.js index 685b63a..eb9ae18 100644 --- a/lib/scheme/coding.js +++ b/lib/scheme/coding.js @@ -13,6 +13,8 @@ module.exports = { 'commits': '/git/commits', 'commits-with-branch': '/git/commits/{branch-name}', 'milestones': '/milestones', + 'milestones/new': '/milestones/new', + 'milestones/id': '/milestones/{milestone-id}', 'tags': '/git/tags', 'releases': '/git/releases', 'releases/new': '/git/releases/new', diff --git a/lib/scheme/gitcafe.js b/lib/scheme/gitcafe.js index 29ac542..8eb881b 100644 --- a/lib/scheme/gitcafe.js +++ b/lib/scheme/gitcafe.js @@ -12,7 +12,9 @@ module.exports = { 'blob': '/blob/{hash}', 'commits': '/commits/master', 'commits-with-branch': '/commits/{branch-name}', - 'milestones': '/milestones', + 'milestones': '', // NOT SUPPORT. + 'milestones/new': '', // NOT SUPPORT. + 'milestones/id': '', // NOT SUPPORT. 'tags': '/tags', 'releases': '/releases', 'releases/new': '/releases/new', diff --git a/lib/scheme/github.js b/lib/scheme/github.js index 766b743..eee293b 100644 --- a/lib/scheme/github.js +++ b/lib/scheme/github.js @@ -13,6 +13,8 @@ module.exports = { 'commits': '/commits', 'commits-with-branch': '/commits/{branch-name}', 'milestones': '/milestones', + 'milestones/new': '/milestones/new', + 'milestones/id': '/issues?q=milestone%3A{milestone-id}', 'tags': '/tags', 'releases': '/releases', 'releases/new': '/releases/new', diff --git a/lib/scheme/gitlab.js b/lib/scheme/gitlab.js index ef7d8a7..9964eb2 100644 --- a/lib/scheme/gitlab.js +++ b/lib/scheme/gitlab.js @@ -13,6 +13,8 @@ module.exports = { 'commits': '/commits', 'commits-with-branch': '/commits/{branch-name}', 'milestones': '/milestones', + 'milestones/new': '/milestones/new', + 'milestones/id': '/milestones/{milestone-id}', 'tags': '/tags', 'releases': '/releases', 'releases/new': '/releases/new', diff --git a/lib/scheme/oschina.js b/lib/scheme/oschina.js index 531f4aa..21496a1 100644 --- a/lib/scheme/oschina.js +++ b/lib/scheme/oschina.js @@ -13,6 +13,8 @@ module.exports = { 'commits': '/commits/master', 'commits-with-branch': '/commits/{branch-name}', 'milestones': '/milestones', + 'milestones/new': '/milestones/new', + 'milestones/id': '/milestones/{milestone-id}', 'tags': '/tags', 'releases': '/releases', 'releases/new': '/releases/new', diff --git a/test/gitopen.test.js b/test/gitopen.test.js index 4da5985..ab5de73 100644 --- a/test/gitopen.test.js +++ b/test/gitopen.test.js @@ -112,7 +112,38 @@ describe('gitresolve()', function () { }).should.be.eql('https://' + test[1] + '/issues/new?title=TEST'); }); - it('gitresolve(' + test[0] + ', {issues/new?title})', function () { + it('gitresolve(' + test[0] + ', {milestones})', function () { + gitresolve(test[0], { + category: 'milestones', + scheme: { + base: '{protocol}://{hostname}/{username}/{reponame}', + milestones: '/milestones', + } + }).should.be.eql('https://' + test[1] + '/milestones'); + }); + + it('gitresolve(' + test[0] + ', {milestones/id})', function () { + gitresolve(test[0], { + category: 'milestones/id', + args: {'milestone_id': '1'}, + scheme: { + base: '{protocol}://{hostname}/{username}/{reponame}', + 'milestones/id': '/milestones/{milestone-id}', + } + }).should.be.eql('https://' + test[1] + '/milestones/1'); + }); + + it('gitresolve(' + test[0] + ', {milestones/new})', function () { + gitresolve(test[0], { + category: 'milestones/new', + scheme: { + base: '{protocol}://{hostname}/{username}/{reponame}', + 'milestones/new': '/milestones/new', + } + }).should.be.eql('https://' + test[1] + '/milestones/new'); + }); + + it('gitresolve(' + test[0] + ', {pulls})', function () { gitresolve(test[0], { category: 'pulls', scheme: { @@ -234,6 +265,14 @@ describe('$ gitopen', function () { ['issue', '/hotoo/gitopen/issues/new'], ['issue TITLE', '/hotoo/gitopen/issues/new?title=TITLE'], ['issue 标题', '/hotoo/gitopen/issues/new?title=%E6%A0%87%E9%A2%98'], + ['issue TITLE 标题', '/hotoo/gitopen/issues/new?title=TITLE%20%E6%A0%87%E9%A2%98'], + ['milestones', '/hotoo/gitopen/milestones'], + ['milestone', '/hotoo/gitopen/milestones/new'], + ['milestone@2.0.0', '/hotoo/gitopen/issues?q=milestone%3A2.0.0'], + ['milestone/2.0.0', '/hotoo/gitopen/issues?q=milestone%3A2.0.0'], + ['milestone-2.0.0', '/hotoo/gitopen/issues?q=milestone%3A2.0.0'], + ['milestone#2.0.0', '/hotoo/gitopen/issues?q=milestone%3A2.0.0'], + ['milestone#里程碑', '/hotoo/gitopen/issues?q=milestone%3A%E9%87%8C%E7%A8%8B%E7%A2%91'], ['pr', '/hotoo/gitopen/compare/' + cwb + '?expand=1'], ['pull', '/hotoo/gitopen/compare/' + cwb + '?expand=1'], ['pr compare-branch', '/hotoo/gitopen/compare/compare-branch?expand=1'], From b1622d77f81c5f5addaaeb6c64043fca43956be1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=97=B2=E8=80=98=E2=84=A2?= Date: Wed, 22 Jul 2015 07:44:54 +0800 Subject: [PATCH 5/5] doc(hgopen,svnopen): Add hgopen and svnopen documents --- README.md | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 551d35e..68ec62a 100644 --- a/README.md +++ b/README.md @@ -114,7 +114,7 @@ Then you can use command like: $ git open ``` -## Commands +## gitopen Commands ### $ gitopen @@ -231,11 +231,26 @@ Open network page. ### $ gitopen @profile -Open profile page on GitHub. +[GLOBAL COMMAND] Open profile page on GitHub. ### $ gitopen @profile/repository-name -Open given repository homepage on GitHub. +[GLOBAL COMMAND] Open given repository homepage on GitHub. + +## hgopen Commands + +Support all of gitopen in repository local commands (not support global commands), like: + +* `$ hgopen` open homepage. +* `$ hgopen issues` open issues list page. +* `$ hgopen #id` op issues by id. +* ... + +## svnopen Commands + +### $ svnopen + +Open svn repository on current working directory. ## License