From f8788d86824f99f8eb16c2a849ea8f1a67d35f08 Mon Sep 17 00:00:00 2001 From: Matt Travi Date: Sun, 6 Oct 2024 10:58:53 -0500 Subject: [PATCH] fix(rulesets): filter organization rulesets from the list compared for the repository for #732 --- lib/plugins/rulesets.js | 2 +- .../features/step_definitions/rulesets-steps.js | 14 +++++++++++--- test/unit/lib/plugins/rulesets.test.js | 2 +- 3 files changed, 13 insertions(+), 5 deletions(-) diff --git a/lib/plugins/rulesets.js b/lib/plugins/rulesets.js index 1a7d439bf..21748050c 100644 --- a/lib/plugins/rulesets.js +++ b/lib/plugins/rulesets.js @@ -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 })) diff --git a/test/integration/features/step_definitions/rulesets-steps.js b/test/integration/features/step_definitions/rulesets-steps.js index e23aa836f..f22be101a 100644 --- a/test/integration/features/step_definitions/rulesets-steps.js +++ b/test/integration/features/step_definitions/rulesets-steps.js @@ -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 }) diff --git a/test/unit/lib/plugins/rulesets.test.js b/test/unit/lib/plugins/rulesets.test.js index 7670aa0bc..ff1a812cd 100644 --- a/test/unit/lib/plugins/rulesets.test.js +++ b/test/unit/lib/plugins/rulesets.test.js @@ -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