-
Notifications
You must be signed in to change notification settings - Fork 89
Feature/50 fix gitlab pathmatch 3 0 0 #52
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
145b0c9
test: added default fixtures and github specific fixtures
305939f
test: added refactered tests for gists
fa87af7
fix: updated pathmatch for gitlab
b473c55
test: added basic test for ._fill() method
0aea712
test: added ignore; for 100% testing (this seems wonky)
a03d51e
test: added refactered tests for bitbucket
4693b9c
test: moved all github url tests together
d04239b
test: removed unused testing structure
af4835c
test: added script to get coverage report
f4f05cb
fix: update pathmatch for gitlab
claudiahdz File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,32 +2,292 @@ | |
var HostedGit = require('../index') | ||
var test = require('tap').test | ||
|
||
test('fromUrl(bitbucket url)', function (t) { | ||
function verify (host, label, branch) { | ||
var showLabel = function (label, fn) { return label + ' -> ' + fn } | ||
|
||
var testFixtures = function (t, params, fixtures) { | ||
for (var i = 0; i < fixtures.length; ++i) { | ||
var fixture = fixtures[i] | ||
|
||
var host = fixture.host(params) | ||
var hostinfo = HostedGit.fromUrl(host) | ||
var hash = branch ? '#' + branch : '' | ||
t.ok(hostinfo, label) | ||
if (!hostinfo) return | ||
t.is(hostinfo.https(), 'git+https://bitbucket.org/111/222.git' + hash, label + ' -> https') | ||
t.is(hostinfo.browse(), 'https://bitbucket.org/111/222' + (branch ? '/src/' + branch : ''), label + ' -> browse') | ||
t.is(hostinfo.browse(''), 'https://bitbucket.org/111/222/src/' + (branch || 'master') + '/', label + ' -> browse(path)') | ||
t.is(hostinfo.browse('C'), 'https://bitbucket.org/111/222/src/' + (branch || 'master') + '/C', label + ' -> browse(path)') | ||
t.is(hostinfo.browse('C/D'), 'https://bitbucket.org/111/222/src/' + (branch || 'master') + '/C/D', label + ' -> browse(path)') | ||
t.is(hostinfo.browse('C', 'A'), 'https://bitbucket.org/111/222/src/' + (branch || 'master') + '/C#a', label + ' -> browse(path, fragment)') | ||
t.is(hostinfo.browse('C/D', 'A'), 'https://bitbucket.org/111/222/src/' + (branch || 'master') + '/C/D#a', label + ' -> browse(path, fragment)') | ||
t.is(hostinfo.docs(), 'https://bitbucket.org/111/222' + (branch ? '/src/' + branch : '') + '#readme', label + ' -> docs') | ||
t.is(hostinfo.ssh(), '[email protected]:111/222.git' + hash, label + ' -> ssh') | ||
t.is(hostinfo.sshurl(), 'git+ssh://[email protected]/111/222.git' + hash, label + ' -> sshurl') | ||
t.is(hostinfo.shortcut(), 'bitbucket:111/222' + hash, label + ' -> shortcut') | ||
t.is(hostinfo.file(''), 'https://bitbucket.org/111/222/raw/' + (branch || 'master') + '/', label + ' -> file') | ||
t.is(hostinfo.file('C'), 'https://bitbucket.org/111/222/raw/' + (branch || 'master') + '/C', label + ' -> file') | ||
t.is(hostinfo.file('C/D'), 'https://bitbucket.org/111/222/raw/' + (branch || 'master') + '/C/D', label + ' -> file') | ||
t.is(hostinfo.tarball(), 'https://bitbucket.org/111/222/get/' + (branch || 'master') + '.tar.gz', label + ' -> tarball') | ||
t.is(hostinfo.tarball({ noCommittish: true }), 'https://bitbucket.org/111/222/get/' + (branch || 'master') + '.tar.gz', label + ' -> tarball') | ||
|
||
// INFO: fromUrl should return `undefined` from fixture input | ||
if (fixture.isUndefined) { | ||
t.test('input results in undefined', function (tt) { | ||
tt.is(hostinfo, undefined) | ||
tt.end() | ||
}) | ||
break | ||
} | ||
|
||
t.test('hostinfo.https', function (tt) { | ||
var expected = function (url, hasBranch) { | ||
return (hasBranch) | ||
? url + '#' + params.branch | ||
: url | ||
} | ||
tt.is( | ||
hostinfo.https(), | ||
expected('git+https://bitbucket.org/some-owner/some-repo.git', fixture.hasBranch, fixture.hasGroup), | ||
showLabel(fixture.label, 'https') | ||
) | ||
// INFO: not using `expected` because with `{noCommittish: true}` the output is always the same | ||
tt.is( | ||
hostinfo.https({ noCommittish: true }), | ||
'git+https://bitbucket.org/some-owner/some-repo.git', | ||
showLabel(fixture.label, 'https({ noCommittish: true })') | ||
) | ||
tt.is( | ||
hostinfo.https({ noGitPlus: true }), | ||
expected('https://bitbucket.org/some-owner/some-repo.git', fixture.hasBranch), | ||
showLabel(fixture.label, 'https({ noGitPlus: true })') | ||
) | ||
tt.end() | ||
}) | ||
t.test('hostinfo.browse', function (tt) { | ||
var expected = function (url, hasBranch) { | ||
if (hasBranch) { | ||
if (url.indexOf('master') === -1) { | ||
return url + '/src/' + params.branch | ||
} else { | ||
return url.replace(/master/gi, params.branch) | ||
} | ||
} | ||
return url | ||
} | ||
tt.is( | ||
hostinfo.browse(), | ||
expected('https://bitbucket.org/some-owner/some-repo', fixture.hasBranch), | ||
showLabel(fixture.label, 'browse') | ||
) | ||
tt.is( | ||
hostinfo.browse(''), | ||
expected('https://bitbucket.org/some-owner/some-repo/src/master/', fixture.hasBranch), | ||
showLabel(fixture.label, "browse('')") | ||
) | ||
tt.is( | ||
hostinfo.browse('C'), | ||
expected('https://bitbucket.org/some-owner/some-repo/src/master/C', fixture.hasBranch), | ||
showLabel(fixture.label, "browse('C')") | ||
) | ||
tt.is( | ||
hostinfo.browse('C/D'), | ||
expected('https://bitbucket.org/some-owner/some-repo/src/master/C/D', fixture.hasBranch), | ||
showLabel(fixture.label, "browse('C/D')") | ||
) | ||
tt.is( | ||
hostinfo.browse('C', 'A'), | ||
expected('https://bitbucket.org/some-owner/some-repo/src/master/C#a', fixture.hasBranch), | ||
showLabel(fixture.label, "browse('C', 'A')") | ||
) | ||
tt.is( | ||
hostinfo.browse('C/D', 'A'), | ||
expected('https://bitbucket.org/some-owner/some-repo/src/master/C/D#a', fixture.hasBranch), | ||
showLabel(fixture.label, "browse('C/D', 'A')") | ||
) | ||
tt.end() | ||
}) | ||
t.test('hostinfo.docs', function (tt) { | ||
var expected = function (url, hasBranch) { | ||
if (hasBranch) { | ||
var splitUrl = url.split('#') | ||
return splitUrl[0] + '/src/' + params.branch + '#' + splitUrl[1] | ||
} | ||
return url | ||
} | ||
tt.is( | ||
hostinfo.docs(), | ||
expected('https://bitbucket.org/some-owner/some-repo#readme', fixture.hasBranch), | ||
showLabel(fixture.label, 'docs') | ||
) | ||
tt.is( | ||
hostinfo.docs({ noCommittish: true }), | ||
// INFO: not using `expected` because with `{noCommittish: true}` the output is always the same | ||
'https://bitbucket.org/some-owner/some-repo#readme', | ||
showLabel(fixture.label, 'docs({ noCommittish: true })') | ||
) | ||
tt.is( | ||
hostinfo.docs({ noGitPlus: true }), | ||
expected('https://bitbucket.org/some-owner/some-repo#readme', fixture.hasBranch), | ||
showLabel(fixture.label, 'docs({ noGitPlus: true })') | ||
) | ||
tt.end() | ||
}) | ||
t.test('hostinfo.ssh', function (tt) { | ||
var expected = function (url, hasBranch) { | ||
return (hasBranch) | ||
? url + '#' + params.branch | ||
: url | ||
} | ||
tt.is( | ||
hostinfo.ssh(), | ||
expected('[email protected]:some-owner/some-repo.git', fixture.hasBranch), | ||
showLabel(fixture.label, 'ssh') | ||
) | ||
tt.is( | ||
hostinfo.ssh({ noCommittish: true }), | ||
// INFO: not using `expected` because with `{noCommittish: true}` the output is always the same | ||
'[email protected]:some-owner/some-repo.git', | ||
showLabel(fixture.label, 'ssh({ noCommittish: true })') | ||
) | ||
tt.is( | ||
hostinfo.ssh({ noGitPlus: true }), | ||
expected('[email protected]:some-owner/some-repo.git', fixture.hasBranch), | ||
showLabel(fixture.label, 'ssh({ noGitPlus: true })') | ||
) | ||
tt.end() | ||
}) | ||
t.test('hostinfo.sshurl', function (tt) { | ||
var expected = function (url, hasBranch) { | ||
return (hasBranch) | ||
? url + '#' + params.branch | ||
: url | ||
} | ||
tt.is( | ||
hostinfo.sshurl(), | ||
expected('git+ssh://[email protected]/some-owner/some-repo.git', fixture.hasBranch), | ||
showLabel(fixture.label, 'sshurl') | ||
) | ||
tt.is( | ||
hostinfo.sshurl({ noCommittish: true }), | ||
// INFO: not using `expected` because with `{noCommittish: true}` the output is always the same | ||
'git+ssh://[email protected]/some-owner/some-repo.git', | ||
showLabel(fixture.label, 'sshurl({ noCommittish: true })') | ||
) | ||
tt.is( | ||
hostinfo.sshurl({ noGitPlus: true }), | ||
expected('ssh://[email protected]/some-owner/some-repo.git', fixture.hasBranch), | ||
showLabel(fixture.label, 'sshurl({ noGitPlus: true })') | ||
) | ||
tt.end() | ||
}) | ||
t.test('hostinfo.shortcut', function (tt) { | ||
var expected = function (url, hasBranch) { | ||
return (hasBranch) | ||
? url + '#' + params.branch | ||
: url | ||
} | ||
tt.is( | ||
hostinfo.shortcut(), | ||
expected('bitbucket:some-owner/some-repo', fixture.hasBranch), | ||
showLabel(fixture.label, 'shortcut') | ||
) | ||
tt.is( | ||
hostinfo.shortcut({ noCommittish: true }), | ||
// INFO: not using `expected` because with `{noCommittish: true}` the output is always the same | ||
'bitbucket:some-owner/some-repo', | ||
showLabel(fixture.label, 'shortcut({ noCommittish: true })') | ||
) | ||
tt.is( | ||
hostinfo.shortcut({ noGitPlus: true }), | ||
expected('bitbucket:some-owner/some-repo', fixture.hasBranch), | ||
showLabel(fixture.label, 'shortcut({ noGitPlus: true })') | ||
) | ||
tt.end() | ||
}) | ||
t.test('hostinfo.file', function (tt) { | ||
var expected = function (url, hasBranch) { | ||
return (hasBranch) | ||
? url.replace(/master/gi, params.branch) | ||
: url | ||
} | ||
tt.is( | ||
hostinfo.file(), | ||
expected('https://bitbucket.org/some-owner/some-repo/raw/master/', fixture.hasBranch), | ||
showLabel(fixture.label, 'file') | ||
) | ||
tt.is( | ||
hostinfo.file('C'), | ||
expected('https://bitbucket.org/some-owner/some-repo/raw/master/C', fixture.hasBranch), | ||
showLabel(fixture.label, "file('C')") | ||
) | ||
tt.is( | ||
hostinfo.file('C/D'), | ||
expected('https://bitbucket.org/some-owner/some-repo/raw/master/C/D', fixture.hasBranch), | ||
showLabel(fixture.label, "file('C/D')") | ||
) | ||
tt.end() | ||
}) | ||
t.test('hostinfo.tarball', function (tt) { | ||
var expected = function (url, hasBranch) { | ||
return (hasBranch) | ||
? url.replace(/master/gi, params.branch) | ||
: url | ||
} | ||
tt.is( | ||
hostinfo.tarball(), | ||
expected('https://bitbucket.org/some-owner/some-repo/get/master.tar.gz', fixture.hasBranch), | ||
showLabel(fixture.label, 'tarball') | ||
) | ||
tt.is( | ||
hostinfo.tarball({ noCommittish: true }), | ||
expected('https://bitbucket.org/some-owner/some-repo/get/master.tar.gz', fixture.hasBranch), | ||
showLabel(fixture.label, 'tarball({ noCommittish: true })') | ||
) | ||
tt.is( | ||
hostinfo.tarball({ noGitPlus: true }), | ||
expected('https://bitbucket.org/some-owner/some-repo/get/master.tar.gz', fixture.hasBranch), | ||
showLabel(fixture.label, 'tarball({ noGitPlus: true })') | ||
) | ||
tt.end() | ||
}) | ||
} | ||
} | ||
|
||
test('fromUrl(bitbucket url)', function (t) { | ||
var fixtures = require('./fixtures/bitbucket') | ||
// var gitlabFixtures = require('./fixtures/bitbucket') | ||
// var collectedFixtures = [].concat(fixtures, gitlabFixtures) | ||
|
||
t.test('domain: bitbucket.org', function (tt) { | ||
var params = { | ||
domain: 'bitbucket.org', | ||
shortname: 'bitbucket', | ||
label: 'bitbucket', | ||
owner: 'some-owner', | ||
project: 'some-repo', | ||
branch: 'feature-branch' | ||
} | ||
testFixtures(tt, params, fixtures) | ||
tt.end() | ||
}) | ||
|
||
t.test('domain: www.bitbucket.org', function (tt) { | ||
var params = { | ||
domain: 'www.bitbucket.org', | ||
shortname: 'bitbucket', | ||
label: 'bitbucket', | ||
owner: 'some-owner', | ||
project: 'some-repo', | ||
branch: 'feature-branch' | ||
} | ||
testFixtures(tt, params, fixtures) | ||
tt.end() | ||
}) | ||
|
||
require('./lib/standard-tests')(verify, 'bitbucket.org', 'bitbucket') | ||
require('./lib/standard-tests')(verify, 'www.bitbucket.org', 'bitbucket') | ||
t.test('Bitbucket HTTPS URLs with embedded auth', function (tt) { | ||
tt.is( | ||
HostedGit.fromUrl('https://user:[email protected]/user/repo.git').toString(), | ||
'git+https://user:[email protected]/user/repo.git', | ||
'credentials were included in URL' | ||
) | ||
tt.is( | ||
HostedGit.fromUrl('https://user:[email protected]/user/repo').toString(), | ||
'git+https://user:[email protected]/user/repo.git', | ||
'credentials were included in URL' | ||
) | ||
tt.is( | ||
HostedGit.fromUrl('git+https://user:[email protected]/user/repo.git').toString(), | ||
'git+https://user:[email protected]/user/repo.git', | ||
'credentials were included in URL' | ||
) | ||
tt.is( | ||
HostedGit.fromUrl('git+https://user:[email protected]/user/repo').toString(), | ||
'git+https://user:[email protected]/user/repo.git', | ||
'credentials were included in URL' | ||
) | ||
tt.end() | ||
}) | ||
|
||
t.end() | ||
}) |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could this be tested with a url where the host matches, but the path isn't a match? Like
https://github.com/isaacs
?Possibly I'm misreading this bit, and it is actually just a safety guard that never hits. But in that case, it'd be preferable to make that explicit.