diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..32dd133 --- /dev/null +++ b/.editorconfig @@ -0,0 +1,27 @@ +# http://editorconfig.org +root = true + +[*] +indent_style = space +end_of_line = lf +charset = utf-8 +indent_size = 2 +trim_trailing_whitespace = true +insert_final_newline = true + +[*.json] +indent_style = space +indent_size = 2 + +[*.yml] +indent_style = space +indent_size = 2 + +[*.md] +indent_style = space +indent_size = 2 +trim_trailing_whitespace = false + +[test/fixtures/*] +trim_trailing_whitespace = false +insert_final_newline = false \ No newline at end of file diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..4a3f1d3 --- /dev/null +++ b/.gitattributes @@ -0,0 +1,10 @@ +# Enforce Unix newlines +* text eol=lf + +# binaries +*.ai binary +*.psd binary +*.jpg binary +*.gif binary +*.png binary +*.jpeg binary \ No newline at end of file diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..b120372 --- /dev/null +++ b/.gitignore @@ -0,0 +1,12 @@ +*.DS_Store +*.sublime-* +_gh_pages +bower_components +node_modules +npm-debug.log +actual +test/actual +temp +tmp +TODO.md +vendor diff --git a/.jshintrc b/.jshintrc new file mode 100644 index 0000000..6e5a84a --- /dev/null +++ b/.jshintrc @@ -0,0 +1,18 @@ +{ + "asi": false, + "boss": true, + "curly": true, + "eqeqeq": true, + "eqnull": true, + "esnext": true, + "immed": true, + "latedef": false, + "laxcomma": false, + "mocha": true, + "newcap": true, + "noarg": true, + "node": true, + "sub": true, + "undef": true, + "unused": true +} \ No newline at end of file diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..f9cffe6 --- /dev/null +++ b/.travis.yml @@ -0,0 +1,8 @@ +sudo: false +language: node_js +node_js: + - "0.10" + - "0.12" + - "iojs" +git: + depth: 10 diff --git a/.verb.md b/.verb.md new file mode 100644 index 0000000..f8e4805 --- /dev/null +++ b/.verb.md @@ -0,0 +1,313 @@ +# {%= name %} {%= badge("fury") %} {%= badge("travis") %} + +> {%= description %} + +**Why another GitHub URL parser library?** + +Seems like every lib I've found does too much, like both stringifying and parsing, or converts the URL from one format to another, only returns certain segments of the URL except for what I need, yields inconsistent results or has poor coverage. + +{%= include("install-npm", {save: true}) %} + +## Usage + +```js +var gh = require('{%= name %}'); +``` + +## Example results + +Generated results from test fixtures: + +```js +// assemble/verb#1.2.3 +{ + "user": "assemble", + "repo": "verb", + "repopath": "assemble/verb", + "branch": "1.2.3" +} + +// assemble/verb#branch +{ + "user": "assemble", + "repo": "verb", + "repopath": "assemble/verb", + "branch": "branch" +} + +// assemble/verb +{ + "user": "assemble", + "repo": "verb", + "repopath": "assemble/verb", + "branch": "master" +} + +// git+https://github.com/assemble/verb.git +{ + "user": "assemble", + "repo": "verb", + "repopath": "assemble/verb", + "branch": "master" +} + +// git+ssh://github.com/assemble/verb.git +{ + "user": "assemble", + "repo": "verb", + "repopath": "assemble/verb", + "branch": "master" +} + +// git://gh.pages.com/assemble/verb.git +{ + "user": "assemble", + "repo": "verb", + "repopath": "assemble/verb", + "branch": "master" +} + +// git://github.assemble.com/assemble/verb.git +{ + "user": "assemble", + "repo": "verb", + "repopath": "assemble/verb", + "branch": "master" +} + +// git://github.assemble.two.com/assemble/verb.git +{ + "user": "assemble", + "repo": "verb", + "repopath": "assemble/verb", + "branch": "master" +} + +// git://github.com/assemble/verb +{ + "user": "assemble", + "repo": "verb", + "repopath": "assemble/verb", + "branch": "master" +} + +// git://github.com/assemble/verb.git +{ + "user": "assemble", + "repo": "verb", + "repopath": "assemble/verb", + "branch": "master" +} + +// git@gh.pages.com:assemble/verb.git +{ + "user": "assemble", + "repo": "verb", + "repopath": "assemble/verb", + "branch": "master" +} + +// git@github.com:assemble/verb.git#1.2.3 +{ + "user": "assemble", + "repo": "verb", + "repopath": "assemble/verb", + "branch": "1.2.3" +} + +// git@github.com:assemble/verb.git#v1.2.3 +{ + "user": "assemble", + "repo": "verb", + "repopath": "assemble/verb", + "branch": "v1.2.3" +} + +// git@github.com:assemble/verb.git +{ + "user": "assemble", + "repo": "verb", + "repopath": "assemble/verb", + "branch": "master" +} + +// github:assemble/verb +{ + "user": "assemble", + "repo": "verb", + "repopath": "assemble/verb", + "branch": "master" +} + +// http://github.com/assemble +{ + "user": "assemble", + "repo": null, + "repopath": null, + "branch": "master" +} + +// http://github.com/assemble/verb +{ + "user": "assemble", + "repo": "verb", + "repopath": "assemble/verb", + "branch": "master" +} + +// http://github.com/assemble/verb.git +{ + "user": "assemble", + "repo": "verb", + "repopath": "assemble/verb", + "branch": "master" +} + +// http://github.com/assemble/verb/tree +{ + "user": "assemble", + "repo": "verb", + "repopath": "assemble/verb", + "branch": "master" +} + +// http://github.com/assemble/verb/tree/master +{ + "user": "assemble", + "repo": "verb", + "repopath": "assemble/verb", + "branch": "master" +} + +// http://github.com/assemble/verb/tree/master/foo/bar +{ + "user": "assemble", + "repo": "verb", + "repopath": "assemble/verb", + "branch": "master/foo/bar" +} + +// https://assemble.github.com/assemble/verb/somefile.tar.gz +{ + "user": "assemble", + "repo": "verb", + "repopath": "assemble/verb", + "branch": "master" +} + +// https://assemble.github.com/assemble/verb/somefile.zip +{ + "user": "assemble", + "repo": "verb", + "repopath": "assemble/verb", + "branch": "master" +} + +// https://assemble@github.com/assemble/verb.git +{ + "user": "assemble", + "repo": "verb", + "repopath": "assemble/verb", + "branch": "master" +} + +// https://gh.pages.com/assemble/verb.git +{ + "user": "assemble", + "repo": "verb", + "repopath": "assemble/verb", + "branch": "master" +} + +// https://github.com/assemble/verb +{ + "user": "assemble", + "repo": "verb", + "repopath": "assemble/verb", + "branch": "master" +} + +// https://github.com/assemble/verb.git +{ + "user": "assemble", + "repo": "verb", + "repopath": "assemble/verb", + "branch": "master" +} + +// https://github.com/assemble/verb/blob/1.2.3/README.md +{ + "user": "assemble", + "repo": "verb", + "repopath": "assemble/verb", + "branch": "1.2.3" +} + +// https://github.com/assemble/verb/blob/249b21a86400b38969cee3d5df6d2edf8813c137/README.md +{ + "user": "assemble", + "repo": "verb", + "repopath": "assemble/verb", + "branch": "master" +} + +// https://github.com/assemble/verb/blob/master/assemble/index.js +{ + "user": "assemble", + "repo": "verb", + "repopath": "assemble/verb", + "branch": "master" +} + +// https://github.com/assemble/verb/tree/1.2.3 +{ + "user": "assemble", + "repo": "verb", + "repopath": "assemble/verb", + "branch": "1.2.3" +} + +// https://github.com/assemble/verb/tree/feature/1.2.3 +{ + "user": "assemble", + "repo": "verb", + "repopath": "assemble/verb", + "branch": "feature/1.2.3" +} + +// https://github.com/repos/assemble/verb/tarball +{ + "user": "assemble", + "repo": "verb", + "repopath": "assemble/verb", + "branch": "master" +} + +// https://github.com/repos/assemble/verb/zipball +{ + "user": "assemble", + "repo": "verb", + "repopath": "assemble/verb", + "branch": "master" +} +``` + +## Related projects +{%= related(['is-git-url']) %} + +## Running tests +{%= include("tests") %} + +## Contributing +{%= include("contributing") %} + +## Author +{%= include("author") %} + +## License +{%= copyright() %} +{%= license() %} + +*** + +{%= include("footer") %} diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..65f90ac --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +The MIT License (MIT) + +Copyright (c) 2015, Jon Schlinkert. + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. diff --git a/README.md b/README.md new file mode 100644 index 0000000..8a2724e --- /dev/null +++ b/README.md @@ -0,0 +1,325 @@ +# parse-github-url [![NPM version](https://badge.fury.io/js/parse-github-url.svg)](http://badge.fury.io/js/parse-github-url) [![Build Status](https://travis-ci.org/jonschlinkert/parse-github-url.svg)](https://travis-ci.org/jonschlinkert/parse-github-url) + +> Parse a github URL into an object. + +**Why another GitHub URL parser library?** + +Seems like every lib I've found does too much, like both stringifying and parsing, or converts the URL from one format to another, only returns certain segments of the URL except for what I need, yields inconsistent results or has poor coverage. + +## Install with [npm](npmjs.org) + +```bash +npm i parse-github-url --save +``` + +## Usage + +```js +var gh = require('parse-github-url'); +``` + +## Example results + +Generated results from test fixtures: + +```js +// assemble/verb#1.2.3 +{ + "user": "assemble", + "repo": "verb", + "repopath": "assemble/verb", + "branch": "1.2.3" +} + +// assemble/verb#branch +{ + "user": "assemble", + "repo": "verb", + "repopath": "assemble/verb", + "branch": "branch" +} + +// assemble/verb +{ + "user": "assemble", + "repo": "verb", + "repopath": "assemble/verb", + "branch": "master" +} + +// git+https://github.com/assemble/verb.git +{ + "user": "assemble", + "repo": "verb", + "repopath": "assemble/verb", + "branch": "master" +} + +// git+ssh://github.com/assemble/verb.git +{ + "user": "assemble", + "repo": "verb", + "repopath": "assemble/verb", + "branch": "master" +} + +// git://gh.pages.com/assemble/verb.git +{ + "user": "assemble", + "repo": "verb", + "repopath": "assemble/verb", + "branch": "master" +} + +// git://github.assemble.com/assemble/verb.git +{ + "user": "assemble", + "repo": "verb", + "repopath": "assemble/verb", + "branch": "master" +} + +// git://github.assemble.two.com/assemble/verb.git +{ + "user": "assemble", + "repo": "verb", + "repopath": "assemble/verb", + "branch": "master" +} + +// git://github.com/assemble/verb +{ + "user": "assemble", + "repo": "verb", + "repopath": "assemble/verb", + "branch": "master" +} + +// git://github.com/assemble/verb.git +{ + "user": "assemble", + "repo": "verb", + "repopath": "assemble/verb", + "branch": "master" +} + +// git@gh.pages.com:assemble/verb.git +{ + "user": "assemble", + "repo": "verb", + "repopath": "assemble/verb", + "branch": "master" +} + +// git@github.com:assemble/verb.git#1.2.3 +{ + "user": "assemble", + "repo": "verb", + "repopath": "assemble/verb", + "branch": "1.2.3" +} + +// git@github.com:assemble/verb.git#v1.2.3 +{ + "user": "assemble", + "repo": "verb", + "repopath": "assemble/verb", + "branch": "v1.2.3" +} + +// git@github.com:assemble/verb.git +{ + "user": "assemble", + "repo": "verb", + "repopath": "assemble/verb", + "branch": "master" +} + +// github:assemble/verb +{ + "user": "assemble", + "repo": "verb", + "repopath": "assemble/verb", + "branch": "master" +} + +// http://github.com/assemble +{ + "user": "assemble", + "repo": null, + "repopath": null, + "branch": "master" +} + +// http://github.com/assemble/verb +{ + "user": "assemble", + "repo": "verb", + "repopath": "assemble/verb", + "branch": "master" +} + +// http://github.com/assemble/verb.git +{ + "user": "assemble", + "repo": "verb", + "repopath": "assemble/verb", + "branch": "master" +} + +// http://github.com/assemble/verb/tree +{ + "user": "assemble", + "repo": "verb", + "repopath": "assemble/verb", + "branch": "master" +} + +// http://github.com/assemble/verb/tree/master +{ + "user": "assemble", + "repo": "verb", + "repopath": "assemble/verb", + "branch": "master" +} + +// http://github.com/assemble/verb/tree/master/foo/bar +{ + "user": "assemble", + "repo": "verb", + "repopath": "assemble/verb", + "branch": "master/foo/bar" +} + +// https://assemble.github.com/assemble/verb/somefile.tar.gz +{ + "user": "assemble", + "repo": "verb", + "repopath": "assemble/verb", + "branch": "master" +} + +// https://assemble.github.com/assemble/verb/somefile.zip +{ + "user": "assemble", + "repo": "verb", + "repopath": "assemble/verb", + "branch": "master" +} + +// https://assemble@github.com/assemble/verb.git +{ + "user": "assemble", + "repo": "verb", + "repopath": "assemble/verb", + "branch": "master" +} + +// https://gh.pages.com/assemble/verb.git +{ + "user": "assemble", + "repo": "verb", + "repopath": "assemble/verb", + "branch": "master" +} + +// https://github.com/assemble/verb +{ + "user": "assemble", + "repo": "verb", + "repopath": "assemble/verb", + "branch": "master" +} + +// https://github.com/assemble/verb.git +{ + "user": "assemble", + "repo": "verb", + "repopath": "assemble/verb", + "branch": "master" +} + +// https://github.com/assemble/verb/blob/1.2.3/README.md +{ + "user": "assemble", + "repo": "verb", + "repopath": "assemble/verb", + "branch": "1.2.3" +} + +// https://github.com/assemble/verb/blob/249b21a86400b38969cee3d5df6d2edf8813c137/README.md +{ + "user": "assemble", + "repo": "verb", + "repopath": "assemble/verb", + "branch": "master" +} + +// https://github.com/assemble/verb/blob/master/assemble/index.js +{ + "user": "assemble", + "repo": "verb", + "repopath": "assemble/verb", + "branch": "master" +} + +// https://github.com/assemble/verb/tree/1.2.3 +{ + "user": "assemble", + "repo": "verb", + "repopath": "assemble/verb", + "branch": "1.2.3" +} + +// https://github.com/assemble/verb/tree/feature/1.2.3 +{ + "user": "assemble", + "repo": "verb", + "repopath": "assemble/verb", + "branch": "feature/1.2.3" +} + +// https://github.com/repos/assemble/verb/tarball +{ + "user": "assemble", + "repo": "verb", + "repopath": "assemble/verb", + "branch": "master" +} + +// https://github.com/repos/assemble/verb/zipball +{ + "user": "assemble", + "repo": "verb", + "repopath": "assemble/verb", + "branch": "master" +} +``` + +## Related projects +* [is-git-url](https://github.com/jonschlinkert/is-git-url): Regex to validate that a URL is a git url. + +## Running tests +Install dev dependencies. + +```bash +npm i -d && npm test +``` + +## Contributing +Pull requests and stars are always welcome. For bugs and feature requests, [please create an issue](https://github.com/jonschlinkert/parse-github-url/issues) + +## Author + +**Jon Schlinkert** + ++ [github/jonschlinkert](https://github.com/jonschlinkert) ++ [twitter/jonschlinkert](http://twitter.com/jonschlinkert) + +## License +Copyright (c) 2015 Jon Schlinkert +Released under the MIT license + +*** + +_This file was generated by [verb-cli](https://github.com/assemble/verb-cli) on March 14, 2015._ \ No newline at end of file diff --git a/index.js b/index.js new file mode 100644 index 0000000..9e1e55f --- /dev/null +++ b/index.js @@ -0,0 +1,123 @@ +/*! + * parse-github-url + * + * Copyright (c) 2015, Jon Schlinkert. + * Licensed under the MIT License. + */ + +'use strict'; + +var url = require('url'); + +var cache = {}; + +module.exports = function gh(str) { + return cache[str] || (cache[str] = parse(str)); +}; + +function parse(str) { + if (typeof str !== 'string' || !str.length) { + return null; + } + + if (str.indexOf('git@gist') !== -1 || str.indexOf('//gist') !== -1) { + return null; + } + + // parse the URL + var o = url.parse(str); + + o.path = trimSlash(o.path); + o.pathname = trimSlash(o.pathname); + + if (o.path.indexOf('repos') === 0) { + o.path = o.path.substr(6); + } + + var seg = o.path.split('/').filter(Boolean); + var hasBlob = seg[2] === 'blob'; + if (hasBlob && !isChecksum(seg[3])) { + o.branch = seg[3]; + } + + var blob = str.indexOf('blob'); + if (blob !== -1) { + o.blob = str.substr(blob + 5); + str = str.substr(0, blob); + } + + var tree = str.indexOf('tree'); + if (tree !== -1) { + o.branch = str.substr(tree + 5); + } + + o.user = user(seg[0]); + o.repo = repo(seg[1]); + + if (seg.length > 1 && o.user && o.repo) { + o.repopath = o.user + '/' + o.repo; + } else { + var href = o.href.split(':'); + if (href.length === 2 && o.href.indexOf('//') === -1) { + o.repopath = o.repopath || href[href.length - 1]; + var repoSegments = o.repopath.split('/'); + o.user = repoSegments[0]; + o.repo = repoSegments[1]; + } else { + var match = o.href.match(/\/([^\/]*)$/); + o.user = match ? match[1] : null; + o.repopath = null; + } + + var segs = o.repopath && o.repopath.split('/').filter(Boolean); + if (segs && segs.length === 2) { + o.user = segs[0]; + o.repo = segs[1]; + } + } + + o.branch = o.branch || parseBranch(o.path, o); + var res = {}; + res.user = o.user || null; + res.repo = o.repo || null; + res.repopath = o.repopath; + res.branch = o.branch; + return res; +} + +function isChecksum(str) { + return /^[a-f0-9]{40}$/i.test(str); +} + +function parseBranch(str, obj) { + var branch; + var segs = str.split('#'); + if (segs.length !== 1) { + branch = segs[segs.length - 1]; + } + if (!branch && obj.hash && obj.hash.charAt(0) === '#') { + branch = obj.hash.substr(1); + } + return branch || 'master'; +} + +function trimSlash(path) { + if (path.charAt(0) === '/') { + path = path.slice(1); + } + return path; +} + +function repo(str) { + if (!str || !str.length) return null; + str = str.replace(/^\W+/, ''); + return str.split('.')[0]; +} + +function user(str) { + if (str.indexOf(':') !== -1) { + var segs = str.split(':'); + return segs[segs.length - 1]; + } + return str; +} diff --git a/package.json b/package.json new file mode 100644 index 0000000..6ebd82c --- /dev/null +++ b/package.json @@ -0,0 +1,35 @@ +{ + "name": "parse-github-url", + "description": "Parse a github URL into an object.", + "version": "0.1.0", + "homepage": "https://github.com/jonschlinkert/parse-github-url", + "author": { + "name": "Jon Schlinkert", + "url": "https://github.com/jonschlinkert" + }, + "repository": { + "type": "git", + "url": "git://github.com/jonschlinkert/parse-github-url.git" + }, + "bugs": { + "url": "https://github.com/jonschlinkert/parse-github-url/issues" + }, + "license": { + "type": "MIT", + "url": "https://github.com/jonschlinkert/parse-github-url/blob/master/LICENSE" + }, + "files": [ + "index.js" + ], + "main": "index.js", + "engines": { + "node": ">=0.10.0" + }, + "scripts": { + "test": "mocha" + }, + "devDependencies": { + "mocha": "*", + "should": "*" + } +} \ No newline at end of file diff --git a/support.js b/support.js new file mode 100644 index 0000000..4bc41dc --- /dev/null +++ b/support.js @@ -0,0 +1,50 @@ +'use strict'; + +var util = require('util'); +var gh = require('./'); + +var formats = [ + 'assemble/verb#1.2.3', + 'assemble/verb#branch', + 'assemble/verb', + 'git+https://github.com/assemble/verb.git', + 'git+ssh://github.com/assemble/verb.git', + 'git://gh.pages.com/assemble/verb.git', + 'git://github.assemble.com/assemble/verb.git', + 'git://github.assemble.two.com/assemble/verb.git', + 'git://github.com/assemble/verb', + 'git://github.com/assemble/verb.git', + 'git@gh.pages.com:assemble/verb.git', + 'git@github.com:assemble/verb.git#1.2.3', + 'git@github.com:assemble/verb.git#v1.2.3', + 'git@github.com:assemble/verb.git', + 'github:assemble/verb', + 'http://github.com/assemble', + 'http://github.com/assemble/verb', + 'http://github.com/assemble/verb.git', + 'http://github.com/assemble/verb/tree', + 'http://github.com/assemble/verb/tree/master', + 'http://github.com/assemble/verb/tree/master/foo/bar', + 'https://assemble.github.com/assemble/verb/somefile.tar.gz', + 'https://assemble.github.com/assemble/verb/somefile.zip', + 'https://assemble@github.com/assemble/verb.git', + 'https://gh.pages.com/assemble/verb.git', + 'https://github.com/assemble/verb', + 'https://github.com/assemble/verb.git', + 'https://github.com/assemble/verb/blob/1.2.3/README.md', + 'https://github.com/assemble/verb/blob/249b21a86400b38969cee3d5df6d2edf8813c137/README.md', + 'https://github.com/assemble/verb/blob/master/assemble/index.js', + 'https://github.com/assemble/verb/tree/1.2.3', + 'https://github.com/assemble/verb/tree/feature/1.2.3', + 'https://github.com/repos/assemble/verb/tarball', + 'https://github.com/repos/assemble/verb/zipball', +]; + +var res = '```js'; +formats.forEach(function (url) { + res += '\n// ' + url + '\n' + JSON.stringify(gh(url), null, 2) + '\n'; +}); + +res += '```\n' + +console.log(res); diff --git a/test.js b/test.js new file mode 100644 index 0000000..5f6c7fe --- /dev/null +++ b/test.js @@ -0,0 +1,136 @@ +'use strict'; + +/* deps:mocha */ +var assert = require('assert'); +var gh = require('./'); +var o; + +describe('parse-github-url', function () { + it('should get the user:', function () { + assert.equal(gh(''), null); + assert.equal(gh('assemble/verb#branch').user, 'assemble'); + assert.equal(gh('assemble/verb#dev').user, 'assemble'); + assert.equal(gh('assemble/verb').user, 'assemble'); + assert.equal(gh('git+https://github.com/assemble/verb.git').user, 'assemble'); + assert.equal(gh('git+ssh://github.com/assemble/verb.git').user, 'assemble'); + assert.equal(gh('git://gh.pages.com/assemble/verb.git').user, 'assemble'); + assert.equal(gh('git://github.com/assemble/verb').user, 'assemble'); + assert.equal(gh('git://github.com/assemble/verb.git').user, 'assemble'); + assert.equal(gh('git://github.com/foo/bar.git').user, 'foo'); + assert.equal(gh('git://github.one.com/assemble/verb.git').user, 'assemble'); + assert.equal(gh('git://github.one.two.com/assemble/verb.git').user, 'assemble'); + assert.equal(gh('git@gh.pages.com:assemble/verb.git').user, 'assemble'); + assert.equal(gh('git@gist.github.com:9284722.git'), null); + assert.equal(gh('git@github.com:assemble/verb.git#0.6.0').user, 'assemble'); + assert.equal(gh('git@github.com:assemble/verb.git#v0.6.0').user, 'assemble'); + assert.equal(gh('git@github.com:assemble/verb.git').user, 'assemble'); + assert.equal(gh('github:user/repo').user, 'user'); + assert.equal(gh('http://github.com/assemble/verb').user, 'assemble'); + assert.equal(gh('http://github.com/assemble/verb.git').user, 'assemble'); + assert.equal(gh('http://github.com/assemble/verb/tree').user, 'assemble'); + assert.equal(gh('http://github.com/assemble/verb/tree/master').user, 'assemble'); + assert.equal(gh('http://github.com/assemble/verb/tree/master/foo/bar').user, 'assemble'); + assert.equal(gh('https://assemble@github.com/assemble/verb.git').user, 'assemble'); + assert.equal(gh('https://foo.github.com/assemble/verb/bar.tar.gz').user, 'assemble'); + assert.equal(gh('https://foo.github.com/assemble/verb/bar.zip').user, 'assemble'); + assert.equal(gh('https://gh.pages.com/assemble/verb.git').user, 'assemble'); + assert.equal(gh('https://gist.github.com/9284722.git'), null); + assert.equal(gh('https://github.com/assemble/verb').user, 'assemble'); + assert.equal(gh('https://github.com/assemble/verb.git').user, 'assemble'); + assert.equal(gh('https://github.com/assemble/verb/blob/249b21a86400b38969cee3d5df6d2edf8813c137/README.md').user, 'assemble'); + assert.equal(gh('https://github.com/assemble/verb/blob/master/assemble/index.js').user, 'assemble'); + assert.equal(gh('https://github.com/assemble/verb/blob/master/foo/index.js').user, 'assemble'); + assert.equal(gh('https://github.com/assemble/verb/blob/v1.0.0/README.md').user, 'assemble'); + assert.equal(gh('https://github.com/assemble/verb/tree/0.2.0').user, 'assemble'); + assert.equal(gh('https://github.com/assemble/verb/tree/dev').user, 'assemble'); + assert.equal(gh('https://github.com/assemble/verb/tree/feature/dev').user, 'assemble'); + assert.equal(gh('https://github.com/repos/assemble/verb/tarball').user, 'assemble'); + assert.equal(gh('https://github.com/repos/assemble/verb/zipball').user, 'assemble'); + assert.equal(gh(), null); + assert.equal(gh(null), null); + assert.equal(gh(undefined), null); + }); + it('should get the branch:', function () { + assert.equal(gh('assemble/verb#branch').branch, 'branch'); + assert.equal(gh('assemble/verb#dev').branch, 'dev'); + assert.equal(gh('git@github.com:assemble/verb.git#0.6.0').branch, '0.6.0'); + assert.equal(gh('git@github.com:assemble/verb.git#v0.6.0').branch, 'v0.6.0'); + assert.equal(gh('https://github.com/assemble/verb/blob/foo/README.md').branch, 'foo'); + assert.equal(gh('https://github.com/assemble/verb/tree/dev').branch, 'dev'); + assert.equal(gh('https://github.com/assemble/verb/tree/feature/dev').branch, 'feature/dev'); + assert.equal(gh('https://github.com/assemble/verb/tree/foo').branch, 'foo'); + }); + it('should use master branch when another branch is not defined:', function () { + assert.equal(gh('assemble/verb').branch, 'master'); + assert.equal(gh('git://github.com/foo/bar.git').branch, 'master'); + assert.equal(gh('git@github.com:assemble/verb.git').branch, 'master'); + assert.equal(gh('github:assemble/verb').branch, 'master'); + assert.equal(gh('http://github.com/assemble/verb/tree/master').branch, 'master'); + assert.equal(gh('http://github.com/assemble/verb/tree/master/foo/bar').branch, 'master/foo/bar'); + assert.equal(gh('https://github.com/assemble/verb').branch, 'master'); + assert.equal(gh('https://github.com/assemble/verb/blob/master/foo/index.js').branch, 'master'); + }); + it('should get a full repo path:', function () { + assert.equal(gh('assemble/verb#dev').repopath, 'assemble/verb'); + assert.equal(gh('assemble/verb').repopath, 'assemble/verb'); + assert.equal(gh('git+https://github.com/assemble/verb.git').repopath, 'assemble/verb'); + assert.equal(gh('git+ssh://github.com/assemble/verb.git').repopath, 'assemble/verb'); + assert.equal(gh('git://github.com/assemble/verb').repopath, 'assemble/verb'); + assert.equal(gh('git://github.com/assemble/verb.git').repopath, 'assemble/verb'); + assert.equal(gh('git://github.one.com/assemble/verb.git').repopath, 'assemble/verb'); + assert.equal(gh('git://github.one.two.com/assemble/verb.git').repopath, 'assemble/verb'); + }); + it('should know when repo is not defined:', function () { + assert.equal(gh('git+https://github.com/assemble').repo, null); + assert.equal(gh('git+https://github.com/assemble').repopath, null); + assert.equal(gh('git+https://github.com/assemble').user, 'assemble'); + assert.equal(gh('git+ssh://github.com/assemble').repo, null); + assert.equal(gh('git+ssh://github.com/assemble').repopath, null); + assert.equal(gh('git+ssh://github.com/assemble').user, 'assemble'); + assert.equal(gh('git://github.com/assemble').repo, null); + assert.equal(gh('git://github.com/assemble').repopath, null); + assert.equal(gh('git://github.com/assemble').user, 'assemble'); + assert.equal(gh('git://github.one.com/assemble').repo, null); + assert.equal(gh('git://github.one.com/assemble').repopath, null); + assert.equal(gh('git://github.one.com/assemble').user, 'assemble'); + assert.equal(gh('git://github.one.two.com/assemble').repo, null); + assert.equal(gh('git://github.one.two.com/assemble').repopath, null); + assert.equal(gh('git://github.one.two.com/assemble').user, 'assemble'); + assert.equal(gh('http://github.com/assemble').repo, null); + assert.equal(gh('http://github.com/assemble').repopath, null); + assert.equal(gh('http://github.com/assemble').user, 'assemble'); + }); + it('should get the repo:', function () { + assert.equal(gh('assemble/verb#branch').repo, 'verb'); + assert.equal(gh('assemble/verb#dev').repo, 'verb'); + assert.equal(gh('assemble/verb').repo, 'verb'); + assert.equal(gh('git+https://github.com/assemble/verb.git').repo, 'verb'); + assert.equal(gh('git+ssh://github.com/assemble/verb.git').repo, 'verb'); + assert.equal(gh('git://gh.pages.com/assemble/verb.git').repo, 'verb'); + assert.equal(gh('git://github.com/assemble/verb').repo, 'verb'); + assert.equal(gh('git://github.com/assemble/verb.git').repo, 'verb'); + assert.equal(gh('git://github.com/foo/bar.git').repo, 'bar'); + assert.equal(gh('git://github.one.com/assemble/verb.git').repo, 'verb'); + assert.equal(gh('git://github.one.two.com/assemble/verb.git').repo, 'verb'); + assert.equal(gh('git@gh.pages.com:assemble/verb.git').repo, 'verb'); + assert.equal(gh('git@github.com:assemble/verb.git#0.6.0').repo, 'verb'); + assert.equal(gh('git@github.com:assemble/verb.git#v0.6.0').repo, 'verb'); + assert.equal(gh('git@github.com:assemble/verb.git').repo, 'verb'); + assert.equal(gh('github:assemble/verb').repo, 'verb'); + assert.equal(gh('http://github.com/assemble/verb').repo, 'verb'); + assert.equal(gh('http://github.com/assemble/verb.git').repo, 'verb'); + assert.equal(gh('http://github.com/assemble/verb/tree').repo, 'verb'); + assert.equal(gh('http://github.com/assemble/verb/tree/master').repo, 'verb'); + assert.equal(gh('http://github.com/assemble/verb/tree/master/foo/dev').repo, 'verb'); + assert.equal(gh('https://assemble.github.io/assemble/verb/dev.tar.gz').repo, 'verb'); + assert.equal(gh('https://assemble.github.io/assemble/verb/dev.zip').repo, 'verb'); + assert.equal(gh('https://assemble@github.com/assemble/verb.git').repo, 'verb'); + assert.equal(gh('https://gh.pages.com/assemble/verb.git').repo, 'verb'); + assert.equal(gh('https://github.com/assemble/verb').repo, 'verb'); + assert.equal(gh('https://github.com/assemble/verb.git').repo, 'verb'); + assert.equal(gh('https://github.com/assemble/verb/blob/249b21a86400b38969cee3d5df6d2edf8813c137/README.md').repo, 'verb'); + assert.equal(gh('https://github.com/assemble/verb/blob/master/foo/index.js').repo, 'verb'); + assert.equal(gh('https://github.com/repos/assemble/verb/tarball').repo, 'verb'); + assert.equal(gh('https://github.com/repos/assemble/verb/zipball').repo, 'verb'); + }); +});