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): filter organization rulesets from the list compared for the repository #1048

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
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