diff --git a/.eslintrc b/.eslintrc new file mode 100644 index 0000000..92e1562 --- /dev/null +++ b/.eslintrc @@ -0,0 +1,196 @@ +{ + "ecmaFeatures": { + "jsx": true + }, + "parser": "espree", + "env": { + "amd": false, + "jasmine": false, + "node": true, + "mocha": true, + "browser": true, + "builtin": true, + "es6": true + }, + "rules": { + "no-alert": 2, + "no-array-constructor": 2, + "no-bitwise": 2, + "no-caller": 2, + "no-catch-shadow": 2, + "no-cond-assign": [2, "except-parens"], + "no-constant-condition": 2, + "no-continue": 0, + "no-control-regex": 2, + "no-debugger": 2, + "no-delete-var": 2, + "no-div-regex": 0, + "no-dupe-keys": 2, + "no-dupe-args": 2, + "no-duplicate-case": 2, + "no-else-return": 0, + "no-empty": 2, + "no-empty-character-class": 2, + "no-empty-label": 2, + "no-eq-null": 0, + "no-eval": 2, + "no-ex-assign": 2, + "no-extend-native": 2, + "no-extra-bind": 2, + "no-extra-boolean-cast": 2, + "no-extra-parens": 0, + "no-extra-semi": 2, + "no-fallthrough": 2, + "no-floating-decimal": 0, + "no-func-assign": 2, + "no-implied-eval": 2, + "no-inline-comments": 0, + "no-inner-declarations": [2, "functions"], + "no-invalid-regexp": 2, + "no-irregular-whitespace": 2, + "no-iterator": 0, + "no-label-var": 2, + "no-labels": 2, + "no-lone-blocks": 2, + "no-lonely-if": 0, + "no-loop-func": 2, + "no-mixed-requires": [0, false], + "no-mixed-spaces-and-tabs": [2, false], + "linebreak-style": [0, "unix"], + "no-multi-spaces": 2, + "no-multi-str": 2, + "no-multiple-empty-lines": [0, { + "max": 2 + }], + "no-native-reassign": 2, + "no-negated-in-lhs": 2, + "no-nested-ternary": 0, + "no-new": 0, + "no-new-func": 2, + "no-new-object": 2, + "no-new-require": 0, + "no-new-wrappers": 2, + "no-obj-calls": 2, + "no-octal": 2, + "no-octal-escape": 2, + "no-param-reassign": 0, + "no-path-concat": 0, + "no-plusplus": 0, + "no-process-env": 0, + "no-process-exit": 0, + "no-proto": 2, + "no-redeclare": 2, + "no-regex-spaces": 2, + "no-restricted-modules": 0, + "no-return-assign": 0, + "no-script-url": 2, + "no-self-compare": 0, + "no-sequences": 2, + "no-shadow": 0, + "no-shadow-restricted-names": 2, + "no-spaced-func": 2, + "no-sparse-arrays": 2, + "no-sync": 0, + "no-ternary": 0, + "no-trailing-spaces": 2, + "no-this-before-super": 0, + "no-throw-literal": 0, + "no-undef": 2, + "no-undef-init": 2, + "no-undefined": 0, + "no-unexpected-multiline": 0, + "no-underscore-dangle": 0, + "no-unneeded-ternary": 0, + "no-unreachable": 2, + "no-unused-expressions": 0, + "no-unused-vars": 2, + "no-use-before-define": [2, "nofunc"], + "no-void": 0, + "no-var": 0, + "no-const-assign": 2, + "prefer-const": 0, + "no-warning-comments": [0, { + "terms": ["todo", "fixme", "xxx"], + "location": "start" + }], + "no-with": 2, + "array-bracket-spacing": [0, "never"], + "accessor-pairs": 0, + "block-scoped-var": 0, + "brace-style": [0, "1tbs"], + "camelcase": 0, + "comma-dangle": [2, "always-multiline"], + "comma-spacing": 2, + "comma-style": 0, + "complexity": [0, 11], + "computed-property-spacing": [0, "never"], + "consistent-return": 2, + "consistent-this": [0, "that"], + "constructor-super": 0, + "curly": [2, "multi-line"], + "default-case": 0, + "dot-location": 0, + "dot-notation": 0, + "eol-last": 2, + "eqeqeq": 2, + "func-names": 0, + "func-style": [0, "declaration"], + "generator-star-spacing": 0, + "guard-for-in": 0, + "handle-callback-err": 0, + "indent": [2, 2], + "key-spacing": [2, { + "beforeColon": false, + "afterColon": true + }], + "lines-around-comment": 0, + "max-depth": [0, 4], + "max-len": [0, 80, 4], + "max-nested-callbacks": [0, 2], + "max-params": [0, 3], + "max-statements": [0, 10], + "new-cap": 0, + "new-parens": 2, + "newline-after-var": 0, + "object-curly-spacing": [0, "never"], + "object-shorthand": 0, + "one-var": 0, + "operator-assignment": [0, "always"], + "operator-linebreak": 0, + "padded-blocks": 0, + "quote-props": 0, + "quotes": [2, "single"], + "radix": 0, + "semi": 2, + "semi-spacing": [2, { + "before": false, + "after": true + }], + "sort-vars": 0, + "space-after-keywords": [2, "always"], + "space-before-blocks": [2, "always"], + "space-before-function-paren": [2, "never"], + "space-before-keywords": [2, "always"], + "space-in-parens": [2, "never"], + "space-infix-ops": 2, + "space-return-throw-case": 2, + "space-unary-ops": [2, { + "words": true, + "nonwords": false + }], + "spaced-comment": [2, "always"], + "strict": [2, "global"], + "use-isnan": 2, + "valid-jsdoc": [2, { + "prefer": { + "returns": "return" + } + }], + "valid-typeof": 0, + "vars-on-top": 0, + "wrap-iife": 0, + "wrap-regex": 0, + "yoda": [2, "never"], + "eol-last": 2 + } +} diff --git a/.travis.yml b/.travis.yml index dedfe56..8a293bb 100644 --- a/.travis.yml +++ b/.travis.yml @@ -10,5 +10,6 @@ node_js: - "3" - "4" - "5" + - "6" after_success: - cat ./coverage/lcov.info | ./node_modules/.bin/coveralls diff --git a/Makefile b/Makefile index ad2f932..7c9a5a0 100644 --- a/Makefile +++ b/Makefile @@ -9,7 +9,10 @@ MOCHA_OPTS = install: @npm install -test: +lint: + @./node_modules/.bin/eslint bin lib test + +test: lint @if [ ! -d $(HG_SSH_DIR) ]; then \ mkdir -p $(HG_SSH_DIR); \ cd $(HG_SSH_DIR); \ diff --git a/bin/gitopen b/bin/gitopen index aab638f..94f7d5f 100755 --- a/bin/gitopen +++ b/bin/gitopen @@ -1,4 +1,5 @@ #!/usr/bin/env node +'use strict'; var xopen = require('../lib/xopen'); var getConfig = require('./openrc'); @@ -18,11 +19,12 @@ commander(process.argv, { root: gitroot, }, function(command) { + var url; // 4. if @profile then open @profile if (command.category === 'profile') { var username = command.args.username; var reponame = command.args.reponame; - var url = 'https://github.com/' + username + (reponame ? '/' + reponame : ''); + url = 'https://github.com/' + username + (reponame ? '/' + reponame : ''); if (command.verbose) { console.log('URL:', url); process.exit(0); @@ -37,7 +39,7 @@ commander(process.argv, { var uri; try { uri = gitremote.getRemoteUrl({cwd: process.cwd()}); - } catch(ex) { + } catch (ex) { if (command.category === 'snippets/new') { uri = 'https://github.com/hotoo/gitopen'; } else { @@ -51,7 +53,7 @@ commander(process.argv, { command.scheme = config.scheme; command.protocol = config.protocol; // 6. resolve paths. - var url = gitresolve(uri, command); + url = gitresolve(uri, command); // 7. open if (command.verbose) { console.log('Option:', command); diff --git a/bin/hgopen b/bin/hgopen index 89d9c4a..2b904c1 100755 --- a/bin/hgopen +++ b/bin/hgopen @@ -1,4 +1,5 @@ #!/usr/bin/env node +'use strict'; var xopen = require('../lib/xopen'); var getConfig = require('./openrc'); @@ -17,14 +18,15 @@ commander(process.argv, { cwb: cwb, root: hgroot, }, function(command) { + var url; // 4. if @profile then open @profile if (command.category === 'profile') { var username = command.args.username; var reponame = command.args.reponame; - var url = 'https://github.com/' + username + (reponame? '/'+reponame : ''); + url = 'https://github.com/' + username + (reponame ? '/' + reponame : ''); if (command.verbose) { - console.log("URL:", url); + console.log('URL:', url); process.exit(0); return 0; } @@ -34,17 +36,17 @@ commander(process.argv, { } // 5. git/hg/svn remote url. - var uri = hgremote.getRemoteUrl({cwd:process.cwd()}); + var uri = hgremote.getRemoteUrl({cwd: process.cwd()}); // 6. get openrc var config = getConfig(uri); command.scheme = config.scheme; command.protocol = config.protocol; // 6. resolve paths. - var url = gitresolve(uri, command); + 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 3b2dd1b..92bd64a 100644 --- a/bin/open-commander.js +++ b/bin/open-commander.js @@ -1,3 +1,5 @@ +'use strict'; + /* global module, process */ var fs = require('fs'); var path = require('path'); @@ -17,7 +19,7 @@ module.exports = function(argv, option, callback) { function parseFilePath(options, cpath) { try { - var stat = fs.statSync(cpath); //throw error when cpath is not accessable. + var stat = fs.statSync(cpath); // throw error when cpath is not accessable. var filepath = resolve(cpath, option.cwd, option.root); if (stat.isFile()) { @@ -83,7 +85,7 @@ module.exports = function(argv, option, callback) { var options = { category: 'home', - cwd: path.dirname(commander.path) || option.cwd || process.cwd(), + cwd: commander.path ? path.dirname(commander.path) : option.cwd || process.cwd(), hash: commander.branch || option.cwb || 'master', remote: commander.remote || 'origin', protocol: 'https', @@ -113,11 +115,11 @@ module.exports = function(argv, option, callback) { var category = commander.args[0]; var match; - switch(category){ + switch (category) { case 'issue': options.category = 'issues/new'; options.args = { - title: commander.args.slice(1).join(' ') + title: commander.args.slice(1).join(' '), }; break; case 'issues': @@ -200,7 +202,7 @@ module.exports = function(argv, option, callback) { case 'milestone': options.category = 'milestones/new'; options.args = { - title: commander.args.slice(1).join(' ') + title: commander.args.slice(1).join(' '), }; break; case 'milestones': @@ -229,11 +231,11 @@ module.exports = function(argv, option, callback) { break; case 'ci': case 'commit': - //options.category = 'commit'; - //if (commander.args[2] && commander.args[2] !== '.') { - //options.hash = commander.args[2]; - //} - //break; + // options.category = 'commit'; + // if (commander.args[2] && commander.args[2] !== '.') { + // options.hash = commander.args[2]; + // } + // break; case 'commits': options.category = 'commits'; if (commander.branch) { @@ -301,7 +303,6 @@ module.exports = function(argv, option, callback) { if (!parseFilePath(options, category)) { console.error('Unknow category or path: ' + category); process.exit(1); - return 1; } } } @@ -309,8 +310,7 @@ module.exports = function(argv, option, callback) { if (commander.path && !parseFilePath(options, commander.path)) { console.error('Unknow path: ' + commander.path); process.exit(1); - return 1; } - return callback(options); + callback(options); }; diff --git a/bin/openrc.js b/bin/openrc.js index 24da687..9573d08 100644 --- a/bin/openrc.js +++ b/bin/openrc.js @@ -1,3 +1,4 @@ +'use strict'; /* global process, module */ var fs = require('fs'); @@ -29,7 +30,7 @@ function openrc(uri) { if (fs.existsSync(gitopenrc)) { try { config = yaml.safeLoad(fs.readFileSync(gitopenrc, 'utf8')); - Object.keys(config).some(function(hostname){ + Object.keys(config).some(function(hostname) { if (HOSTNAME === hostname) { result.protocol = config[hostname].protocol || 'https'; result.type = config[hostname].type; diff --git a/bin/svnopen b/bin/svnopen index 0788715..22426bf 100755 --- a/bin/svnopen +++ b/bin/svnopen @@ -1,4 +1,5 @@ #!/usr/bin/env node +'use strict'; var commander = require('commander'); var child_process = require('child_process'); diff --git a/lib/gitremote.js b/lib/gitremote.js index d3ff315..6c10197 100644 --- a/lib/gitremote.js +++ b/lib/gitremote.js @@ -1,3 +1,4 @@ +'use strict'; /* global exports, process */ var child_process = require('child_process'); diff --git a/lib/hgremote.js b/lib/hgremote.js index 4c648d3..1c52b20 100644 --- a/lib/hgremote.js +++ b/lib/hgremote.js @@ -1,3 +1,4 @@ +'use strict'; /* global exports, process */ var child_process = require('child_process'); diff --git a/lib/index.js b/lib/index.js index c868e4e..c014c30 100644 --- a/lib/index.js +++ b/lib/index.js @@ -1,3 +1,4 @@ +'use strict'; /* global module */ var merge = require('deepmerge'); @@ -7,8 +8,8 @@ var DEFAULT_OPTIONS = { protocol: 'https', remote: 'origin', scheme: { - base: '{protocol}://{hostname}/{username}/{reponame}' - } + base: '{protocol}://{hostname}/{username}/{reponame}', + }, }; var RE_URL = /^https?:\/\//i; @@ -65,113 +66,113 @@ module.exports = function(uri, options) { var path = ''; switch (options.category) { - case 'issues': - path = scheme.issues; - break; - case 'issues/id': - path = scheme['issues/id'] - .replace('{issue-id}', options.args.issue_id); - break; - case 'issues/new': - if (options.args && options.args.title) { - path = scheme['issues/new?title'].replace('{title}', encodeURIComponent(options.args.title)); - } else { - path = scheme['issues/new']; - } - break; - case 'mrs': - case 'prs': - case 'pulls': - path = scheme.pulls; - break; - case 'pulls/new': - if (options.args) { - if (options.args['branch-A']) { - path = scheme['pulls/new-with-base-branch'] - .replace('{branch-A}', options.args['branch-A']) - .replace('{branch-B}', options.args['branch-B']); - } else if (options.args['branch-B']) { - path = scheme['pulls/new-with-compare-branch'] - .replace('{branch-A}', options.args['branch-A']) - .replace('{branch-B}', options.args['branch-B']); - } - } else { - path = scheme['pulls/new']; - } - break; - case 'pulls/id': - path = scheme['pulls/id'] - .replace('{pull-id}', options.args.pull_id); - break; - 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; - case 'tags': - path = scheme.tags; - break; - case 'releases': - path = scheme.releases; - break; - case 'releases/new': - path = scheme['releases/new']; - break; - case 'releases/new-with-tag': - path = scheme['releases/new-with-tag'] - .replace('{tag}', options.args.tag); - break; - case 'releases/edit/tag-id': - path = scheme['releases/edit/tag-id'] - .replace('{tag}', options.args.tag); - break; - case 'network': - path = scheme.network; - break; - case 'commit': - path = scheme['commit'] - .replace('{hash}', options.hash); - break; - case 'commits': - path = scheme.commits; - break; - case 'commits-with-branch': - path = scheme['commits-with-branch'] - .replace('{branch-name}', options.branch); - break; - case 'tree': - path = scheme.tree.replace('{hash}', options.hash) - .replace('{path}', options.args.path); - break; - case 'blob': - path = scheme.blob.replace('{hash}', options.hash) - .replace('{path}', options.args.path); - break; - case 'home': - path = scheme.home; - break; - case 'snippets/new': - var snippets_uri = parse(uri, options); - path = scheme['snippets/new'].replace('{protocol}', snippets_uri.protocol || options.protocol || 'https') - .replace('{hostname}', snippets_uri.hostname); - break; - default: - path = ''; - if (options.hash !== 'master') { - path = scheme.tree.replace('{hash}', options.hash); + case 'issues': + path = scheme.issues; + break; + case 'issues/id': + path = scheme['issues/id'] + .replace('{issue-id}', options.args.issue_id); + break; + case 'issues/new': + if (options.args && options.args.title) { + path = scheme['issues/new?title'].replace('{title}', encodeURIComponent(options.args.title)); + } else { + path = scheme['issues/new']; + } + break; + case 'mrs': + case 'prs': + case 'pulls': + path = scheme.pulls; + break; + case 'pulls/new': + if (options.args) { + if (options.args['branch-A']) { + path = scheme['pulls/new-with-base-branch'] + .replace('{branch-A}', options.args['branch-A']) + .replace('{branch-B}', options.args['branch-B']); + } else if (options.args['branch-B']) { + path = scheme['pulls/new-with-compare-branch'] + .replace('{branch-A}', options.args['branch-A']) + .replace('{branch-B}', options.args['branch-B']); } - break; + } else { + path = scheme['pulls/new']; + } + break; + case 'pulls/id': + path = scheme['pulls/id'] + .replace('{pull-id}', options.args.pull_id); + break; + 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; + case 'tags': + path = scheme.tags; + break; + case 'releases': + path = scheme.releases; + break; + case 'releases/new': + path = scheme['releases/new']; + break; + case 'releases/new-with-tag': + path = scheme['releases/new-with-tag'] + .replace('{tag}', options.args.tag); + break; + case 'releases/edit/tag-id': + path = scheme['releases/edit/tag-id'] + .replace('{tag}', options.args.tag); + break; + case 'network': + path = scheme.network; + break; + case 'commit': + path = scheme['commit'] + .replace('{hash}', options.hash); + break; + case 'commits': + path = scheme.commits; + break; + case 'commits-with-branch': + path = scheme['commits-with-branch'] + .replace('{branch-name}', options.branch); + break; + case 'tree': + path = scheme.tree.replace('{hash}', options.hash) + .replace('{path}', options.args.path); + break; + case 'blob': + path = scheme.blob.replace('{hash}', options.hash) + .replace('{path}', options.args.path); + break; + case 'home': + path = scheme.home; + break; + case 'snippets/new': + var snippets_uri = parse(uri, options); + path = scheme['snippets/new'].replace('{protocol}', snippets_uri.protocol || options.protocol || 'https') + .replace('{hostname}', snippets_uri.hostname); + break; + default: + path = ''; + if (options.hash !== 'master') { + path = scheme.tree.replace('{hash}', options.hash); + } + break; } - //if (options.path) { - //path += options.path; - //} + // if (options.path) { + // path += options.path; + // } return RE_URL.test(path) ? path : url + path; }; diff --git a/lib/scheme/bitbucket.js b/lib/scheme/bitbucket.js index 3e0a458..07fe8fe 100644 --- a/lib/scheme/bitbucket.js +++ b/lib/scheme/bitbucket.js @@ -1,3 +1,4 @@ +'use strict'; module.exports = { 'base': '{protocol}://{hostname}/{username}/{reponame}', 'home': '', diff --git a/lib/scheme/coding.js b/lib/scheme/coding.js index a09a231..3c0e9cc 100644 --- a/lib/scheme/coding.js +++ b/lib/scheme/coding.js @@ -1,3 +1,4 @@ +'use strict'; module.exports = { 'base': '{protocol}://{hostname}/u/{username}/p/{reponame}', 'home': '/git', diff --git a/lib/scheme/gitcafe.js b/lib/scheme/gitcafe.js index 78d4829..01399de 100644 --- a/lib/scheme/gitcafe.js +++ b/lib/scheme/gitcafe.js @@ -1,3 +1,4 @@ +'use strict'; module.exports = { 'base': '{protocol}://{hostname}/{username}/{reponame}', 'home': '', diff --git a/lib/scheme/github.js b/lib/scheme/github.js index 9257e05..d7e922f 100644 --- a/lib/scheme/github.js +++ b/lib/scheme/github.js @@ -1,3 +1,4 @@ +'use strict'; module.exports = { 'base': '{protocol}://{hostname}/{username}/{reponame}', 'home': '', diff --git a/lib/scheme/gitlab.js b/lib/scheme/gitlab.js index b070bfe..e92862c 100644 --- a/lib/scheme/gitlab.js +++ b/lib/scheme/gitlab.js @@ -1,3 +1,4 @@ +'use strict'; module.exports = { 'base': '{protocol}://{hostname}/{username}/{reponame}', 'home': '', diff --git a/lib/scheme/oschina.js b/lib/scheme/oschina.js index 7897312..8a106e1 100644 --- a/lib/scheme/oschina.js +++ b/lib/scheme/oschina.js @@ -1,3 +1,4 @@ +'use strict'; module.exports = { 'base': '{protocol}://{hostname}/{username}/{reponame}', 'home': '', diff --git a/lib/xopen.js b/lib/xopen.js index 9ac5a84..8f77b80 100644 --- a/lib/xopen.js +++ b/lib/xopen.js @@ -1,3 +1,4 @@ +'use strict'; /* global module, process */ var child_process = require('child_process'); @@ -19,7 +20,7 @@ module.exports = function open(url, options) { console.log('URL:', url); } - switch(process.platform){ + switch (process.platform) { case 'win32': case 'win64': shell = 'start'; @@ -34,4 +35,4 @@ module.exports = function open(url, options) { } child_process.execSync(shell + ' ' + escapeCommand(url)); -} +}; diff --git a/package.json b/package.json index 11e3e14..a8ad2dd 100644 --- a/package.json +++ b/package.json @@ -37,6 +37,7 @@ }, "devDependencies": { "coveralls": "^2.11.3", + "eslint": "^1.10.3", "istanbul": "^0.3.17", "mocha": "^2.2.5", "should": "^7.0.1" diff --git a/test/gitopen.test.js b/test/gitopen.test.js index 55f27ec..69c8d26 100644 --- a/test/gitopen.test.js +++ b/test/gitopen.test.js @@ -1,3 +1,4 @@ +'use strict'; var gitresolve = require('../'); var gitremote = require('../lib/gitremote'); @@ -7,7 +8,7 @@ var should = require('should'); var cwb = gitremote.getCurrentBranch(); var RE_URL = /^https?:\/\//i; -describe('gitresolve.parse()', function () { +describe('gitresolve.parse()', function() { var cases = [ ['git@github.com:hotoo/gitopen.git', {hostname: 'github.com', username: 'hotoo', reponame: 'gitopen'}], ['git://github.com/hotoo/gitopen.git', {hostname: 'github.com', username: 'hotoo', reponame: 'gitopen'}], @@ -16,14 +17,14 @@ describe('gitresolve.parse()', function () { ['https://github.com/hotoo/gitopen.git', {hostname: 'github.com', username: 'hotoo', reponame: 'gitopen'}], ['https://hotoo@bitbucket.org/hotoo/gitopen.git', {hostname: 'bitbucket.org', username: 'hotoo', reponame: 'gitopen'}], ]; - cases.forEach(function(test){ - it('gitresolve.parse(' + test[0] + ')', function () { + cases.forEach(function(test) { + it('gitresolve.parse(' + test[0] + ')', function() { gitresolve.parse(test[0]).should.be.eql(test[1]); }); }); }); -describe('gitresolve.resolve()', function () { +describe('gitresolve.resolve()', function() { var cases = [ ['git@github.com:hotoo/gitopen.git', 'github.com/hotoo/gitopen'], ['git://github.com/hotoo/gitopen.git', 'github.com/hotoo/gitopen'], @@ -32,23 +33,23 @@ describe('gitresolve.resolve()', function () { ['https://github.com/hotoo/gitopen.git', 'github.com/hotoo/gitopen'], ['https://hotoo@bitbucket.org/hotoo/gitopen.git', 'bitbucket.org/hotoo/gitopen'], ]; - cases.forEach(function(test){ - it('gitresolve.resolve(' + test[0] + ',{base})', function () { + cases.forEach(function(test) { + it('gitresolve.resolve(' + test[0] + ',{base})', function() { gitresolve.resolve(test[0], { - scheme: {base: '{protocol}://{hostname}/{username}/{reponame}'} + scheme: {base: '{protocol}://{hostname}/{username}/{reponame}'}, }).should.be.eql('https://' + test[1]); }); - it('gitresolve.resolve(' + test[0] + ',{base,protocol})', function () { + it('gitresolve.resolve(' + test[0] + ',{base,protocol})', function() { gitresolve.resolve(test[0], { protocol: 'http', - scheme: {base: '{protocol}://{hostname}/{username}/{reponame}'} + scheme: {base: '{protocol}://{hostname}/{username}/{reponame}'}, }).should.be.eql('http://' + test[1]); }); }); }); -describe('gitresolve()', function () { +describe('gitresolve()', function() { var cases = [ ['git@github.com:hotoo/gitopen.git', 'github.com/hotoo/gitopen'], ['git://github.com/hotoo/gitopen.git', 'github.com/hotoo/gitopen'], @@ -57,214 +58,214 @@ describe('gitresolve()', function () { ['https://github.com/hotoo/gitopen.git', 'github.com/hotoo/gitopen'], ['https://hotoo@bitbucket.org/hotoo/gitopen.git', 'bitbucket.org/hotoo/gitopen'], ]; - cases.forEach(function(test){ - it('gitresolve(' + test[0] + ')', function () { + cases.forEach(function(test) { + it('gitresolve(' + test[0] + ')', function() { gitresolve(test[0], { - scheme: {base: '{protocol}://{hostname}/{username}/{reponame}'} + scheme: {base: '{protocol}://{hostname}/{username}/{reponame}'}, }).should.be.eql('https://' + test[1]); }); - it('gitresolve.resolve(' + test[0] + ',{base,protocol})', function () { + it('gitresolve.resolve(' + test[0] + ',{base,protocol})', function() { gitresolve(test[0], { protocol: 'http', - scheme: {base: '{protocol}://{hostname}/{username}/{reponame}/something'} + scheme: {base: '{protocol}://{hostname}/{username}/{reponame}/something'}, }).should.be.eql('http://' + test[1] + '/something'); }); - it('gitresolve(' + test[0] + ', {issues})', function () { + it('gitresolve(' + test[0] + ', {issues})', function() { gitresolve(test[0], { category: 'issues', scheme: { base: '{protocol}://{hostname}/{username}/{reponame}', issues: '/issues', - } + }, }).should.be.eql('https://' + test[1] + '/issues'); }); - it('gitresolve(' + test[0] + ', {issues/id})', function () { + it('gitresolve(' + test[0] + ', {issues/id})', function() { gitresolve(test[0], { category: 'issues/id', args: {'issue_id': '1'}, scheme: { base: '{protocol}://{hostname}/{username}/{reponame}', 'issues/id': '/issues/{issue-id}', - } + }, }).should.be.eql('https://' + test[1] + '/issues/1'); }); - it('gitresolve(' + test[0] + ', {issues/new})', function () { + it('gitresolve(' + test[0] + ', {issues/new})', function() { gitresolve(test[0], { category: 'issues/new', scheme: { base: '{protocol}://{hostname}/{username}/{reponame}', 'issues/new': '/issues/new', - } + }, }).should.be.eql('https://' + test[1] + '/issues/new'); }); - it('gitresolve(' + test[0] + ', {issues/new?title})', function () { + it('gitresolve(' + test[0] + ', {issues/new?title})', function() { gitresolve(test[0], { category: 'issues/new', args: {title: 'TEST'}, scheme: { base: '{protocol}://{hostname}/{username}/{reponame}', 'issues/new?title': '/issues/new?title={title}', - } + }, }).should.be.eql('https://' + test[1] + '/issues/new?title=TEST'); }); - it('gitresolve(' + test[0] + ', {milestones})', 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 () { + 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 () { + 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 () { + it('gitresolve(' + test[0] + ', {pulls})', function() { gitresolve(test[0], { category: 'pulls', scheme: { base: '{protocol}://{hostname}/{username}/{reponame}', pulls: '/pulls', - } + }, }).should.be.eql('https://' + test[1] + '/pulls'); }); - it('gitresolve(' + test[0] + ', {pulls/id})', function () { + it('gitresolve(' + test[0] + ', {pulls/id})', function() { gitresolve(test[0], { category: 'pulls/id', args: {'pull_id': '1'}, scheme: { base: '{protocol}://{hostname}/{username}/{reponame}', 'pulls/id': '/pulls/{pull-id}', - } + }, }).should.be.eql('https://' + test[1] + '/pulls/1'); }); - it('gitresolve(' + test[0] + ', {pulls/new})', function () { + it('gitresolve(' + test[0] + ', {pulls/new})', function() { gitresolve(test[0], { category: 'pulls/new', scheme: { base: '{protocol}://{hostname}/{username}/{reponame}', 'pulls/new': '/compare', - } + }, }).should.be.eql('https://' + test[1] + '/compare'); }); - it('gitresolve(' + test[0] + ', {pulls/new})', function () { + it('gitresolve(' + test[0] + ', {pulls/new})', function() { gitresolve(test[0], { category: 'pulls/new', args: { 'branch-A': '123', - 'branch-B': '456' + 'branch-B': '456', }, scheme: { base: '{protocol}://{hostname}/{username}/{reponame}', 'pulls/new-with-base-branch': '/compare/{branch-A}...{branch-B}', - } + }, }).should.be.eql('https://' + test[1] + '/compare/123...456'); }); - it('gitresolve(' + test[0] + ', {pulls/new/branchName})', function () { + it('gitresolve(' + test[0] + ', {pulls/new/branchName})', function() { gitresolve(test[0], { category: 'pulls/new', args: { - 'branch-B': '456' + 'branch-B': '456', }, scheme: { base: '{protocol}://{hostname}/{username}/{reponame}', 'pulls/new-with-compare-branch': '/compare/{branch-B}?expand=1', - } + }, }).should.be.eql('https://' + test[1] + '/compare/456?expand=1'); }); - it('gitresolve(' + test[0] + ', {wiki})', function () { + it('gitresolve(' + test[0] + ', {wiki})', function() { gitresolve(test[0], { category: 'wiki', scheme: { base: '{protocol}://{hostname}/{username}/{reponame}', wiki: '/wiki', - } + }, }).should.be.eql('https://' + test[1] + '/wiki'); }); - it('gitresolve(' + test[0] + ', {tags})', function () { + it('gitresolve(' + test[0] + ', {tags})', function() { gitresolve(test[0], { category: 'tags', scheme: { base: '{protocol}://{hostname}/{username}/{reponame}', tags: '/tags', - } + }, }).should.be.eql('https://' + test[1] + '/tags'); }); - it('gitresolve(' + test[0] + ', {releases})', function () { + it('gitresolve(' + test[0] + ', {releases})', function() { gitresolve(test[0], { category: 'releases', scheme: { base: '{protocol}://{hostname}/{username}/{reponame}', releases: '/releases', - } + }, }).should.be.eql('https://' + test[1] + '/releases'); }); - it('gitresolve(' + test[0] + ', {releases/new})', function () { + it('gitresolve(' + test[0] + ', {releases/new})', function() { gitresolve(test[0], { category: 'releases/new', scheme: { base: '{protocol}://{hostname}/{username}/{reponame}', 'releases/new': '/releases/new', - } + }, }).should.be.eql('https://' + test[1] + '/releases/new'); }); - it('gitresolve(' + test[0] + ', {releases/new-with-tag})', function () { + it('gitresolve(' + test[0] + ', {releases/new-with-tag})', function() { gitresolve(test[0], { category: 'releases/new-with-tag', scheme: { base: '{protocol}://{hostname}/{username}/{reponame}', 'releases/new-with-tag': '/releases/new?tag={tag}', }, - args: {tag: '2.0.0'} + args: {tag: '2.0.0'}, }).should.be.eql('https://' + test[1] + '/releases/new?tag=2.0.0'); }); - it('gitresolve(' + test[0] + ', {releases/edit/tag-id})', function () { + it('gitresolve(' + test[0] + ', {releases/edit/tag-id})', function() { gitresolve(test[0], { category: 'releases/edit/tag-id', scheme: { base: '{protocol}://{hostname}/{username}/{reponame}', 'releases/edit/tag-id': '/releases/edit/{tag}', }, - args: {tag: '2.0.0'} + args: {tag: '2.0.0'}, }).should.be.eql('https://' + test[1] + '/releases/edit/2.0.0'); }); - it('gitresolve(' + test[0] + ', {network})', function () { + it('gitresolve(' + test[0] + ', {network})', function() { gitresolve(test[0], { category: 'network', scheme: { @@ -274,7 +275,7 @@ describe('gitresolve()', function () { }).should.be.eql('https://' + test[1] + '/network'); }); - it('gitresolve(' + test[0] + ', {commits})', function () { + it('gitresolve(' + test[0] + ', {commits})', function() { gitresolve(test[0], { category: 'commits', scheme: { @@ -284,29 +285,29 @@ describe('gitresolve()', function () { }).should.be.eql('https://' + test[1] + '/commits'); }); - it('gitresolve(' + test[0] + ', {commits-with-branch})', function () { + it('gitresolve(' + test[0] + ', {commits-with-branch})', function() { gitresolve(test[0], { category: 'commits-with-branch', scheme: { base: '{protocol}://{hostname}/{username}/{reponame}', 'commits-with-branch': '/commits?branch={branch-name}', }, - branch: 'br' + branch: 'br', }).should.be.eql('https://' + test[1] + '/commits?branch=br'); }); - it('gitresolve(' + test[0] + ', {home})', function () { + it('gitresolve(' + test[0] + ', {home})', function() { gitresolve(test[0], { category: 'home', scheme: { base: '{protocol}://{hostname}/{username}/{reponame}', 'home': '', }, - args: {branch: 'br'} + args: {branch: 'br'}, }).should.be.eql('https://' + test[1]); }); - it('gitresolve(' + test[0] + ', {tree})', function () { + it('gitresolve(' + test[0] + ', {tree})', function() { gitresolve(test[0], { category: 'tree', scheme: { @@ -314,11 +315,11 @@ describe('gitresolve()', function () { 'tree': '/tree/{hash}/', }, hash: 'br', - args: {path: ''} + args: {path: ''}, }).should.be.eql('https://' + test[1] + '/tree/br/'); }); - it('gitresolve(' + test[0] + ', {blob})', function () { + it('gitresolve(' + test[0] + ', {blob})', function() { gitresolve(test[0], { category: 'blob', scheme: { @@ -326,11 +327,11 @@ describe('gitresolve()', function () { 'blob': '/blob/{hash}{path}', }, hash: 'br', - args: {path: '/README'} + args: {path: '/README'}, }).should.be.eql('https://' + test[1] + '/blob/br/README'); }); - it('gitresolve(' + test[0] + ', {snippets/new})', function () { + it('gitresolve(' + test[0] + ', {snippets/new})', function() { gitresolve(test[0], { category: 'snippets/new', scheme: { @@ -340,21 +341,21 @@ describe('gitresolve()', function () { }).should.be.eql('https://' + test[1] + '/snippets/new'); }); - it('gitresolve(' + test[0] + ', {commit:ed8d9e3})', function () { + it('gitresolve(' + test[0] + ', {commit:ed8d9e3})', function() { gitresolve(test[0], { category: 'commit', scheme: { base: '{protocol}://{hostname}/{username}/{reponame}', 'commit': '/commits/{hash}', }, - hash: 'ed8d9e3' + hash: 'ed8d9e3', }).should.be.eql('https://' + test[1] + '/commits/ed8d9e3'); }); }); }); -describe('gitremote()', function () { +describe('gitremote()', function() { var RE_PROTOCOL = /^(?:\w+\:\/\/|\w+@)/; var RE_GIT_EXT = /\.git$/i; function resolve(uri) { @@ -362,22 +363,22 @@ describe('gitremote()', function () { .replace(':', '/') .replace(RE_GIT_EXT, ''); } - it('gitremote.getRemoteUrl()', function () { + it('gitremote.getRemoteUrl()', function() { resolve(gitremote.getRemoteUrl()).should.be.eql('github.com/hotoo/gitopen'); }); - it('gitremote.getRemoteUrl({cwd})', function () { + it('gitremote.getRemoteUrl({cwd})', function() { resolve(gitremote.getRemoteUrl({cwd: '.'})).should.be.eql('github.com/hotoo/gitopen'); }); - it('gitremote.getRemoteUrl({remote})', function () { + it('gitremote.getRemoteUrl({remote})', function() { resolve(gitremote.getRemoteUrl({remote: 'origin'})).should.be.eql('github.com/hotoo/gitopen'); }); }); -describe('$ cd non-git-dir && gitopen', function () { - it('$ gitopen @hotoo', function (done) { +describe('$ cd non-git-dir && gitopen', function() { + it('$ gitopen @hotoo', function(done) { child_process.exec('./gitopen/bin/gitopen --verbose @hotoo', {cwd: '..'}, function(err, stdout) { should(err).not.be.ok(); stdout.should.be.containEql('URL: https://github.com/hotoo\n'); @@ -385,7 +386,7 @@ describe('$ cd non-git-dir && gitopen', function () { }); }); - it('$ gitopen @hotoo/gitopen', function (done) { + it('$ gitopen @hotoo/gitopen', function(done) { child_process.exec('./gitopen/bin/gitopen --verbose @hotoo/gitopen', {cwd: '..'}, function(err, stdout) { should(err).not.be.ok(); stdout.should.be.containEql('URL: https://github.com/hotoo/gitopen\n'); @@ -393,7 +394,7 @@ describe('$ cd non-git-dir && gitopen', function () { }); }); - it('$ gitopen snippet', function (done) { + it('$ gitopen snippet', function(done) { child_process.exec('./gitopen/bin/gitopen --verbose snippet', {cwd: '..'}, function(err, stdout) { should(err).not.be.ok(); stdout.should.be.containEql('URL: https://gist.github.com/\n'); @@ -401,7 +402,7 @@ describe('$ cd non-git-dir && gitopen', function () { }); }); - it('$ gitopen #1 SHOULD ERROR', function (done) { + it('$ gitopen #1 SHOULD ERROR', function(done) { child_process.exec('./gitopen/bin/gitopen --verbose "#1"', {cwd: '..'}, function(err) { should(err).be.ok(); done(); @@ -409,7 +410,7 @@ describe('$ cd non-git-dir && gitopen', function () { }); }); -describe('$ gitopen', function () { +describe('$ gitopen', function() { var git_command_case = [ ['', '/hotoo/gitopen'], @@ -481,7 +482,7 @@ describe('$ gitopen', function () { git_command_case.forEach(function(testcase) { var cmd = testcase[0] ? ' ' + testcase[0] : ''; - it('$ gitopen' + cmd, function (done) { + it('$ gitopen' + cmd, function(done) { child_process.exec('./bin/gitopen --verbose' + cmd, function(err, stdout) { should(err).not.be.ok(); stdout.should.be.containEql('URL: ' + (RE_URL.test(testcase[1]) ? testcase[1] : 'https://github.com' + testcase[1]) + '\n'); @@ -498,7 +499,7 @@ describe('$ gitopen', function () { ]; git_command_case_in_subdir.forEach(function(testcase) { var cmd = testcase[0] ? ' ' + testcase[0] : ''; - it('$ cd bin && gitopen' + cmd, function (done) { + it('$ cd bin && gitopen' + cmd, function(done) { child_process.exec('./gitopen --verbose' + cmd, {cwd: './bin'}, function(err, stdout) { should(err).not.be.ok(); stdout.should.be.containEql('URL: ' + (RE_URL.test(testcase[1]) ? testcase[1] : 'https://github.com' + testcase[1]) + '\n'); @@ -509,7 +510,7 @@ describe('$ gitopen', function () { }); -describe('$ hgopen', function () { +describe('$ hgopen', function() { var hg_command_case = [ ['', '/hotoo/gitopen'], ['#1', '/hotoo/gitopen/issues/1'], @@ -518,10 +519,10 @@ describe('$ hgopen', function () { ['gist', 'https://bitbucket.org/snippets/new'], ]; - describe('$ ssh://', function () { + describe('$ ssh://', function() { hg_command_case.forEach(function(testcase) { var cmd = testcase[0] ? ' "' + testcase[0] + '"' : ''; - it('$ hgopen' + cmd, function (done) { + it('$ hgopen' + cmd, function(done) { child_process.exec('../../bin/hgopen --verbose' + cmd, {cwd: 'test/hgssh'}, function(err, stdout) { should(err).not.be.ok(); stdout.should.be.containEql('URL: ' + (RE_URL.test(testcase[1]) ? testcase[1] : 'https://bitbucket.org' + testcase[1]) + '\n'); @@ -531,10 +532,10 @@ describe('$ hgopen', function () { }); }); - describe('$ https://', function () { + describe('$ https://', function() { hg_command_case.forEach(function(testcase) { var cmd = testcase[0] ? ' "' + testcase[0] + '"' : ''; - it('$ hgopen' + cmd, function (done) { + it('$ hgopen' + cmd, function(done) { child_process.exec('../../bin/hgopen --verbose' + cmd, {cwd: 'test/hghttp'}, function(err, stdout) { should(err).not.be.ok(); stdout.should.be.containEql('URL: ' + (RE_URL.test(testcase[1]) ? testcase[1] : 'https://bitbucket.org' + testcase[1]) + '\n'); @@ -545,6 +546,6 @@ describe('$ hgopen', function () { }); }); -describe('$ svnopen', function () { +describe('$ svnopen', function() { // TODO: });