Make CIS ruleset fixes idempotent, add fix for PR approval dismissal - #2
Open
timgentry wants to merge 1 commit into
Open
Make CIS ruleset fixes idempotent, add fix for PR approval dismissal#2timgentry wants to merge 1 commit into
timgentry wants to merge 1 commit into
Conversation
Each fixable CIS rule now owns a RULESET_NAME constant and shares a single apply_ruleset_fix helper (in the RulesetFinder concern) that updates the existing managed ruleset if one is found by name, instead of creating a new one on every --fix run. Also adds fix support to PreviousPrApprovalsDismissed, which previously only reported failures.
🦙 MegaLinter status: ❌ ERROR
See detailed report in MegaLinter reports You could have the same capabilities but better runtime performances if you use a MegaLinter flavor:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

What?
Refactors the three fixable CIS ruleset rules (branch deletion denial, force push denial, default branch protection) to share a naming convention and a common fix helper, and adds
--fixsupport to the previously read-onlyPreviousPrApprovalsDismissedrule.Why?
Running
--fixrepeatedly against the same repo used to create a brand new ruleset every time a rule was still failing, rather than updating the one it had already made — leading to duplicate, accumulating rulesets in GitHub over time. A stable per-rule ruleset name lets--fixfind and update its own previously-created ruleset instead of piling up copies.PreviousPrApprovalsDismissedwas also the last of the four ruleset-based CIS rules with no remediation path, so it always required manual intervention.How?
Each fixable rule now defines a
RULESET_NAMEconstant (e.g.'Way of Working CIS: Branch Deletion Denied'). TheRulesetFinderconcern gained a sharedapply_ruleset_fixmethod that looks for an existing ruleset with that name in the repo's ruleset list —PATCHing it if found,POSTing a new one if not — replacing the three duplicated per-ruleapply_fixmethods that always created.PreviousPrApprovalsDismissedwas updated to follow the same pattern (includingRulesetFinder, defining its ownrequired_ruleset_config) instead of only reading rulesets to report failure with no fix.Testing?
Ran
bundle exec rake test(existing suite passes) andbundle exec rubocopon the changed files — no new lint offenses were introduced (the offense count net decreased, since the three duplicatedapply_fixmethods collapsed into one shared implementation). No dedicated unit tests exist yet for individual rulevalidate/fix behaviour — that's a pre-existing gap in this repo, not something this PR adds coverage for.Screenshots (optional)
N/A — no UI changes.
Anything Else?
PreviousPrApprovalsDismissed's fix andDefaultBranchProtection's fix can each create a separate ruleset targeting the default branch'spull_requestrule (one enforcing justdismiss_stale_reviews_on_push, the other enforcing several parameters). GitHub merges rules from multiple rulesets on the same branch, so this isn't a conflict — just some ruleset sprawl worth consolidating later if it gets noisy.PublicSecurityFileis now the only rule without--fix, since it needs to write file content via the Contents API rather than a ruleset.