fix: normalize provider remote git suffixes (#4286)

This commit is contained in:
Neil
2026-05-31 11:02:56 -07:00
committed by GitHub
parent e28894f581
commit 439371899f
6 changed files with 48 additions and 2 deletions
@@ -37,6 +37,25 @@ describe('parseAzureDevOpsRepoRef', () => {
})
})
it('strips trailing slashes after .git suffixes', () => {
expect(parseAzureDevOpsRepoRef('https://dev.azure.com/acme/Project/_git/repo.git/')).toEqual({
host: 'dev.azure.com',
organization: 'acme',
project: 'Project',
repository: 'repo',
apiBaseUrl: 'https://dev.azure.com/acme/Project',
webBaseUrl: 'https://dev.azure.com/acme/Project/_git/repo'
})
expect(parseAzureDevOpsRepoRef('git@ssh.dev.azure.com:v3/acme/Project/repo.git/')).toEqual({
host: 'dev.azure.com',
organization: 'acme',
project: 'Project',
repository: 'repo',
apiBaseUrl: 'https://dev.azure.com/acme/Project',
webBaseUrl: 'https://dev.azure.com/acme/Project/_git/repo'
})
})
it('parses legacy visualstudio.com HTTPS remotes', () => {
expect(parseAzureDevOpsRepoRef('https://acme.visualstudio.com/Project/_git/repo.git')).toEqual({
host: 'acme.visualstudio.com',
+1
View File
@@ -48,6 +48,7 @@ function encodeSegment(value: string): string {
function splitPath(path: string): string[] {
return path
.replace(/\/+$/, '')
.replace(/\.git$/i, '')
.split('/')
.map((part) => part.trim())
+11
View File
@@ -46,6 +46,17 @@ describe('Bitbucket repository refs', () => {
expect(parseBitbucketRepoRef('https://github.com/team/project.git')).toBeNull()
})
it('strips trailing slashes after .git suffixes', () => {
expect(parseBitbucketRepoRef('https://bitbucket.org/team/project.git/')).toEqual({
workspace: 'team',
repoSlug: 'project'
})
expect(parseBitbucketRepoRef('git@bitbucket.org:team/project.git/')).toEqual({
workspace: 'team',
repoSlug: 'project'
})
})
it('keeps malformed percent sequences as literal repo path text', async () => {
expect(parseBitbucketRepoRef('git@bitbucket.org:team/project%zz.git')).toEqual({
workspace: 'team',
+1 -1
View File
@@ -39,7 +39,7 @@ function decodeSegment(value: string): string {
}
function parseBitbucketPath(pathname: string): BitbucketRepoRef | null {
const withoutSuffix = pathname.replace(/\.git$/i, '')
const withoutSuffix = pathname.replace(/\/+$/, '').replace(/\.git$/i, '')
const parts = withoutSuffix
.split('/')
.map((part) => part.trim())
+15
View File
@@ -40,6 +40,21 @@ describe('Gitea repository ref parsing', () => {
})
})
it('strips trailing slashes after .git suffixes', () => {
expect(parseGiteaRepoRef('https://git.example.com/team/project.git/')).toEqual({
host: 'git.example.com',
owner: 'team',
repo: 'project',
apiBaseUrl: 'https://git.example.com/api/v1',
webBaseUrl: 'https://git.example.com'
})
expect(parseGiteaRepoRef('git@gitea.example.test:team/project.git/')).toMatchObject({
host: 'gitea.example.test',
owner: 'team',
repo: 'project'
})
})
it('preserves an HTTP subpath when deriving the API base URL', () => {
expect(parseGiteaRepoRef('https://git.example.com/code/team/project.git')).toEqual({
host: 'git.example.com',
+1 -1
View File
@@ -49,7 +49,7 @@ function decodeSegment(value: string): string {
}
function parsePath(pathname: string): { owner: string; repo: string; basePath: string } | null {
const withoutSuffix = pathname.replace(/\.git$/i, '')
const withoutSuffix = pathname.replace(/\/+$/, '').replace(/\.git$/i, '')
const parts = withoutSuffix
.split('/')
.map((part) => part.trim())