-
Notifications
You must be signed in to change notification settings - Fork 79
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: support repositories within subgroups
- Loading branch information
Showing
6 changed files
with
110 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
const parsePath = require('parse-path'); | ||
const escapeStringRegexp = require('escape-string-regexp'); | ||
|
||
module.exports = (gitlabUrl, repositoryUrl) => { | ||
return parsePath(repositoryUrl) | ||
.pathname.replace(new RegExp(`^${escapeStringRegexp(parsePath(gitlabUrl).pathname)}`), '') | ||
.replace(/^\//, '') | ||
.replace(/\/$/, '') | ||
.replace(/\.git$/, ''); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import test from 'ava'; | ||
import getRepoId from '../lib/get-repo-id'; | ||
|
||
test('Parse repo id with https URL', t => { | ||
t.is(getRepoId('https://gitlbab.com', 'https://gitlab.com/owner/repo.git'), 'owner/repo'); | ||
t.is(getRepoId('https://gitlbab.com', 'https://gitlab.com/owner/repo'), 'owner/repo'); | ||
}); | ||
|
||
test('Parse repo id with git URL', t => { | ||
t.is(getRepoId('https://gitlab.com', 'git+ssh://git@gitlab.com/owner/repo.git'), 'owner/repo'); | ||
t.is(getRepoId('https://gitlab.com', 'git+ssh://git@gitlab.com/owner/repo'), 'owner/repo'); | ||
}); | ||
|
||
test('Parse repo id with context in repo URL', t => { | ||
t.is(getRepoId('https://gitlbab.com/context', 'https://gitlab.com/context/owner/repo.git'), 'owner/repo'); | ||
t.is(getRepoId('https://gitlab.com/context', 'git+ssh://git@gitlab.com/context/owner/repo.git'), 'owner/repo'); | ||
}); | ||
|
||
test('Parse repo id with context not in repo URL', t => { | ||
t.is(getRepoId('https://gitlbab.com/context', 'https://gitlab.com/owner/repo.git'), 'owner/repo'); | ||
t.is(getRepoId('https://gitlab.com/context', 'git+ssh://git@gitlab.com/owner/repo.git'), 'owner/repo'); | ||
}); | ||
|
||
test('Parse repo id with organization and subgroup', t => { | ||
t.is( | ||
getRepoId('https://gitlbab.com/context', 'https://gitlab.com/orga/subgroup/owner/repo.git'), | ||
'orga/subgroup/owner/repo' | ||
); | ||
t.is( | ||
getRepoId('https://gitlab.com/context', 'git+ssh://git@gitlab.com/orga/subgroup/owner/repo.git'), | ||
'orga/subgroup/owner/repo' | ||
); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters