From f0a259d0b0bea3b78e881e4497048dd8e9ab2e53 Mon Sep 17 00:00:00 2001 From: Shinyaigeek Date: Sat, 31 Dec 2022 14:59:50 +0900 Subject: [PATCH] Parse branch name with slash from https github URL --- git-host-info.js | 13 +++++++++++-- test/github.js | 2 ++ 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/git-host-info.js b/git-host-info.js index d4919344..8fdb1908 100644 --- a/git-host-info.js +++ b/git-host-info.js @@ -27,15 +27,24 @@ gitHosts.github = Object.assign({}, defaults, { 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'}`, extract: (url) => { - let [, user, project, type, committish] = url.pathname.split('/', 5) - if (type && type !== 'tree') { + let [, user, project, type, ...committish] = url.pathname.split('/') + + if (type && type !== 'tree' && type !== 'pull') { return } + if (type && type === 'pull' && committish.length > 0) { + committish = `pull/${committish[0]}/merge` + } + if (!type) { committish = url.hash.slice(1) } + if (Array.isArray(committish) && type === 'tree') { + committish = committish.join('/') + } + if (project && project.endsWith('.git')) { project = project.slice(0, -4) } diff --git a/test/github.js b/test/github.js index 0168e8c1..81631cb5 100644 --- a/test/github.js +++ b/test/github.js @@ -150,6 +150,8 @@ const valid = { 'git+https://github.com/foo/bar.git': { ...defaults, default: 'https' }, 'git+https://github.com/foo/bar.git#branch': { ...defaults, default: 'https', committish: 'branch' }, + 'git+https://github.com/foo/bar/tree/fix/patch': { ...defaults, default: 'https', committish: 'fix/patch' }, + 'git+https://github.com/foo/bar/pull/1': { ...defaults, default: 'https', committish: 'pull/1/merge' }, 'git+https://user@github.com/foo/bar.git': { ...defaults, default: 'https', auth: 'user' }, 'git+https://user@github.com/foo/bar.git#branch': { ...defaults, default: 'https', auth: 'user', committish: 'branch' }, 'git+https://user:password@github.com/foo/bar.git': { ...defaults, default: 'https', auth: 'user:password' },