Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion src/remote.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,23 @@ const getRemote = (remoteURL, options = {}) => {
const protocol = remote.protocol === 'http:' ? 'http:' : 'https:'
const hostname = remote.hostname || remote.host

const IS_GITHUB = /github\.com/.test(hostname)
const IS_BITBUCKET = /bitbucket/.test(hostname)
const IS_GITLAB = /gitlab/.test(hostname)
const IS_AZURE = /dev\.azure/.test(hostname)
const IS_VISUAL_STUDIO = /visualstudio/.test(hostname)

if (IS_GITHUB) {
const url = `${protocol}//${hostname}/${remote.repo}`
return {
getCommitLink: id => `${url}/commit/${id}`,
getIssueLink: id => `${url}/issues/${id}`,
getMergeLink: id => `${url}/pull/${id}`,
getCompareLink: (from, to) => `${url}/compare/${from}...${to}`,
...overrides
}
}

if (IS_BITBUCKET) {
const url = `${protocol}//${hostname}/${remote.repo}`
return {
Expand Down Expand Up @@ -68,7 +80,8 @@ const getRemote = (remoteURL, options = {}) => {
}
}

const url = `${protocol}//${hostname}/${remote.repo}`
// Generic fallback for unknown platforms (GitHub Enterprise, custom GitLab instances, etc.)
const url = `${protocol}//${hostname}/${remote.pathname.replace(/git@.*:/, '').replace(/\.git$/, '')}`
return {
getCommitLink: id => `${url}/commit/${id}`,
getIssueLink: id => `${url}/issues/${id}`,
Expand Down
46 changes: 46 additions & 0 deletions test/remote.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,52 @@ const TEST_DATA = [
compare: 'https://gitlab.com/user/repo/group/repo/compare/v1.2.3...v2.0.0'
}
},
{
remotes: [
'https://git.example.com/foo/bar/baz/project.git',
'[email protected]:foo/bar/baz/project.git'
],
expected: {
commit: 'https://git.example.com/foo/bar/baz/project/commit/123',
issue: 'https://git.example.com/foo/bar/baz/project/issues/123',
merge: 'https://git.example.com/foo/bar/baz/project/pull/123',
compare: 'https://git.example.com/foo/bar/baz/project/compare/v1.2.3...v2.0.0'
}
},
{
remotes: [
'http://git.example.com/foo/bar/baz/project.git'
],
expected: {
commit: 'http://git.example.com/foo/bar/baz/project/commit/123',
issue: 'http://git.example.com/foo/bar/baz/project/issues/123',
merge: 'http://git.example.com/foo/bar/baz/project/pull/123',
compare: 'http://git.example.com/foo/bar/baz/project/compare/v1.2.3...v2.0.0'
}
},
{
remotes: [
'https://github.company.com/user/repo.git',
'[email protected]:user/repo.git'
],
expected: {
commit: 'https://github.company.com/user/repo/commit/123',
issue: 'https://github.company.com/user/repo/issues/123',
merge: 'https://github.company.com/user/repo/pull/123',
compare: 'https://github.company.com/user/repo/compare/v1.2.3...v2.0.0'
}
},
{
remotes: [
'https://gitlab.company.com/team/subteam/project.git'
],
expected: {
commit: 'https://gitlab.company.com/team/subteam/project/commit/123',
issue: 'https://gitlab.company.com/team/subteam/project/issues/123',
merge: 'https://gitlab.company.com/team/subteam/project/merge_requests/123',
compare: 'https://gitlab.company.com/team/subteam/project/compare/v1.2.3...v2.0.0'
}
},
{
remotes: [
'https://bitbucket.org/user/repo',
Expand Down