diff --git a/src/main/azure-devops/repository-ref.test.ts b/src/main/azure-devops/repository-ref.test.ts index 910a9c032..92e738afb 100644 --- a/src/main/azure-devops/repository-ref.test.ts +++ b/src/main/azure-devops/repository-ref.test.ts @@ -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', diff --git a/src/main/azure-devops/repository-ref.ts b/src/main/azure-devops/repository-ref.ts index 981af6b9b..56baaa4e8 100644 --- a/src/main/azure-devops/repository-ref.ts +++ b/src/main/azure-devops/repository-ref.ts @@ -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()) diff --git a/src/main/bitbucket/repository-ref.test.ts b/src/main/bitbucket/repository-ref.test.ts index 8b8d6a750..bc277b832 100644 --- a/src/main/bitbucket/repository-ref.test.ts +++ b/src/main/bitbucket/repository-ref.test.ts @@ -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', diff --git a/src/main/bitbucket/repository-ref.ts b/src/main/bitbucket/repository-ref.ts index de50b98ca..e69956759 100644 --- a/src/main/bitbucket/repository-ref.ts +++ b/src/main/bitbucket/repository-ref.ts @@ -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()) diff --git a/src/main/gitea/repository-ref.test.ts b/src/main/gitea/repository-ref.test.ts index 36bcf87bd..a104208d1 100644 --- a/src/main/gitea/repository-ref.test.ts +++ b/src/main/gitea/repository-ref.test.ts @@ -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', diff --git a/src/main/gitea/repository-ref.ts b/src/main/gitea/repository-ref.ts index f8063e1c9..08dfd7108 100644 --- a/src/main/gitea/repository-ref.ts +++ b/src/main/gitea/repository-ref.ts @@ -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())