1 |
|
2 |
|
3 | var assert = require('assert')
|
4 | var gh = require('..')
|
5 |
|
6 | describe('github-url-to-object', function () {
|
7 | describe('shorthand', function () {
|
8 | it('supports user/repo style', function () {
|
9 | var obj = gh('user/repo#branch')
|
10 | assert.equal(obj.user, 'user')
|
11 | assert.equal(obj.repo, 'repo')
|
12 | })
|
13 |
|
14 | it('supports user/repo#branch style', function () {
|
15 | var obj = gh('user/repo#branch')
|
16 | assert.equal(obj.user, 'user')
|
17 | assert.equal(obj.repo, 'repo')
|
18 | assert.equal(obj.branch, 'branch')
|
19 | })
|
20 |
|
21 | it('defaults to master branch', function () {
|
22 | var obj = gh('user/repo')
|
23 | assert.equal(obj.user, 'user')
|
24 | assert.equal(obj.repo, 'repo')
|
25 | assert.equal(obj.branch, 'master')
|
26 | })
|
27 | })
|
28 |
|
29 | describe('mediumhand', function () {
|
30 | it('supports github:user/repo style', function () {
|
31 | var obj = gh('github:user/repo#branch')
|
32 | assert.equal(obj.user, 'user')
|
33 | assert.equal(obj.repo, 'repo')
|
34 | })
|
35 |
|
36 | it('supports github:user/repo#branch style', function () {
|
37 | var obj = gh('github:user/repo#branch')
|
38 | assert.equal(obj.user, 'user')
|
39 | assert.equal(obj.repo, 'repo')
|
40 | assert.equal(obj.branch, 'branch')
|
41 | })
|
42 |
|
43 | it('defaults to master branch', function () {
|
44 | var obj = gh('github:user/repo')
|
45 | assert.equal(obj.user, 'user')
|
46 | assert.equal(obj.repo, 'repo')
|
47 | assert.equal(obj.branch, 'master')
|
48 | })
|
49 |
|
50 | it('rejects bitbucket', function () {
|
51 | var obj = gh('bitbucket:user/repo')
|
52 | assert.equal(obj, null)
|
53 | })
|
54 | })
|
55 |
|
56 | describe('oldschool', function () {
|
57 | it('supports git@ URLs', function () {
|
58 | var obj = gh('git@github.com:heroku/heroku-flags.git')
|
59 | assert.equal(obj.user, 'heroku')
|
60 | assert.equal(obj.repo, 'heroku-flags')
|
61 | })
|
62 |
|
63 | it('defaults to master branch for git@ URLs', function () {
|
64 | var obj = gh('git@github.com:heroku/heroku-flags.git')
|
65 | assert.equal(obj.branch, 'master')
|
66 | })
|
67 |
|
68 | it('supports git+https:// URLs', function () {
|
69 | var obj = gh('git+https://github.com/foo/bar.git')
|
70 | assert.equal(obj.user, 'foo')
|
71 | assert.equal(obj.repo, 'bar')
|
72 | })
|
73 |
|
74 | it('supports git:// URLs', function () {
|
75 | var obj = gh('git://github.com/foo/bar.git')
|
76 | assert.equal(obj.user, 'foo')
|
77 | assert.equal(obj.repo, 'bar')
|
78 | })
|
79 |
|
80 | it('defaults to master branch for git:// URLs', function () {
|
81 | var obj = gh('git://github.com/foo/bar.git')
|
82 | assert.equal(obj.branch, 'master')
|
83 | })
|
84 |
|
85 | describe('github enterprise', function () {
|
86 | it('supports git@ URLs', function () {
|
87 | var obj = gh('git@ghe.example.com:heroku/heroku-flags.git', {enterprise: true})
|
88 | assert.equal(obj.user, 'heroku')
|
89 | assert.equal(obj.repo, 'heroku-flags')
|
90 | })
|
91 |
|
92 | it('supports git:// URLs', function () {
|
93 | var obj = gh('git://ghe.example.com/foo/bar.git', {enterprise: true})
|
94 | assert.equal(obj.user, 'foo')
|
95 | assert.equal(obj.repo, 'bar')
|
96 | })
|
97 | })
|
98 | })
|
99 |
|
100 | describe('repository.url object', function () {
|
101 | it('accepts an object with a `url` property; common in package.json files', function () {
|
102 | var obj = gh({url: 'http://github.com/zeke/outlet.git', type: 'git'})
|
103 | assert.equal(obj.user, 'zeke')
|
104 | assert.equal(obj.repo, 'outlet')
|
105 | })
|
106 | })
|
107 |
|
108 | describe('http', function () {
|
109 | it('supports http URLs', function () {
|
110 | var obj = gh('http://github.com/zeke/outlet.git')
|
111 | assert.equal(obj.user, 'zeke')
|
112 | assert.equal(obj.repo, 'outlet')
|
113 | })
|
114 |
|
115 | it('supports https URLs', function () {
|
116 | var obj = gh('https://github.com/zeke/outlet.git')
|
117 | assert.equal(obj.user, 'zeke')
|
118 | assert.equal(obj.repo, 'outlet')
|
119 | })
|
120 |
|
121 | it('supports URLs with www', function () {
|
122 | var obj = gh('https://www.github.com/zeke/outlet')
|
123 | assert.equal(obj.user, 'zeke')
|
124 | assert.equal(obj.repo, 'outlet')
|
125 | })
|
126 |
|
127 | it('supports deep URLs', function () {
|
128 | var obj = gh('https://github.com/zeke/ruby-rails-sample/blob/b1e1000fedb6ca448dd78702de4fc78dedfee48c/app.json')
|
129 | assert.equal(obj.user, 'zeke')
|
130 | assert.equal(obj.repo, 'ruby-rails-sample')
|
131 | })
|
132 |
|
133 | it("doesn't require .git extension", function () {
|
134 | var obj = gh('https://github.com/zeke/outlet')
|
135 | assert.equal(obj.user, 'zeke')
|
136 | assert.equal(obj.repo, 'outlet')
|
137 | })
|
138 |
|
139 | it('defaults to master branch', function () {
|
140 | var obj = gh('https://github.com/zeke/outlet')
|
141 | assert.equal(obj.branch, 'master')
|
142 | })
|
143 |
|
144 | it('resolves tree-style URLS for branches other than master', function () {
|
145 | var obj = gh('https://github.com/zeke/outlet/tree/other-branch')
|
146 | assert.equal(obj.branch, 'other-branch')
|
147 | })
|
148 |
|
149 | it('resolves URLS for branches containing /', function () {
|
150 | var obj = gh('https://github.com/zeke/outlet/tree/feature/other-branch')
|
151 | assert.equal(obj.branch, 'feature/other-branch')
|
152 | })
|
153 |
|
154 | it('resolves URLS for branches containing .', function () {
|
155 | var obj = gh('https://github.com/zeke/outlet/tree/2.1')
|
156 | assert.equal(obj.branch, '2.1')
|
157 | })
|
158 |
|
159 | it('resolves blob-style URLS for branches other than master', function () {
|
160 | var obj = gh('https://github.com/zeke/ord/blob/new-style/.gitignore')
|
161 | assert.equal(obj.branch, 'new-style')
|
162 | })
|
163 |
|
164 | it('supports nested packages (lerna-style)', function () {
|
165 | var obj = gh('https://github.com/babel/babel/tree/master/packages/babel-plugin-transform-object-rest-spread/')
|
166 | assert.equal(obj.https_url, 'https://github.com/babel/babel/tree/master/packages/babel-plugin-transform-object-rest-spread')
|
167 | })
|
168 |
|
169 | describe('github enterprise', function () {
|
170 | it('supports http URLs', function () {
|
171 | var obj = gh('http://ghe.example.com/zeke/outlet.git', {enterprise: true})
|
172 | assert.equal(obj.user, 'zeke')
|
173 | assert.equal(obj.repo, 'outlet')
|
174 | })
|
175 |
|
176 | it('supports https URLs', function () {
|
177 | var obj = gh('https://ghe.example.com/zeke/outlet.git', {enterprise: true})
|
178 | assert.equal(obj.user, 'zeke')
|
179 | assert.equal(obj.repo, 'outlet')
|
180 | })
|
181 | })
|
182 | })
|
183 |
|
184 | describe('properties', function () {
|
185 | var obj
|
186 |
|
187 | describe('github.com', function () {
|
188 | before(function () {
|
189 | obj = gh('zeke/ord')
|
190 | })
|
191 |
|
192 | it('user', function () {
|
193 | assert.equal(obj.user, 'zeke')
|
194 | })
|
195 |
|
196 | it('repo', function () {
|
197 | assert.equal(obj.repo, 'ord')
|
198 | })
|
199 |
|
200 | it('branch', function () {
|
201 | assert.equal(obj.branch, 'master')
|
202 | })
|
203 |
|
204 | it('tarball_url', function () {
|
205 | assert.equal(obj.tarball_url, 'https://api.github.com/repos/zeke/ord/tarball/master')
|
206 | })
|
207 |
|
208 | it('api_url', function () {
|
209 | assert.equal(obj.api_url, 'https://api.github.com/repos/zeke/ord')
|
210 | })
|
211 |
|
212 | it('https_url', function () {
|
213 | assert.equal(obj.https_url, 'https://github.com/zeke/ord')
|
214 | })
|
215 |
|
216 | it('travis_url', function () {
|
217 | assert.equal(obj.travis_url, 'https://travis-ci.org/zeke/ord')
|
218 | })
|
219 |
|
220 | it('zip_url', function () {
|
221 | assert.equal(obj.zip_url, 'https://github.com/zeke/ord/archive/master.zip')
|
222 | })
|
223 | })
|
224 |
|
225 | describe('github enterprise', function () {
|
226 | before(function () {
|
227 | obj = gh('https://ghe.example.com/zeke/outlet.git', {enterprise: true})
|
228 | })
|
229 |
|
230 | it('user', function () {
|
231 | assert.equal(obj.user, 'zeke')
|
232 | })
|
233 |
|
234 | it('repo', function () {
|
235 | assert.equal(obj.repo, 'outlet')
|
236 | })
|
237 |
|
238 | it('branch', function () {
|
239 | assert.equal(obj.branch, 'master')
|
240 | })
|
241 |
|
242 | it('tarball_url', function () {
|
243 | assert.equal(obj.tarball_url, 'https://ghe.example.com/api/v3/repos/zeke/outlet/tarball/master')
|
244 | })
|
245 |
|
246 | it('api_url', function () {
|
247 | assert.equal(obj.api_url, 'https://ghe.example.com/api/v3/repos/zeke/outlet')
|
248 | })
|
249 |
|
250 | it('https_url', function () {
|
251 | assert.equal(obj.https_url, 'https://ghe.example.com/zeke/outlet')
|
252 | })
|
253 |
|
254 | it('zip_url', function () {
|
255 | assert.equal(obj.zip_url, 'https://ghe.example.com/zeke/outlet/archive/master.zip')
|
256 | })
|
257 | })
|
258 | })
|
259 |
|
260 | describe('branch other than master', function () {
|
261 | var obj
|
262 |
|
263 | before(function () {
|
264 | obj = gh('zeke/ord#experiment')
|
265 | })
|
266 |
|
267 | it('applies to tarball_url', function () {
|
268 | assert.equal(obj.tarball_url, 'https://api.github.com/repos/zeke/ord/tarball/experiment')
|
269 | })
|
270 |
|
271 | it('applies to https_url', function () {
|
272 | assert.equal(obj.https_url, 'https://github.com/zeke/ord/blob/experiment')
|
273 | })
|
274 |
|
275 | it('applies to clone_url', function () {
|
276 | assert.equal(obj.clone_url, 'https://github.com/zeke/ord')
|
277 | })
|
278 |
|
279 | it("doesn't apply to api_url", function () {
|
280 | assert.equal(obj.api_url, 'https://api.github.com/repos/zeke/ord')
|
281 | })
|
282 |
|
283 | it('applies to travis_url', function () {
|
284 | assert.equal(obj.travis_url, 'https://travis-ci.org/zeke/ord?branch=experiment')
|
285 | })
|
286 |
|
287 | it('applies to zip_url', function () {
|
288 | assert.equal(obj.zip_url, 'https://github.com/zeke/ord/archive/experiment.zip')
|
289 | })
|
290 | })
|
291 |
|
292 | describe('failure', function () {
|
293 | it('returns null if url is falsy', function () {
|
294 | assert.equal(gh(), null)
|
295 | assert.equal(gh(null), null)
|
296 | assert.equal(gh(undefined), null)
|
297 | assert.equal(gh(''), null)
|
298 | assert.equal(gh({url: '', type: 'git'}), null)
|
299 | assert.equal(gh({url: null, type: 'git'}), null)
|
300 | assert.equal(gh({url: undefined, type: 'git'}), null)
|
301 | })
|
302 |
|
303 | it('returns null if hostname is not github.com', function () {
|
304 | assert.equal(gh('https://ghe.something.com/foo/bar'), null)
|
305 | })
|
306 | })
|
307 | })
|