Skip to content

Commit

Permalink
feat!: set default git ref to HEAD
Browse files Browse the repository at this point in the history
  • Loading branch information
darcyclarke authored and lukekarrys committed Oct 12, 2022
1 parent 61ca7fb commit 89155e8
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 26 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ provided to a method override those provided to the constructor.

Given the path of a file relative to the repository, returns a URL for
directly fetching it from the githost. If no committish was set then
`master` will be used as the default.
`HEAD` will be used as the default.

For example `hostedGitInfo.fromUrl("git@github.com:npm/hosted-git-info.git#v1.0.0").file("package.json")`
would return `https://raw.githubusercontent.com/npm/hosted-git-info/v1.0.0/package.json`
Expand Down
18 changes: 9 additions & 9 deletions lib/git-host-info.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ const maybeEncode = (arg) => arg ? encodeURIComponent(arg) : ''
const defaults = {
sshtemplate: ({ domain, user, project, committish }) => `git@${domain}:${user}/${project}.git${maybeJoin('#', committish)}`,
sshurltemplate: ({ domain, user, project, committish }) => `git+ssh://git@${domain}/${user}/${project}.git${maybeJoin('#', committish)}`,
edittemplate: ({ domain, user, project, committish, editpath, path }) => `https://${domain}/${user}/${project}${maybeJoin('/', editpath, '/', maybeEncode(committish || 'master'), '/', path)}`,
edittemplate: ({ domain, user, project, committish, editpath, path }) => `https://${domain}/${user}/${project}${maybeJoin('/', editpath, '/', maybeEncode(committish || 'HEAD'), '/', path)}`,
browsetemplate: ({ domain, user, project, committish, treepath }) => `https://${domain}/${user}/${project}${maybeJoin('/', treepath, '/', maybeEncode(committish))}`,
browsefiletemplate: ({ domain, user, project, committish, treepath, path, fragment, hashformat }) => `https://${domain}/${user}/${project}/${treepath}/${maybeEncode(committish || 'master')}/${path}${maybeJoin('#', hashformat(fragment || ''))}`,
browsefiletemplate: ({ domain, user, project, committish, treepath, path, fragment, hashformat }) => `https://${domain}/${user}/${project}/${treepath}/${maybeEncode(committish || 'HEAD')}/${path}${maybeJoin('#', hashformat(fragment || ''))}`,
docstemplate: ({ domain, user, project, treepath, committish }) => `https://${domain}/${user}/${project}${maybeJoin('/', treepath, '/', maybeEncode(committish))}#readme`,
httpstemplate: ({ auth, domain, user, project, committish }) => `git+https://${maybeJoin(auth, '@')}${domain}/${user}/${project}.git${maybeJoin('#', committish)}`,
filetemplate: ({ domain, user, project, committish, path }) => `https://${domain}/${user}/${project}/raw/${maybeEncode(committish) || 'master'}/${path}`,
filetemplate: ({ domain, user, project, committish, path }) => `https://${domain}/${user}/${project}/raw/${maybeEncode(committish) || 'HEAD'}/${path}`,
shortcuttemplate: ({ type, user, project, committish }) => `${type}:${user}/${project}${maybeJoin('#', committish)}`,
pathtemplate: ({ user, project, committish }) => `${user}/${project}${maybeJoin('#', committish)}`,
bugstemplate: ({ domain, user, project }) => `https://${domain}/${user}/${project}/issues`,
Expand All @@ -26,9 +26,9 @@ gitHosts.github = Object.assign({}, defaults, {
domain: 'github.com',
treepath: 'tree',
editpath: 'edit',
filetemplate: ({ auth, user, project, committish, path }) => `https://${maybeJoin(auth, '@')}raw.githubusercontent.com/${user}/${project}/${maybeEncode(committish) || 'master'}/${path}`,
filetemplate: ({ auth, user, project, committish, path }) => `https://${maybeJoin(auth, '@')}raw.githubusercontent.com/${user}/${project}/${maybeEncode(committish) || 'HEAD'}/${path}`,
gittemplate: ({ auth, domain, user, project, committish }) => `git://${maybeJoin(auth, '@')}${domain}/${user}/${project}.git${maybeJoin('#', committish)}`,
tarballtemplate: ({ domain, user, project, committish }) => `https://codeload.${domain}/${user}/${project}/tar.gz/${maybeEncode(committish) || 'master'}`,
tarballtemplate: ({ domain, user, project, committish }) => `https://codeload.${domain}/${user}/${project}/tar.gz/${maybeEncode(committish) || 'HEAD'}`,
extract: (url) => {
let [, user, project, type, committish] = url.pathname.split('/', 5)
if (type && type !== 'tree') {
Expand Down Expand Up @@ -56,8 +56,8 @@ gitHosts.bitbucket = Object.assign({}, defaults, {
domain: 'bitbucket.org',
treepath: 'src',
editpath: '?mode=edit',
edittemplate: ({ domain, user, project, committish, treepath, path, editpath }) => `https://${domain}/${user}/${project}${maybeJoin('/', treepath, '/', maybeEncode(committish || 'master'), '/', path, editpath)}`,
tarballtemplate: ({ domain, user, project, committish }) => `https://${domain}/${user}/${project}/get/${maybeEncode(committish) || 'master'}.tar.gz`,
edittemplate: ({ domain, user, project, committish, treepath, path, editpath }) => `https://${domain}/${user}/${project}${maybeJoin('/', treepath, '/', maybeEncode(committish || 'HEAD'), '/', path, editpath)}`,
tarballtemplate: ({ domain, user, project, committish }) => `https://${domain}/${user}/${project}/get/${maybeEncode(committish) || 'HEAD'}.tar.gz`,
extract: (url) => {
let [, user, project, aux] = url.pathname.split('/', 4)
if (['get'].includes(aux)) {
Expand All @@ -82,7 +82,7 @@ gitHosts.gitlab = Object.assign({}, defaults, {
treepath: 'tree',
editpath: '-/edit',
httpstemplate: ({ auth, domain, user, project, committish }) => `git+https://${maybeJoin(auth, '@')}${domain}/${user}/${project}.git${maybeJoin('#', committish)}`,
tarballtemplate: ({ domain, user, project, committish }) => `https://${domain}/${user}/${project}/repository/archive.tar.gz?ref=${maybeEncode(committish) || 'master'}`,
tarballtemplate: ({ domain, user, project, committish }) => `https://${domain}/${user}/${project}/repository/archive.tar.gz?ref=${maybeEncode(committish) || 'HEAD'}`,
extract: (url) => {
const path = url.pathname.slice(1)
if (path.includes('/-/') || path.includes('/archive.tar.gz')) {
Expand Down Expand Up @@ -120,7 +120,7 @@ gitHosts.gist = Object.assign({}, defaults, {
pathtemplate: ({ project, committish }) => `${project}${maybeJoin('#', committish)}`,
bugstemplate: ({ domain, project }) => `https://${domain}/${project}`,
gittemplate: ({ domain, project, committish }) => `git://${domain}/${project}.git${maybeJoin('#', committish)}`,
tarballtemplate: ({ project, committish }) => `https://codeload.github.com/gist/${project}/tar.gz/${maybeEncode(committish) || 'master'}`,
tarballtemplate: ({ project, committish }) => `https://codeload.github.com/gist/${project}/tar.gz/${maybeEncode(committish) || 'HEAD'}`,
extract: (url) => {
let [, user, project, aux] = url.pathname.split('/', 4)
if (aux === 'raw') {
Expand Down
10 changes: 5 additions & 5 deletions test/bitbucket.js
Original file line number Diff line number Diff line change
Expand Up @@ -184,15 +184,15 @@ t.test('string methods populate correctly', t => {
t.equal(parsed.edit(), 'https://bitbucket.org/foo/bar')
t.equal(parsed.edit('/lib/index.js'), 'https://bitbucket.org/foo/bar/src/master/lib/index.js?mode=edit')
t.equal(parsed.browse(), 'https://bitbucket.org/foo/bar')
t.equal(parsed.browse('/lib/index.js'), 'https://bitbucket.org/foo/bar/src/master/lib/index.js')
t.equal(parsed.browse('/lib/index.js', 'L100'), 'https://bitbucket.org/foo/bar/src/master/lib/index.js#l100')
t.equal(parsed.browse('/lib/index.js'), 'https://bitbucket.org/foo/bar/src/HEAD/lib/index.js')
t.equal(parsed.browse('/lib/index.js', 'L100'), 'https://bitbucket.org/foo/bar/src/HEAD/lib/index.js#l100')
t.equal(parsed.docs(), 'https://bitbucket.org/foo/bar#readme')
t.equal(parsed.https(), 'git+https://bitbucket.org/foo/bar.git')
t.equal(parsed.shortcut(), 'bitbucket:foo/bar')
t.equal(parsed.path(), 'foo/bar')
t.equal(parsed.tarball(), 'https://bitbucket.org/foo/bar/get/master.tar.gz')
t.equal(parsed.file(), 'https://bitbucket.org/foo/bar/raw/master/')
t.equal(parsed.file('/lib/index.js'), 'https://bitbucket.org/foo/bar/raw/master/lib/index.js')
t.equal(parsed.tarball(), 'https://bitbucket.org/foo/bar/get/HEAD.tar.gz')
t.equal(parsed.file(), 'https://bitbucket.org/foo/bar/raw/HEAD/')
t.equal(parsed.file('/lib/index.js'), 'https://bitbucket.org/foo/bar/raw/HEAD/lib/index.js')
t.equal(parsed.bugs(), 'https://bitbucket.org/foo/bar/issues')

t.equal(parsed.docs({ committish: 'fix/bug' }), 'https://bitbucket.org/foo/bar/src/fix%2Fbug#readme', 'allows overriding options')
Expand Down
2 changes: 1 addition & 1 deletion test/gist.js
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,7 @@ t.test('string methods populate correctly', t => {
t.equal(parsed.https(), 'git+https://gist.github.com/feedbeef.git')
t.equal(parsed.shortcut(), 'gist:feedbeef')
t.equal(parsed.path(), 'feedbeef')
t.equal(parsed.tarball(), 'https://codeload.github.com/gist/feedbeef/tar.gz/master')
t.equal(parsed.tarball(), 'https://codeload.github.com/gist/feedbeef/tar.gz/HEAD')
t.equal(parsed.file(), 'https://gist.githubusercontent.com/foo/feedbeef/raw/')
t.equal(parsed.file('/lib/index.js'), 'https://gist.githubusercontent.com/foo/feedbeef/raw/lib/index.js')
t.equal(parsed.git(), 'git://gist.github.com/feedbeef.git')
Expand Down
10 changes: 5 additions & 5 deletions test/github.js
Original file line number Diff line number Diff line change
Expand Up @@ -238,15 +238,15 @@ t.test('string methods populate correctly', t => {
t.equal(parsed.edit('/lib/index.js'), 'https://github.com/foo/bar/edit/master/lib/index.js')
t.equal(parsed.edit('/lib/index.js', { committish: 'docs' }), 'https://github.com/foo/bar/edit/docs/lib/index.js')
t.equal(parsed.browse(), 'https://github.com/foo/bar')
t.equal(parsed.browse('/lib/index.js'), 'https://github.com/foo/bar/tree/master/lib/index.js')
t.equal(parsed.browse('/lib/index.js', 'L100'), 'https://github.com/foo/bar/tree/master/lib/index.js#l100')
t.equal(parsed.browse('/lib/index.js'), 'https://github.com/foo/bar/tree/HEAD/lib/index.js')
t.equal(parsed.browse('/lib/index.js', 'L100'), 'https://github.com/foo/bar/tree/HEAD/lib/index.js#l100')
t.equal(parsed.docs(), 'https://github.com/foo/bar#readme')
t.equal(parsed.https(), 'git+https://github.com/foo/bar.git')
t.equal(parsed.shortcut(), 'github:foo/bar')
t.equal(parsed.path(), 'foo/bar')
t.equal(parsed.tarball(), 'https://codeload.github.com/foo/bar/tar.gz/master')
t.equal(parsed.file(), 'https://raw.githubusercontent.com/foo/bar/master/')
t.equal(parsed.file('/lib/index.js'), 'https://raw.githubusercontent.com/foo/bar/master/lib/index.js')
t.equal(parsed.tarball(), 'https://codeload.github.com/foo/bar/tar.gz/HEAD')
t.equal(parsed.file(), 'https://raw.githubusercontent.com/foo/bar/HEAD/')
t.equal(parsed.file('/lib/index.js'), 'https://raw.githubusercontent.com/foo/bar/HEAD/lib/index.js')
t.equal(parsed.git(), 'git://github.com/foo/bar.git')
t.equal(parsed.bugs(), 'https://github.com/foo/bar/issues')

Expand Down
10 changes: 5 additions & 5 deletions test/gitlab.js
Original file line number Diff line number Diff line change
Expand Up @@ -290,15 +290,15 @@ t.test('string methods populate correctly', t => {
t.equal(parsed.edit(), 'https://gitlab.com/foo/bar')
t.equal(parsed.edit('/lib/index.js'), 'https://gitlab.com/foo/bar/-/edit/master/lib/index.js')
t.equal(parsed.browse(), 'https://gitlab.com/foo/bar')
t.equal(parsed.browse('/lib/index.js'), 'https://gitlab.com/foo/bar/tree/master/lib/index.js')
t.equal(parsed.browse('/lib/index.js', 'L100'), 'https://gitlab.com/foo/bar/tree/master/lib/index.js#l100')
t.equal(parsed.browse('/lib/index.js'), 'https://gitlab.com/foo/bar/tree/HEAD/lib/index.js')
t.equal(parsed.browse('/lib/index.js', 'L100'), 'https://gitlab.com/foo/bar/tree/HEAD/lib/index.js#l100')
t.equal(parsed.docs(), 'https://gitlab.com/foo/bar#readme')
t.equal(parsed.https(), 'git+https://gitlab.com/foo/bar.git')
t.equal(parsed.shortcut(), 'gitlab:foo/bar')
t.equal(parsed.path(), 'foo/bar')
t.equal(parsed.tarball(), 'https://gitlab.com/foo/bar/repository/archive.tar.gz?ref=master')
t.equal(parsed.file(), 'https://gitlab.com/foo/bar/raw/master/')
t.equal(parsed.file('/lib/index.js'), 'https://gitlab.com/foo/bar/raw/master/lib/index.js')
t.equal(parsed.tarball(), 'https://gitlab.com/foo/bar/repository/archive.tar.gz?ref=HEAD')
t.equal(parsed.file(), 'https://gitlab.com/foo/bar/raw/HEAD/')
t.equal(parsed.file('/lib/index.js'), 'https://gitlab.com/foo/bar/raw/HEAD/lib/index.js')
t.equal(parsed.bugs(), 'https://gitlab.com/foo/bar/issues')

t.same(parsed.git(), null, 'git() returns null')
Expand Down

0 comments on commit 89155e8

Please sign in to comment.