Skip to content

Commit 5cf5bd3

Browse files
fix(autolinks): mark autolink as changed when url template changes (#13)
* fix(autolinks): mark autolink as changed when url template changes * fixup! fix(autolinks): mark autolink as changed when url template changes * fixup! fix(autolinks): mark autolink as changed when url template changes
1 parent 1a9e70a commit 5cf5bd3

File tree

3 files changed

+55
-6
lines changed

3 files changed

+55
-6
lines changed

lib/mergeDeep.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ class MergeDeep {
9898
for (const key in source) {
9999
// Logic specific for Github
100100
// API response includes urls for resources, or other ignorable fields; we can ignore them
101-
if (key.indexOf('url') >= 0 || this.ignorableFields.indexOf(key) >= 0) {
101+
if ((key.indexOf('url') >= 0 && key != "url_template") || this.ignorableFields.indexOf(key) >= 0) {
102102
continue
103103
}
104104
const sourceValue = source[key]

test/unit/lib/mergeDeep.test.js

Lines changed: 40 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -844,7 +844,7 @@ entries:
844844
const target = YAML.load(`
845845
entries:
846846
- key_prefix: ASDF-
847-
url_template: https://jiranew.company.com/browse/ASDF-<num>
847+
url_template: https://jira.company.com/browse/ASDF-<num>
848848
- key_prefix: BOLSIGRAFO-
849849
url_template: https://jira.company.com/browse/BOLIGRAFO-<num>
850850
`)
@@ -857,8 +857,7 @@ entries:
857857
}
858858
]
859859
},
860-
modifications: {
861-
},
860+
modifications: {},
862861
deletions: {
863862
entries: [ {
864863
key_prefix: "BOLSIGRAFO-",
@@ -881,6 +880,44 @@ entries:
881880
expect(merged).toEqual(expected)
882881
})
883882

883+
it('Autolinks different url template', () => {
884+
const source = YAML.load(`
885+
entries:
886+
- key_prefix: ASDF-
887+
url_template: https://jiranew.company.com/browse/ASDF-<num>
888+
`)
889+
const target = YAML.load(`
890+
entries:
891+
- key_prefix: ASDF-
892+
url_template: https://jira.company.com/browse/ASDF-<num>
893+
`)
894+
const expected = {
895+
additions: {},
896+
modifications: {
897+
entries: [
898+
{
899+
key_prefix: "ASDF-",
900+
url_template: "https://jiranew.company.com/browse/ASDF-<num>"
901+
}
902+
]
903+
},
904+
deletions: {},
905+
hasChanges: true
906+
}
907+
const ignorableFields = []
908+
const mockReturnGitHubContext = jest.fn().mockReturnValue({
909+
request: () => {},
910+
});
911+
const mergeDeep = new MergeDeep(
912+
log,
913+
mockReturnGitHubContext,
914+
ignorableFields
915+
);
916+
const merged = mergeDeep.compareDeep(target, source)
917+
console.log(`diffs ${JSON.stringify(merged, null, 2)}`)
918+
expect(merged).toEqual(expected)
919+
})
920+
884921
it('CompareDeep does not mutate source object', () => {
885922
const ignorableFields = []
886923
const mockReturnGitHubContext = jest.fn().mockReturnValue({

test/unit/lib/plugins/autolinks.test.js

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ describe('Autolinks', () => {
3434
{ key_prefix: 'NEW_ALPHA-UNDEFINED-', url_template: 'https://test/<num>' },
3535
{ key_prefix: 'NEW_ALPHA-FALSE-', url_template: 'https://test/<num>', is_alphanumeric: false },
3636
{ key_prefix: 'NEW_ALPHA-TRUE-', url_template: 'https://test/<num>', is_alphanumeric: true },
37+
{ key_prefix: 'NEW_URL_NEW_ALPHA-', url_template: 'https://new-url/<num>', is_alphanumeric: true },
3738
])
3839

3940
github.repos.listAutolinks.mockResolvedValueOnce({
@@ -47,6 +48,7 @@ describe('Autolinks', () => {
4748
{ id: '7', key_prefix: 'NEW_ALPHA-UNDEFINED-', url_template: 'https://test/<num>', is_alphanumeric: false },
4849
{ id: '8', key_prefix: 'NEW_ALPHA-FALSE-', url_template: 'https://test/<num>', is_alphanumeric: true },
4950
{ id: '9', key_prefix: 'NEW_ALPHA-TRUE-', url_template: 'https://test/<num>', is_alphanumeric: false },
51+
{ id: '10', key_prefix: 'NEW_URL_NEW_ALPHA-', url_template: 'https://current-url/<num>', is_alphanumeric: false },
5052
]
5153
})
5254

@@ -139,9 +141,19 @@ describe('Autolinks', () => {
139141
is_alphanumeric: true,
140142
...repo
141143
})
144+
expect(github.repos.deleteAutolink).toHaveBeenCalledWith({
145+
autolink_id: '10',
146+
...repo
147+
})
148+
expect(github.repos.createAutolink).toHaveBeenCalledWith({
149+
key_prefix: 'NEW_URL_NEW_ALPHA-',
150+
url_template: 'https://new-url/<num>',
151+
is_alphanumeric: true,
152+
...repo
153+
})
142154

143-
expect(github.repos.deleteAutolink).toHaveBeenCalledTimes(5)
144-
expect(github.repos.createAutolink).toHaveBeenCalledTimes(5)
155+
expect(github.repos.deleteAutolink).toHaveBeenCalledTimes(6)
156+
expect(github.repos.createAutolink).toHaveBeenCalledTimes(6)
145157
})
146158
})
147159
})

0 commit comments

Comments
 (0)