Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(rulesets): avoid updates when no meaningful change is made #1049

Merged
merged 1 commit into from
Oct 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion lib/plugins/rulesets.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
6 changes: 6 additions & 0 deletions test/integration/features/rulesets.feature
Original file line number Diff line number Diff line change
Expand Up @@ -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
38 changes: 35 additions & 3 deletions test/integration/features/step_definitions/rulesets-steps.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 }) => {
Expand All @@ -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()
})
)
)
})
Expand Down Expand Up @@ -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)
})
Expand All @@ -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
})