Skip to content

Commit

Permalink
Merge pull request #1049 from repository-settings/ruleset-api-properties
Browse files Browse the repository at this point in the history
  • Loading branch information
travi authored Oct 6, 2024
2 parents 2209b6f + cec7bfa commit f5d8dbe
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 4 deletions.
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
})

0 comments on commit f5d8dbe

Please sign in to comment.