Skip to content

Commit

Permalink
Merge pull request #18 from hotoo/mr2
Browse files Browse the repository at this point in the history
Mr2
  • Loading branch information
hotoo committed Jul 21, 2015
2 parents 1d562bc + b1622d7 commit c06a904
Show file tree
Hide file tree
Showing 10 changed files with 238 additions and 30 deletions.
149 changes: 140 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -121,6 +114,144 @@ Then you can use command like:
$ git open
```

## gitopen Commands

### $ gitopen

Open git repository homepage.

### $ gitopen issues

Open git repository issues list page.

### $ gitopen issue [title]

Open new issue with title (optional).

### $ 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 mr#1`

support `@`, `/`, `#`, `:`, `-` or without sparator.

### $ 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.

### $ gitopen milestones@id

Open git repository milestones by given id.

alias:

* `$ gitopen milestone@id`

support `@`, `/`, `#`, `:`, `-` sparator.

### $ gitopen milestone

Open new milestone for git.

### $ 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 <tag-name>

Edit release by tag name.

### $ gitopen network

Open network page.

### $ gitopen @profile

[GLOBAL COMMAND] Open profile page on GitHub.

### $ gitopen @profile/repository-name

[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

[MIT](http://hotoo.mit-license.org/)
31 changes: 19 additions & 12 deletions bin/open-commander.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,9 @@ 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;
var RE_MILESTONE = /^milestones?[@\/:#\-](.+)$/i;
// branch-a:branch-b
// branch-a...branch-b
var RE_BRANCH_COMPARE = /^(.*?)(?::|\.{3})(.*)$/;
Expand All @@ -34,17 +35,13 @@ module.exports = function(argv) {

switch(category){
case 'issue':
options.category = 'issues/new';
options.args = {
title: commander.args.slice(1).join(' ')
};
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':
Expand Down Expand Up @@ -90,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;
Expand Down Expand Up @@ -146,10 +148,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];
Expand All @@ -159,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)) {
Expand Down
15 changes: 11 additions & 4 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -95,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;
Expand Down
4 changes: 3 additions & 1 deletion lib/scheme/bitbucket.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
2 changes: 2 additions & 0 deletions lib/scheme/coding.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
4 changes: 3 additions & 1 deletion lib/scheme/gitcafe.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
2 changes: 2 additions & 0 deletions lib/scheme/github.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
2 changes: 2 additions & 0 deletions lib/scheme/gitlab.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
2 changes: 2 additions & 0 deletions lib/scheme/oschina.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
Loading

0 comments on commit c06a904

Please sign in to comment.