Skip to content

Commit

Permalink
Merge pull request #1048 from repository-settings/org-rulesets
Browse files Browse the repository at this point in the history
  • Loading branch information
travi authored Oct 6, 2024
2 parents c4ae24b + f8788d8 commit 2209b6f
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 5 deletions.
2 changes: 1 addition & 1 deletion lib/plugins/rulesets.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import Diffable from './diffable.js'

export default class Rulesets extends Diffable {
async find () {
const { data: rulesets } = await this.github.repos.getRepoRulesets(this.repo)
const { data: rulesets } = await this.github.repos.getRepoRulesets({ ...this.repo, includes_parents: false })

const expandedRulesetsData = await Promise.all(
rulesets.map(({ id }) => this.github.repos.getRepoRuleset({ ...this.repo, ruleset_id: id }))
Expand Down
14 changes: 11 additions & 3 deletions test/integration/features/step_definitions/rulesets-steps.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,19 @@ 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 }]

this.server.use(
http.get(`https://api.github.com/repos/${repository.owner.name}/${repository.name}/rulesets`, ({ request }) =>
HttpResponse.json([{ id: rulesetId, ...rulesetSubset }])
),
http.get(`https://api.github.com/repos/${repository.owner.name}/${repository.name}/rulesets`, ({ request }) => {
const url = new URL(request.url)

if (url.searchParams.get('includes_parents') === 'false') return HttpResponse.json(existingRulesets)

return HttpResponse.json([
...existingRulesets,
...any.listOf(() => ({ id: any.integer(), ...any.simpleObject() }))
])
}),
http.get(
`https://api.github.com/repos/${repository.owner.name}/${repository.name}/rulesets/${rulesetId}`,
({ request }) => HttpResponse.json({ id: rulesetId, ...rulesetSubset, rules: existingRules })
Expand Down
2 changes: 1 addition & 1 deletion test/unit/lib/plugins/rulesets.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ describe('rulesets', () => {
{ id: removedRulesetId, name: any.word() }
]
when(github.repos.getRepoRulesets)
.calledWith({ owner, repo })
.calledWith({ owner, repo, includes_parents: false })
.mockResolvedValue({
data: existingRulesets.map(
({ rules, conditions, bypass_actors: bypassActors, ...rulesetListProperties }) => rulesetListProperties
Expand Down

0 comments on commit 2209b6f

Please sign in to comment.