From cec7bfad2b7c2292c1582bd38ad18eee3ad713ec Mon Sep 17 00:00:00 2001 From: Matt Travi Date: Sun, 6 Oct 2024 11:28:16 -0500 Subject: [PATCH] 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 --- lib/plugins/rulesets.js | 12 +++++- test/integration/features/rulesets.feature | 6 +++ .../step_definitions/rulesets-steps.js | 38 +++++++++++++++++-- 3 files changed, 52 insertions(+), 4 deletions(-) diff --git a/lib/plugins/rulesets.js b/lib/plugins/rulesets.js index 21748050c..d66e82288 100644 --- a/lib/plugins/rulesets.js +++ b/lib/plugins/rulesets.js @@ -18,7 +18,17 @@ export default class Rulesets extends Diffable { } changed (existing, attrs) { - const { id, ...existingAttrs } = existing + const { + id, + _links, + created_at: createdAt, + updated_at: updatedAd, + source_type: sourceType, + source, + node_id: nodeId, + current_user_can_bypass: currentUserCanBypass, + ...existingAttrs + } = existing return !deepEqual(existingAttrs, attrs) } diff --git a/test/integration/features/rulesets.feature b/test/integration/features/rulesets.feature index 41de57f73..2c067d1d3 100644 --- a/test/integration/features/rulesets.feature +++ b/test/integration/features/rulesets.feature @@ -17,3 +17,9 @@ Feature: Repository Rulesets And the ruleset is removed from the config When a settings sync is triggered Then the ruleset is deleted + + Scenario: No Updates + Given a ruleset exists for the repository + And no ruleset updates are made to the config + When a settings sync is triggered + Then no ruleset updates are triggered diff --git a/test/integration/features/step_definitions/rulesets-steps.js b/test/integration/features/step_definitions/rulesets-steps.js index f22be101a..5208a45c8 100644 --- a/test/integration/features/step_definitions/rulesets-steps.js +++ b/test/integration/features/step_definitions/rulesets-steps.js @@ -22,8 +22,18 @@ Given('no rulesets are defined for the repository', async function () { }) Given('a ruleset exists for the repository', async function () { - const rulesetSubset = { name: rulesetName } - const existingRulesets = [{ id: rulesetId, ...rulesetSubset }] + const existingRulesetSubset = { + id: rulesetId, + name: rulesetName, + _links: any.simpleObject(), + created_at: any.string(), + updated_at: any.string(), + source_type: any.word(), + source: any.string(), + node_id: any.string() + } + const existingRuleset = { ...existingRulesetSubset } + const existingRulesets = [existingRuleset] this.server.use( 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 () { }), http.get( `https://api.github.com/repos/${repository.owner.name}/${repository.name}/rulesets/${rulesetId}`, - ({ request }) => HttpResponse.json({ id: rulesetId, ...rulesetSubset, rules: existingRules }) + ({ request }) => + HttpResponse.json({ + ...existingRuleset, + rules: existingRules, + current_user_can_bypass: any.boolean() + }) ) ) }) @@ -105,6 +120,19 @@ Given('the ruleset is removed from the config', async function () { ) }) +Given('no ruleset updates are made to the config', async function () { + const existingRuleset = { name: rulesetName, rules: existingRules } + + this.server.use( + http.get( + `https://api.github.com/repos/${repository.owner.name}/${repository.name}/contents/${encodeURIComponent( + settings.FILE_NAME + )}`, + ({ request }) => HttpResponse.arrayBuffer(Buffer.from(dump({ rulesets: [existingRuleset] }))) + ) + ) +}) + Then('the ruleset is enabled for the repository', async function () { assert.deepEqual(this.createdRuleset, this.ruleset) }) @@ -116,3 +144,7 @@ Then('the ruleset is updated', async function () { Then('the ruleset is deleted', async function () { assert.equal(this.removedRuleset, rulesetId) }) + +Then('no ruleset updates are triggered', async function () { + return undefined +})