Skip to content

Commit 87b993b

Browse files
authored
Merge pull request #55 from hutte-io/fix/parsing-bitbucket-server-url
fix: parse Bitbucket Server Git URLs [HUT-2055]
2 parents f975755 + aae0097 commit 87b993b

File tree

2 files changed

+18
-3
lines changed

2 files changed

+18
-3
lines changed

src/common.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,9 @@ export function extractGithubRepoName(remoteUrl: string): string {
8484
if (url.slice(-4) === '.git') {
8585
url = url.slice(0, -4);
8686
}
87-
return url;
87+
// the last two parts of the url path
88+
const repoName = url.split('/').slice(-2).join('/');
89+
return repoName;
8890
}
8991

9092
export async function retryWithTimeout<T>(

test/common.test.ts

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import { describe, it } from 'mocha';
21
import { expect } from 'chai';
3-
import { retryWithTimeout } from '../src/common';
2+
import { describe, it } from 'mocha';
3+
import { extractGithubRepoName, retryWithTimeout } from '../src/common';
44

55
describe('common', () => {
66
describe('retryWithTimeout', () => {
@@ -72,4 +72,17 @@ describe('common', () => {
7272
expect(i).to.equal(2);
7373
});
7474
});
75+
76+
describe('extractGithubRepoName', () => {
77+
it('should parse a GitHub repo URL', () => {
78+
expect(extractGithubRepoName('https://github.com/orgname/reponame.git')).to.deep.equal('orgname/reponame');
79+
expect(extractGithubRepoName('git@github.com:orgname/reponame.git')).to.deep.equal('orgname/reponame');
80+
});
81+
it('should parse a Bitbucket Server repo URL', () => {
82+
expect(extractGithubRepoName('https://git.example.org/scm/orgname/reponame.git')).to.deep.equal(
83+
'orgname/reponame',
84+
);
85+
expect(extractGithubRepoName('ssh://git@git.example.org/orgname/reponame.git')).to.deep.equal('orgname/reponame');
86+
});
87+
});
7588
});

0 commit comments

Comments
 (0)