Skip to content
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

fix: support to github gist legacy hash length #68

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion git-host-info.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ var gitHosts = module.exports = {
gist: {
'protocols': [ 'git', 'git+ssh', 'git+https', 'ssh', 'https' ],
'domain': 'gist.github.com',
'pathmatch': /^[/](?:([^/]+)[/])?([a-z0-9]{32,})(?:[.]git)?$/,
'pathmatch': /^[/](?:([^/]+)[/])?([a-z0-9]{7,})(?:[.]git)?$/,
'filetemplate': 'https://gist.githubusercontent.com/{user}/{project}/raw{/committish}/{path}',
'bugstemplate': 'https://{domain}/{project}',
'gittemplate': 'git://{domain}/{project}.git{#committish}',
Expand Down
63 changes: 39 additions & 24 deletions test/gist.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ var testFixtures = function (t, params, fixtures) {
var fixture = fixtures[i]
var host = fixture.host(params)
var hostinfo = HostedGit.fromUrl(host)
var expectedHash = params.project

// INFO: from Url should return `undefined` from fixture input
if (fixture.isUndefined) {
Expand All @@ -27,18 +28,18 @@ var testFixtures = function (t, params, fixtures) {
}
tt.is(
hostinfo.https(),
expected('git+https://gist.github.com/a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2.git', fixture.hasBranch),
expected(`git+https://gist.github.com/${expectedHash}.git`, fixture.hasBranch),
showLabel(fixture.label, 'https')
)
tt.is(
hostinfo.https({ noCommittish: true }),
// INFO: not using `expected` because with `{noCommittish: true}` the output is always the same
'git+https://gist.github.com/a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2.git',
`git+https://gist.github.com/${expectedHash}.git`,
showLabel(fixture.label, 'https({ noCommittish: true })')
)
tt.is(
hostinfo.https({ noGitPlus: true }),
expected('https://gist.github.com/a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2.git', fixture.hasBranch),
expected(`https://gist.github.com/${expectedHash}.git`, fixture.hasBranch),
showLabel(fixture.label, 'https({ noGitPlus: true })')
)
tt.end()
Expand All @@ -51,18 +52,18 @@ var testFixtures = function (t, params, fixtures) {
}
tt.is(
hostinfo.git(),
expected('git://gist.github.com/a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2.git', fixture.hasBranch),
expected(`git://gist.github.com/${expectedHash}.git`, fixture.hasBranch),
showLabel(fixture.label, 'git')
)
tt.is(
hostinfo.git({ noCommittish: true }),
// INFO: not using `expected` because with `{noCommittish: true}` the output is always the same
'git://gist.github.com/a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2.git',
`git://gist.github.com/${expectedHash}.git`,
showLabel(fixture.label, 'git({ noCommittish: true })')
)
tt.is(
hostinfo.git({ noGitPlus: true }),
expected('git://gist.github.com/a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2.git', fixture.hasBranch),
expected(`git://gist.github.com/${expectedHash}.git`, fixture.hasBranch),
showLabel(fixture.label, 'git({ noGitPlus: true })')
)
tt.end()
Expand All @@ -75,35 +76,35 @@ var testFixtures = function (t, params, fixtures) {
}
tt.is(
hostinfo.browse(),
expected('https://gist.github.com/a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2', fixture.hasBranch),
expected(`https://gist.github.com/${expectedHash}`, fixture.hasBranch),
showLabel(fixture.label, 'browse')
)
tt.is(
hostinfo.browse('C'),
expected('https://gist.github.com/a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2', fixture.hasBranch) + '#file-c',
expected(`https://gist.github.com/${expectedHash}`, fixture.hasBranch) + '#file-c',
showLabel(fixture.label, "browse('C')")
)
tt.is(
hostinfo.browse('C/D'),
expected('https://gist.github.com/a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2', fixture.hasBranch) + '#file-cd',
expected(`https://gist.github.com/${expectedHash}`, fixture.hasBranch) + '#file-cd',
showLabel(fixture.label, "browse('C/D')")
)
tt.is(
hostinfo.browse('C', 'A'),
expected('https://gist.github.com/a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2', fixture.hasBranch) + '#file-c',
expected(`https://gist.github.com/${expectedHash}`, fixture.hasBranch) + '#file-c',
showLabel(fixture.label, "browse('C', 'A')")
)
tt.is(
hostinfo.browse('C/D', 'A'),
expected('https://gist.github.com/a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2', fixture.hasBranch) + '#file-cd',
expected(`https://gist.github.com/${expectedHash}`, fixture.hasBranch) + '#file-cd',
showLabel(fixture.label, "browse('C/D', 'A')")
)
tt.end()
})
t.test('hostinfo.bugs', function (tt) {
tt.is(
hostinfo.bugs(),
'https://gist.github.com/a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2',
`https://gist.github.com/${expectedHash}`,
showLabel(fixture.label, 'bugs')
)
tt.end()
Expand All @@ -116,7 +117,7 @@ var testFixtures = function (t, params, fixtures) {
}
tt.is(
hostinfo.docs(),
expected('https://gist.github.com/a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2', fixture.hasBranch),
expected(`https://gist.github.com/${expectedHash}`, fixture.hasBranch),
showLabel(fixture.label, 'docs')
)
tt.end()
Expand All @@ -129,7 +130,7 @@ var testFixtures = function (t, params, fixtures) {
}
tt.is(
hostinfo.ssh(),
expected('git@gist.github.com:/a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2.git', fixture.hasBranch),
expected(`git@gist.github.com:/${expectedHash}.git`, fixture.hasBranch),
showLabel(fixture.label, 'ssh')
)
tt.end()
Expand All @@ -142,7 +143,7 @@ var testFixtures = function (t, params, fixtures) {
}
tt.is(
hostinfo.sshurl(),
expected('git+ssh://git@gist.github.com/a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2.git', fixture.hasBranch),
expected(`git+ssh://git@gist.github.com/${expectedHash}.git`, fixture.hasBranch),
showLabel(fixture.label, 'sshurl')
)
tt.end()
Expand All @@ -155,7 +156,7 @@ var testFixtures = function (t, params, fixtures) {
}
tt.is(
hostinfo.shortcut(),
expected('gist:a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2', fixture.hasBranch),
expected(`gist:${expectedHash}`, fixture.hasBranch),
showLabel(fixture.label, 'shortcut')
)
tt.end()
Expand All @@ -169,27 +170,27 @@ var testFixtures = function (t, params, fixtures) {
}
tt.is(
hostinfo.file(),
expected('https://gist.githubusercontent.com/some-owner/a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2/raw/', fixture.hasBranch),
expected(`https://gist.githubusercontent.com/some-owner/${expectedHash}/raw/`, fixture.hasBranch),
showLabel(fixture.label, 'file')
)
tt.is(
hostinfo.file(''),
expected('https://gist.githubusercontent.com/some-owner/a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2/raw/', fixture.hasBranch),
expected(`https://gist.githubusercontent.com/some-owner/${expectedHash}/raw/`, fixture.hasBranch),
showLabel(fixture.label, "file('')")
)
tt.is(
hostinfo.file('C'),
expected('https://gist.githubusercontent.com/some-owner/a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2/raw/', fixture.hasBranch) + 'C',
expected(`https://gist.githubusercontent.com/some-owner/${expectedHash}/raw/`, fixture.hasBranch) + 'C',
showLabel(fixture.label, "file('C')")
)
tt.is(
hostinfo.file('C/D'),
expected('https://gist.githubusercontent.com/some-owner/a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2/raw/', fixture.hasBranch) + 'C/D',
expected(`https://gist.githubusercontent.com/some-owner/${expectedHash}/raw/`, fixture.hasBranch) + 'C/D',
showLabel(fixture.label, "file('C/D')")
)
tt.is(
hostinfo.file('C', 'A'),
expected('https://gist.githubusercontent.com/some-owner/a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2/raw/', fixture.hasBranch) + 'C',
expected(`https://gist.githubusercontent.com/some-owner/${expectedHash}/raw/`, fixture.hasBranch) + 'C',
showLabel(fixture.label, "file('C', 'A')")
)
tt.end()
Expand All @@ -202,12 +203,12 @@ var testFixtures = function (t, params, fixtures) {
}
tt.is(
hostinfo.tarball(),
expected('https://codeload.github.com/gist/a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2/tar.gz/master', fixture.hasBranch),
expected(`https://codeload.github.com/gist/${expectedHash}/tar.gz/master`, fixture.hasBranch),
showLabel(fixture.label, 'tarball')
)
tt.is(
hostinfo.tarball({ noCommittish: true }),
expected('https://codeload.github.com/gist/a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2/tar.gz/master', fixture.hasBranch),
expected(`https://codeload.github.com/gist/${expectedHash}/tar.gz/master`, fixture.hasBranch),
showLabel(fixture.label, 'tarball({ noCommittish: true })')
)
tt.end()
Expand All @@ -222,7 +223,7 @@ var testFixtures = function (t, params, fixtures) {
}
tt.is(
hostinfo.toString(),
expected('git+https://gist.github.com/a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2.git', fixture.hasBranch),
expected(`git+https://gist.github.com/${expectedHash}.git`, fixture.hasBranch),
showLabel(fixture.label, 'toString')
)
tt.end()
Expand All @@ -249,5 +250,19 @@ test('fromUrl(gist url)', function (t) {
tt.end()
})

t.test('legacy gist hash length', function (tt) {
var params = {
domain: 'gist.github.com',
shortname: 'github',
label: 'github',
owner: 'some-owner',
project: '3135914',
branch: 'feature-branch'
}

testFixtures(tt, params, collectedFixtures)
tt.end()
})

t.end()
})