Skip to content

Commit

Permalink
fix: Not adding checks to existing branch protection contexts
Browse files Browse the repository at this point in the history
  • Loading branch information
stevoland committed Feb 16, 2024
1 parent c0ecee0 commit aa5cdb0
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 3 deletions.
4 changes: 2 additions & 2 deletions lib/mergeDeep.js
Original file line number Diff line number Diff line change
Expand Up @@ -246,9 +246,9 @@ class MergeDeep {
if (visited[id]) {
this.compareDeep(a, visited[id], additions[additions.length - 1], modifications[modifications.length - 1], deletions[deletions.length - 1])
}
// Any addtions for the matching key must be moved to modifications
// Any additions for the matching key must be moved to modifications
if (!this.isEmpty(additions)) {
modifications = modifications.concat(additions)
modifications.push(...additions)
}
// Add name attribute to the modifications to make it look better ; it won't be added otherwise as it would be the same
if (!this.isEmpty(modifications[modifications.length - 1])) {
Expand Down
65 changes: 64 additions & 1 deletion test/unit/lib/mergeDeep.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1315,5 +1315,68 @@ entries:
//console.log(`target ${JSON.stringify(target, null, 2)}`)
//console.log(`diffs ${JSON.stringify(merged, null, 2)}`)
})


it('Has changes with additions to arrays', () => {
const target = {
branches: [
{
name: 'master',
protection: {
required_status_checks: {
strict: true,
contexts: [
"test1",
],
}
}
}
]
}

const source = {
branches: [
{
name: 'master',
protection: {
required_status_checks: {
strict: true,
contexts: [
'test1',
'test2'
],
}
}
}
]
}

const expected = {
additions: {},
deletions: {},
modifications: {
branches: [
{
name: "master",
protection: {
required_status_checks: {
contexts: [
'test2'
]
},
},
}
]
},
hasChanges: true
}

const ignorableFields = []
const mergeDeep = new MergeDeep(
log,
jest.fn(),
ignorableFields
);
const changes = mergeDeep.compareDeep(target, source)
expect(changes).toEqual(expected)
})
})

0 comments on commit aa5cdb0

Please sign in to comment.