Skip to content

Commit

Permalink
Merge pull request #55 from hutte-io/fix/parsing-bitbucket-server-url
Browse files Browse the repository at this point in the history
fix: parse Bitbucket Server Git URLs [HUT-2055]
  • Loading branch information
amtrack authored Jul 29, 2024
2 parents f975755 + aae0097 commit 87b993b
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
4 changes: 3 additions & 1 deletion src/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,9 @@ export function extractGithubRepoName(remoteUrl: string): string {
if (url.slice(-4) === '.git') {
url = url.slice(0, -4);
}
return url;
// the last two parts of the url path
const repoName = url.split('/').slice(-2).join('/');
return repoName;
}

export async function retryWithTimeout<T>(
Expand Down
17 changes: 15 additions & 2 deletions test/common.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { describe, it } from 'mocha';
import { expect } from 'chai';
import { retryWithTimeout } from '../src/common';
import { describe, it } from 'mocha';
import { extractGithubRepoName, retryWithTimeout } from '../src/common';

describe('common', () => {
describe('retryWithTimeout', () => {
Expand Down Expand Up @@ -72,4 +72,17 @@ describe('common', () => {
expect(i).to.equal(2);
});
});

describe('extractGithubRepoName', () => {
it('should parse a GitHub repo URL', () => {
expect(extractGithubRepoName('https://github.com/orgname/reponame.git')).to.deep.equal('orgname/reponame');
expect(extractGithubRepoName('[email protected]:orgname/reponame.git')).to.deep.equal('orgname/reponame');
});
it('should parse a Bitbucket Server repo URL', () => {
expect(extractGithubRepoName('https://git.example.org/scm/orgname/reponame.git')).to.deep.equal(
'orgname/reponame',
);
expect(extractGithubRepoName('ssh://[email protected]/orgname/reponame.git')).to.deep.equal('orgname/reponame');
});
});
});

0 comments on commit 87b993b

Please sign in to comment.