Skip to content

Commit

Permalink
feat: try SSH keys before HTTPS for github packages without protocol (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
midgleyc authored Mar 12, 2021
1 parent 8cbb9fc commit 6eee8d7
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions lib/package-managers/gitTags.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,22 @@ const getSortedVersions = async (name, declaration, options) => {
// if present, github: is parsed as the protocol. This is not valid when passed into remote-git-tags.
declaration = declaration.replace(/^github:/, '')
const { auth, protocol, host, path } = parseGithubUrl(declaration)
const url = `${protocol ? protocol.replace('git+', '') : 'https:'}//${auth ? auth + '@' : ''}${host}/${path}`
let tagsPromise = Promise.resolve()
const protocolKnown = protocol != null
if (protocolKnown) {
tagsPromise = tagsPromise.then(() => remoteGitTags(`${protocol ? protocol.replace('git+', '') : 'https:'}//${auth ? auth + '@' : ''}${host}/${path}`))
}
else {
// try ssh first, then https on failure
tagsPromise = tagsPromise.then(() => remoteGitTags(`ssh://git@${host}/${path}`))
.catch(() => remoteGitTags(`https://${auth ? auth + '@' : ''}${host}/${path}`))
}

let tagMap = new Map()

// fetch remote tags
try {
tagMap = await remoteGitTags(url)
tagMap = await tagsPromise
}
// catch a variety of errors that occur on invalid or private repos
catch (e) {
Expand Down

0 comments on commit 6eee8d7

Please sign in to comment.