Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for azure devops and visualstudio.com #72

Merged
merged 8 commits into from
Nov 8, 2018
Merged
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
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ auto-changelog --commit-limit 5
auto-changelog --commit-limit false
```

By default, changelogs will link to the appropriate pages for commits, issues and merge requests based on the `origin` remote of your repo. GitHub, BitBucket and GitLab are all supported. If you [close issues using keywords](https://help.github.com/articles/closing-issues-using-keywords) but refer to issues outside of your repository, you can use `--issue-url` to link somewhere else:
By default, changelogs will link to the appropriate pages for commits, issues and merge requests based on the `origin` remote of your repo. GitHub, GitLab, BitBucket and Azure DevOps are all supported. If you [close issues using keywords](https://help.github.com/articles/closing-issues-using-keywords) but refer to issues outside of your repository, you can use `--issue-url` to link somewhere else:

```bash
# Link all issues to redmine
Expand Down
6 changes: 6 additions & 0 deletions src/commits.js
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,9 @@ function getIssueLink (match, id, remote, issueUrl) {
if (issueUrl) {
return issueUrl.replace('{id}', id)
}
if (/dev\.azure/.test(remote.hostname) || /visualstudio/.test(remote.hostname)) {
return `${remote.projectUrl}/_workitems/edit/${id}`
}
return `${remote.url}/issues/${id}`
}

Expand All @@ -185,5 +188,8 @@ function getMergeLink (id, remote) {
if (/gitlab/.test(remote.hostname)) {
return `${remote.url}/merge_requests/${id}`
}
if (/dev\.azure/.test(remote.hostname) || /visualstudio/.test(remote.hostname)) {
return `${remote.url}/pullrequest/${id}`
}
return `${remote.url}/pull/${id}`
}
3 changes: 3 additions & 0 deletions src/releases.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,9 @@ function getCompareLink (from, to, remote) {
if (/bitbucket/.test(remote.hostname)) {
return `${remote.url}/compare/${to}..${from}`
}
if (/dev\.azure/.test(remote.hostname) || /visualstudio/.test(remote.hostname)) {
return `${remote.url}/branches?baseVersion=GT${to}&targetVersion=GT${from}&_a=commits`
}
return `${remote.url}/compare/${from}...${to}`
}

Expand Down
24 changes: 21 additions & 3 deletions src/remote.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,33 @@ 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}/${remote.branch.replace(/\.git$/, '')}`
}
}

if (/dev\.azure/.test(hostname)) {
return {
hostname,
url: `${protocol}//${hostname}/${remote.path}`,
projectUrl: `${protocol}//${hostname}/${remote.repo}`
}
}

if (/visualstudio/.test(hostname)) {
return {
hostname,
url: `${protocol}//${hostname}/${remote.repo}/${remote.branch}`,
projectUrl: `${protocol}//${hostname}/${remote.owner}`
}
}

return {
hostname,
url: `${protocol}//${hostname}/${repo}`
url: `${protocol}//${hostname}/${remote.repo}`
}
}
10 changes: 10 additions & 0 deletions test/data/remotes.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,15 @@ export default {
bitbucket: {
hostname: 'bitbucket.org',
url: 'https://bitbucket.org/user/repo'
},
azure: {
hostname: 'dev.azure.com',
url: 'https://dev.azure.com/user/project/_git/repo',
projectUrl: 'https://dev.azure.com/user/project'
},
visualstudio: {
hostname: 'user.visualstudio.com',
url: 'https://user.visualstudio.com/project/_git/repo',
projectUrl: 'https://user.visualstudio.com/project'
}
}
10 changes: 9 additions & 1 deletion test/remote.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,14 +49,22 @@ const TEST_DATA = [
{
remote: '[email protected]:user/repo.git',
expected: remotes.bitbucket
},
{
remote: 'https://dev.azure.com/user/project/_git/repo',
expected: remotes.azure
},
{
remote: 'https://user.visualstudio.com/project/_git/repo',
expected: remotes.visualstudio
}
]

describe('fetchRemote', () => {
for (let test of TEST_DATA) {
it(`parses ${test.remote}`, async () => {
mock('cmd', () => test.remote)
expect(await fetchRemote('origin')).to.include(test.expected)
expect(await fetchRemote('origin')).to.deep.equal(test.expected)
unmock('cmd')
})
}
Expand Down