diff --git a/README.md b/README.md index 8740406..cb30645 100644 --- a/README.md +++ b/README.md @@ -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` diff --git a/lib/git-host-info.js b/lib/git-host-info.js index cdc1e46..e2b70ae 100644 --- a/lib/git-host-info.js +++ b/lib/git-host-info.js @@ -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`, @@ -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') { @@ -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)) { @@ -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')) { @@ -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') { diff --git a/test/bitbucket.js b/test/bitbucket.js index 88795f4..d06e15b 100644 --- a/test/bitbucket.js +++ b/test/bitbucket.js @@ -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') diff --git a/test/gist.js b/test/gist.js index 09c8392..6bc3b4c 100644 --- a/test/gist.js +++ b/test/gist.js @@ -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') diff --git a/test/github.js b/test/github.js index 2a476a2..0bc9484 100644 --- a/test/github.js +++ b/test/github.js @@ -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') diff --git a/test/gitlab.js b/test/gitlab.js index be5187b..7173233 100644 --- a/test/gitlab.js +++ b/test/gitlab.js @@ -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')