Skip to content

Commit cec7bfa

Browse files
committed
fix(rulesets): avoid updates when no meaningful change is made
by filtering ruleset state properties from api response that do not get updated from the config for #732
1 parent 2209b6f commit cec7bfa

File tree

3 files changed

+52
-4
lines changed

3 files changed

+52
-4
lines changed

lib/plugins/rulesets.js

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,17 @@ export default class Rulesets extends Diffable {
1818
}
1919

2020
changed (existing, attrs) {
21-
const { id, ...existingAttrs } = existing
21+
const {
22+
id,
23+
_links,
24+
created_at: createdAt,
25+
updated_at: updatedAd,
26+
source_type: sourceType,
27+
source,
28+
node_id: nodeId,
29+
current_user_can_bypass: currentUserCanBypass,
30+
...existingAttrs
31+
} = existing
2232

2333
return !deepEqual(existingAttrs, attrs)
2434
}

test/integration/features/rulesets.feature

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,9 @@ Feature: Repository Rulesets
1717
And the ruleset is removed from the config
1818
When a settings sync is triggered
1919
Then the ruleset is deleted
20+
21+
Scenario: No Updates
22+
Given a ruleset exists for the repository
23+
And no ruleset updates are made to the config
24+
When a settings sync is triggered
25+
Then no ruleset updates are triggered

test/integration/features/step_definitions/rulesets-steps.js

Lines changed: 35 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,18 @@ Given('no rulesets are defined for the repository', async function () {
2222
})
2323

2424
Given('a ruleset exists for the repository', async function () {
25-
const rulesetSubset = { name: rulesetName }
26-
const existingRulesets = [{ id: rulesetId, ...rulesetSubset }]
25+
const existingRulesetSubset = {
26+
id: rulesetId,
27+
name: rulesetName,
28+
_links: any.simpleObject(),
29+
created_at: any.string(),
30+
updated_at: any.string(),
31+
source_type: any.word(),
32+
source: any.string(),
33+
node_id: any.string()
34+
}
35+
const existingRuleset = { ...existingRulesetSubset }
36+
const existingRulesets = [existingRuleset]
2737

2838
this.server.use(
2939
http.get(`https://api.github.com/repos/${repository.owner.name}/${repository.name}/rulesets`, ({ request }) => {
@@ -38,7 +48,12 @@ Given('a ruleset exists for the repository', async function () {
3848
}),
3949
http.get(
4050
`https://api.github.com/repos/${repository.owner.name}/${repository.name}/rulesets/${rulesetId}`,
41-
({ request }) => HttpResponse.json({ id: rulesetId, ...rulesetSubset, rules: existingRules })
51+
({ request }) =>
52+
HttpResponse.json({
53+
...existingRuleset,
54+
rules: existingRules,
55+
current_user_can_bypass: any.boolean()
56+
})
4257
)
4358
)
4459
})
@@ -105,6 +120,19 @@ Given('the ruleset is removed from the config', async function () {
105120
)
106121
})
107122

123+
Given('no ruleset updates are made to the config', async function () {
124+
const existingRuleset = { name: rulesetName, rules: existingRules }
125+
126+
this.server.use(
127+
http.get(
128+
`https://api.github.com/repos/${repository.owner.name}/${repository.name}/contents/${encodeURIComponent(
129+
settings.FILE_NAME
130+
)}`,
131+
({ request }) => HttpResponse.arrayBuffer(Buffer.from(dump({ rulesets: [existingRuleset] })))
132+
)
133+
)
134+
})
135+
108136
Then('the ruleset is enabled for the repository', async function () {
109137
assert.deepEqual(this.createdRuleset, this.ruleset)
110138
})
@@ -116,3 +144,7 @@ Then('the ruleset is updated', async function () {
116144
Then('the ruleset is deleted', async function () {
117145
assert.equal(this.removedRuleset, rulesetId)
118146
})
147+
148+
Then('no ruleset updates are triggered', async function () {
149+
return undefined
150+
})

0 commit comments

Comments
 (0)