Skip to content

Commit

Permalink
Support for gitlab subgroups and self-hosted instances (#28)
Browse files Browse the repository at this point in the history
  • Loading branch information
a-ignatov-parc authored and cookpete committed Feb 20, 2018
1 parent 7b6a55e commit e80345a
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 6 deletions.
8 changes: 4 additions & 4 deletions src/commits.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ const MERGE_PATTERNS = [
/Merge pull request #(\d+) from .+\n\n(.+)/, // Regular GitHub merge
/^(.+) \(#(\d+)\)(?:$|\n\n)/, // Github squash merge
/Merged in .+ \(pull request #(\d+)\)\n\n(.+)/, // BitBucket merge
/Merge branch .+ into .+\n\n(.+)[\S\s]+See merge request !(\d+)/ // GitLab merge
/Merge branch .+ into .+\n\n(.+)[\S\s]+See merge request [^!]*!(\d+)/ // GitLab merge
]

export async function fetchCommits (remote, options) {
Expand Down Expand Up @@ -146,7 +146,7 @@ function getCommitLink (hash, remote) {
if (!remote) {
return null
}
if (remote.hostname === 'bitbucket.org') {
if (/bitbucket/.test(remote.hostname)) {
return `${remote.url}/commits/${hash}`
}
return `${remote.url}/commit/${hash}`
Expand All @@ -169,10 +169,10 @@ function getMergeLink (id, remote) {
if (!remote) {
return null
}
if (remote.hostname === 'bitbucket.org') {
if (/bitbucket/.test(remote.hostname)) {
return `${remote.url}/pull-requests/${id}`
}
if (remote.hostname === 'gitlab.com') {
if (/gitlab/.test(remote.hostname)) {
return `${remote.url}/merge_requests/${id}`
}
return `${remote.url}/pull/${id}`
Expand Down
2 changes: 1 addition & 1 deletion src/releases.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ function getCompareLink (from, to, remote) {
if (!remote) {
return null
}
if (remote.hostname === 'bitbucket.org') {
if (/bitbucket/.test(remote.hostname)) {
return `${remote.url}/compare/${to}%0D${from}`
}
return `${remote.url}/compare/${from}...${to}`
Expand Down
9 changes: 8 additions & 1 deletion src/remote.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,15 @@ export async function fetchRemote (name) {
const remote = parseRepoURL(remoteURL)
const protocol = remote.protocol === 'http:' ? 'http:' : 'https:'
const hostname = remote.hostname || remote.host
let repo = remote.repo

if (/gitlab/.test(hostname) && /\.git$/.test(remote.branch)) {
// Support gitlab subgroups
repo = `${remote.repo}/${remote.branch.replace(/\.git$/, '')}`
}

return {
hostname,
url: `${protocol}//${hostname}/${remote.repo}`
url: `${protocol}//${hostname}/${repo}`
}
}
13 changes: 13 additions & 0 deletions test/commits.js
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,19 @@ describe('getMerge', () => {
href: 'https://gitlab.com/user/repo/merge_requests/15007'
})
})

it('parses a merge for subgroups', () => {
const message = 'Merge branch \'branch\' into \'master\'\n\nMemoize GitLab logger to reduce open file descriptors\n\nCloses gitlab-ee#3664\n\nSee merge request user/repo/subgroup!15007'
const remote = {
hostname: 'gitlab.com',
url: 'https://gitlab.com/user/repo/subgroup'
}
expect(getMerge(message, remote)).to.deep.equal({
id: '15007',
message: 'Memoize GitLab logger to reduce open file descriptors',
href: 'https://gitlab.com/user/repo/subgroup/merge_requests/15007'
})
})
})

describe('BitBucket', () => {
Expand Down
14 changes: 14 additions & 0 deletions test/remote.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,20 @@ const TEST_DATA = [
remote: '[email protected]:user/repo.git',
expected: remotes.gitlab
},
{
remote: 'https://gitlab.com/user/repo/subgroup.git',
expected: {
hostname: 'gitlab.com',
url: 'https://gitlab.com/user/repo/subgroup'
}
},
{
remote: '[email protected]:user/repo/subgroup.git',
expected: {
hostname: 'gitlab.com',
url: 'https://gitlab.com/user/repo/subgroup'
}
},
{
remote: 'https://bitbucket.org/user/repo',
expected: remotes.bitbucket
Expand Down

0 comments on commit e80345a

Please sign in to comment.