Skip to content

Commit

Permalink
Decyjphr/pr 682 (#685)
Browse files Browse the repository at this point in the history
* 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 <[email protected]>
  • Loading branch information
decyjphr and torgst committed Sep 16, 2024
1 parent c9247f5 commit 610094d
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 8 deletions.
1 change: 0 additions & 1 deletion lib/mergeDeep.js
Original file line number Diff line number Diff line change
Expand Up @@ -378,5 +378,4 @@ class MergeDeep {
}
}
MergeDeep.NAME_FIELDS = NAME_FIELDS
MergeDeep.NAME_FIELDS = NAME_FIELDS
module.exports = MergeDeep
3 changes: 2 additions & 1 deletion lib/plugins/diffable.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,14 +93,15 @@ module.exports = class Diffable extends ErrorStash {
}
}

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

const changes = []
Expand Down
8 changes: 2 additions & 6 deletions lib/plugins/environments.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,6 @@ module.exports = class Environments extends Diffable {
}
})
}

// Remove 'name' from filtering list so Environments with only a name defined are processed.
MergeDeep.NAME_FIELDS.splice(MergeDeep.NAME_FIELDS.indexOf('name'), 1)

}

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

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

const changes = []

Expand Down

0 comments on commit 610094d

Please sign in to comment.