forked from cookpete/auto-changelog
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathremote.js
133 lines (129 loc) · 4.59 KB
/
remote.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
const { describe, it } = require('mocha')
const { expect } = require('chai')
const {
fetchRemote,
__Rewire__: mock,
__ResetDependency__: unmock
} = require('../src/remote')
const TEST_DATA = [
{
remotes: [
'http://github.com/user/repo'
],
expected: {
commit: 'http://github.com/user/repo/commit/123',
issue: 'http://github.com/user/repo/issues/123',
merge: 'http://github.com/user/repo/pull/123',
compare: 'http://github.com/user/repo/compare/v1.2.3...v2.0.0'
}
},
{
remotes: [
'https://github.com/user/repo',
'https://github.com:8080/user/repo',
'git@github.com:user/repo.git'
],
expected: {
commit: 'https://github.com/user/repo/commit/123',
issue: 'https://github.com/user/repo/issues/123',
merge: 'https://github.com/user/repo/pull/123',
compare: 'https://github.com/user/repo/compare/v1.2.3...v2.0.0'
}
},
{
remotes: [
'https://gitlab.com/user/repo',
'git@gitlab.com:user/repo.git'
],
expected: {
commit: 'https://gitlab.com/user/repo/commit/123',
issue: 'https://gitlab.com/user/repo/issues/123',
merge: 'https://gitlab.com/user/repo/merge_requests/123',
compare: 'https://gitlab.com/user/repo/compare/v1.2.3...v2.0.0'
}
},
{
remotes: [
'https://gitlab.com/user/repo/subgroup.git',
'git@gitlab.com:user/repo/subgroup.git'
],
expected: {
commit: 'https://gitlab.com/user/repo/subgroup/commit/123',
issue: 'https://gitlab.com/user/repo/subgroup/issues/123',
merge: 'https://gitlab.com/user/repo/subgroup/merge_requests/123',
compare: 'https://gitlab.com/user/repo/subgroup/compare/v1.2.3...v2.0.0'
}
},
{
remotes: [
'https://bitbucket.org/user/repo',
'git@bitbucket.org:user/repo.git'
],
expected: {
commit: 'https://bitbucket.org/user/repo/commits/123',
issue: 'https://bitbucket.org/user/repo/issues/123',
merge: 'https://bitbucket.org/user/repo/pull-requests/123',
compare: 'https://bitbucket.org/user/repo/compare/v2.0.0..v1.2.3'
}
},
{
remotes: [
'https://dev.azure.com/user/project/_git/repo'
],
expected: {
commit: 'https://dev.azure.com/user/project/_git/repo/commit/123',
issue: 'https://dev.azure.com/user/project/_workitems/edit/123',
merge: 'https://dev.azure.com/user/project/_git/repo/pullrequest/123',
compare: 'https://dev.azure.com/user/project/_git/repo/branches?baseVersion=GTv2.0.0&targetVersion=GTv1.2.3&_a=commits'
}
},
{
remotes: [
'https://user.visualstudio.com/project/_git/repo'
],
expected: {
commit: 'https://user.visualstudio.com/project/_git/repo/commit/123',
issue: 'https://user.visualstudio.com/project/_workitems/edit/123',
merge: 'https://user.visualstudio.com/project/_git/repo/pullrequest/123',
compare: 'https://user.visualstudio.com/project/_git/repo/branches?baseVersion=GTv2.0.0&targetVersion=GTv1.2.3&_a=commits'
}
}
]
describe('fetchRemote', () => {
for (const { remotes, expected } of TEST_DATA) {
for (const remote of remotes) {
it(`parses ${remote}`, async () => {
mock('cmd', () => remote)
const result = await fetchRemote({})
expect(result.getCommitLink('123')).to.equal(expected.commit)
expect(result.getIssueLink('123')).to.equal(expected.issue)
expect(result.getMergeLink('123')).to.equal(expected.merge)
expect(result.getCompareLink('v1.2.3', 'v2.0.0')).to.equal(expected.compare)
unmock('cmd')
})
}
}
it('supports overrides', async () => {
mock('cmd', () => '')
const result = await fetchRemote({
commitUrl: 'https://example.com/commit/{id}',
issueUrl: 'https://example.com/issue/{id}',
mergeUrl: 'https://example.com/merge/{id}',
compareUrl: 'https://example.com/compare/{from}-{to}'
})
expect(result.getCommitLink('123')).to.equal('https://example.com/commit/123')
expect(result.getIssueLink('123')).to.equal('https://example.com/issue/123')
expect(result.getMergeLink('123')).to.equal('https://example.com/merge/123')
expect(result.getCompareLink('v1.2.3', 'v2.0.0')).to.equal('https://example.com/compare/v1.2.3-v2.0.0')
unmock('cmd')
})
it('returns null functions', async () => {
mock('cmd', () => '')
const result = await fetchRemote({})
expect(result.getCommitLink('123')).to.equal(null)
expect(result.getIssueLink('123')).to.equal(null)
expect(result.getMergeLink('123')).to.equal(null)
expect(result.getCompareLink('v1.2.3', 'v2.0.0')).to.equal(null)
unmock('cmd')
})
})