Skip to content

Commit

Permalink
✨ Support Branch-Protection via GitHub Repository Rules (#3354)
Browse files Browse the repository at this point in the history
* repo rulesets via v4 api

Signed-off-by: Peter Wagner <[email protected]>

* good enough fnmatch implementation.

Signed-off-by: Spencer Schrock <[email protected]>

* good enough rulesMatchingBranch

Signed-off-by: Peter Wagner <[email protected]>

* apply matching repo rules to branch protection settings

Signed-off-by: Peter Wagner <[email protected]>

* rules: consider admins and require checks

Signed-off-by: Peter Wagner <[email protected]>

* non-structural chanages from PR feedback

Signed-off-by: Peter Wagner <[email protected]>

* fetch default branch name during repo rules query

Signed-off-by: Peter Wagner <[email protected]>

* Testing applyRepoRules

Tests assume a single rule is being applied to a branch, which might be
guarded by a legacy branch protection rule.

I think this logic gets problematic when there are multiple rules
overlaid on the same branch: the "the existing rules does not enforce
for admins, but i do and therefore this branch now does" will give
false-positives.

Signed-off-by: Peter Wagner <[email protected]>

* Test_applyRepoRules: builder and standardize names

Signed-off-by: Peter Wagner <[email protected]>

* attempt to upgrade/downgrade EnforceAdmins as each rule is applied

Signed-off-by: Peter Wagner <[email protected]>

* simplify enforce admin for now.

Signed-off-by: Spencer Schrock <[email protected]>

* handle merging pull request reviews

Signed-off-by: Spencer Schrock <[email protected]>

* handle merging check rules

Signed-off-by: Spencer Schrock <[email protected]>

* handle last push approval

Signed-off-by: Spencer Schrock <[email protected]>

* handle linear history

Signed-off-by: Spencer Schrock <[email protected]>

* use constants for github rule types.

Signed-off-by: Spencer Schrock <[email protected]>

* add status check test.

Signed-off-by: Spencer Schrock <[email protected]>

* add e2e test for repo rules.

Signed-off-by: Spencer Schrock <[email protected]>

* handle nil branch name data

Signed-off-by: Spencer Schrock <[email protected]>

* add tracking issue.

Signed-off-by: Spencer Schrock <[email protected]>

* fix precedence in if statement

Signed-off-by: Spencer Schrock <[email protected]>

* include repo rules in the check docs.

Signed-off-by: Spencer Schrock <[email protected]>

---------

Signed-off-by: Peter Wagner <[email protected]>
Signed-off-by: Spencer Schrock <[email protected]>
Co-authored-by: Spencer Schrock <[email protected]>
  • Loading branch information
thepwagner and spencerschrock authored Sep 14, 2023
1 parent 9c9c84b commit e515c2a
Show file tree
Hide file tree
Showing 7 changed files with 920 additions and 35 deletions.
Loading

0 comments on commit e515c2a

Please sign in to comment.