Skip to content

Commit 610094d

Browse files
decyjphrgramatus
andauthored
Decyjphr/pr 682 (#685)
* update comments from #249 I found the logic behind some of what happened here hard to follow and updated the comments to try to make it easier to follow. * fix environments updating global array The environments plugin was changing `MergeDeep.NAME_FIELDS`, which is a global object. The reason was to avoid environments being filtered out from the change list if they only have a name field. However, the environments plugin has it's own overriden sync method, and thus we can simply drop the whole filtering from that method. Fixes #108 * remove repeating line This has to be a "typo" from 9a74e05 calling the same assignment twice. Removing to clean up. --------- Co-authored-by: Torgeir S. hos Sykehuspartner <93591857+torgst@users.noreply.github.com>
1 parent c9247f5 commit 610094d

File tree

3 files changed

+4
-8
lines changed

3 files changed

+4
-8
lines changed

lib/mergeDeep.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -378,5 +378,4 @@ class MergeDeep {
378378
}
379379
}
380380
MergeDeep.NAME_FIELDS = NAME_FIELDS
381-
MergeDeep.NAME_FIELDS = NAME_FIELDS
382381
module.exports = MergeDeep

lib/plugins/diffable.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,14 +93,15 @@ module.exports = class Diffable extends ErrorStash {
9393
}
9494
}
9595

96-
// Filter out all empty entries (usually from repo override)
96+
// Remove any null or undefined values from the diffables (usually comes from repo override)
9797
for (const entry of filteredEntries) {
9898
for (const key of Object.keys(entry)) {
9999
if (entry[key] === null || entry[key] === undefined) {
100100
delete entry[key]
101101
}
102102
}
103103
}
104+
// Delete any diffable that now only has name and no other attributes
104105
filteredEntries = filteredEntries.filter(entry => Object.keys(entry).filter(key => !MergeDeep.NAME_FIELDS.includes(key)).length !== 0)
105106

106107
const changes = []

lib/plugins/environments.js

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,6 @@ module.exports = class Environments extends Diffable {
1717
}
1818
})
1919
}
20-
21-
// Remove 'name' from filtering list so Environments with only a name defined are processed.
22-
MergeDeep.NAME_FIELDS.splice(MergeDeep.NAME_FIELDS.indexOf('name'), 1)
23-
2420
}
2521

2622
async find() {
@@ -296,15 +292,15 @@ module.exports = class Environments extends Diffable {
296292
let filteredEntries = this.filterEntries()
297293
return this.find().then(existingRecords => {
298294

299-
// Filter out all empty entries (usually from repo override)
295+
// Remove any null or undefined values from the diffables (usually comes from repo override)
300296
for (const entry of filteredEntries) {
301297
for (const key of Object.keys(entry)) {
302298
if (entry[key] === null || entry[key] === undefined) {
303299
delete entry[key]
304300
}
305301
}
306302
}
307-
filteredEntries = filteredEntries.filter(entry => Object.keys(entry).filter(key => !MergeDeep.NAME_FIELDS.includes(key)).length !== 0)
303+
// For environments, we want to keep the entries with only name defined.
308304

309305
const changes = []
310306

0 commit comments

Comments
 (0)