Skip to content

Commit 3d61f1f

Browse files
authored
Fix custom_properties diffing when config uses property_name (#978)
* Initial plan * Handle alternate custom property name shapes in normalize * Add explicit object guard in custom property normalization * Support property_name in custom_properties config entries * Polish custom properties test descriptions --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
1 parent b9afee8 commit 3d61f1f

2 files changed

Lines changed: 59 additions & 12 deletions

File tree

lib/plugins/custom_properties.js

Lines changed: 35 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,24 @@ module.exports = class CustomProperties extends Diffable {
1212

1313
// Force all names to lowercase to avoid comparison issues.
1414
normalizeEntries () {
15-
this.entries = this.entries
16-
.filter(({ name }) => name != null)
17-
.map(({ name, value }) => ({
18-
name: name.toLowerCase(),
19-
value
20-
}))
15+
this.entries = this.entries.reduce((normalizedEntries, entry) => {
16+
if (!entry || typeof entry !== 'object') {
17+
return normalizedEntries
18+
}
19+
20+
const entryName = entry.name || entry.property_name
21+
22+
if (typeof entryName !== 'string') {
23+
return normalizedEntries
24+
}
25+
26+
normalizedEntries.push({
27+
name: entryName.toLowerCase(),
28+
value: entry.value
29+
})
30+
31+
return normalizedEntries
32+
}, [])
2133
}
2234

2335
async find () {
@@ -40,12 +52,24 @@ module.exports = class CustomProperties extends Diffable {
4052

4153
// Force all names to lowercase to avoid comparison issues.
4254
normalize (properties) {
43-
return properties
44-
.filter(({ property_name: propertyName }) => propertyName != null)
45-
.map(({ property_name: propertyName, value }) => ({
55+
return properties.reduce((normalizedProperties, property) => {
56+
if (!property || typeof property !== 'object') {
57+
return normalizedProperties
58+
}
59+
60+
const propertyName = property.property_name || property.name
61+
62+
if (typeof propertyName !== 'string') {
63+
return normalizedProperties
64+
}
65+
66+
normalizedProperties.push({
4667
name: propertyName.toLowerCase(),
47-
value
48-
}))
68+
value: property.value
69+
})
70+
71+
return normalizedProperties
72+
}, [])
4973
}
5074

5175
comparator (existing, attrs) {

test/unit/lib/plugins/custom_properties.test.js

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,16 @@ describe('CustomProperties', () => {
2727
})
2828

2929
describe('Custom Properties plugin', () => {
30-
it('should normalize entries when be instantiated', () => {
30+
it('should normalize entries when instantiated', () => {
3131
const plugin = configure([{ name: 'Test', value: 'test' }])
3232
expect(plugin.entries).toEqual([{ name: 'test', value: 'test' }])
3333
})
3434

35+
it('should normalize entries with property_name when instantiated', () => {
36+
const plugin = configure([{ property_name: 'ent-ownership', value: 'expert-services' }])
37+
expect(plugin.entries).toEqual([{ name: 'ent-ownership', value: 'expert-services' }])
38+
})
39+
3540
it('should fetch and normalize custom properties successfully', async () => {
3641
const mockResponse = [
3742
{ property_name: 'Test1', value: 'value1' },
@@ -58,6 +63,24 @@ describe('CustomProperties', () => {
5863
])
5964
})
6065

66+
it('should normalize paginated custom properties when property name shape differs', async () => {
67+
const mockResponse = [
68+
{ name: 'Owner', value: 'My Team' },
69+
{ property_name: 'Criticality', value: 'High' },
70+
{ value: 'ignored' }
71+
]
72+
73+
github.paginate.mockResolvedValue(mockResponse)
74+
75+
const plugin = configure()
76+
const result = await plugin.find()
77+
78+
expect(result).toEqual([
79+
{ name: 'owner', value: 'My Team' },
80+
{ name: 'criticality', value: 'High' }
81+
])
82+
})
83+
6184
it('should sync', async () => {
6285
const mockResponse = [
6386
{ property_name: 'no-change', value: 'no-change' },

0 commit comments

Comments
 (0)