-
Notifications
You must be signed in to change notification settings - Fork 1
feat: implement issue #323 — Compliance: ruleset-drift-pr-quality-require_code_owner_review #332
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,87 @@ | ||
| #!/usr/bin/env bash | ||
| # apply-pr-quality-ruleset.sh — Idempotently create/update the pr-quality ruleset | ||
| # | ||
| # This script creates (or updates) the `pr-quality` repository ruleset that | ||
| # enforces pull-request review requirements on the default branch of | ||
| # petry-projects/markets. It restores the codified standard after drift — | ||
| # specifically `require_code_owner_review` (see issue #323). | ||
| # | ||
| # Parameters mirror the codified source of truth: | ||
| # petry-projects/.github → standards/rulesets/pr-quality.json | ||
| # required_approving_review_count: 1 | ||
| # require_code_owner_review: true | ||
| # required_review_thread_resolution: true | ||
| # dismiss_stale_reviews_on_push: true | ||
| # require_last_push_approval: true | ||
| # | ||
| # Standard reference: | ||
| # https://github.com/petry-projects/.github/blob/main/standards/github-settings.md#pr-quality--standard-ruleset-all-repositories | ||
| # | ||
| # Usage: | ||
| # GH_TOKEN=<admin-token> bash .github/scripts/apply-pr-quality-ruleset.sh | ||
| # | ||
| # The org-level script (petry-projects/.github/scripts/apply-rulesets.sh) is the | ||
| # canonical tool for managing rulesets across all repos. This script exists as a | ||
| # repo-local reference and fallback for the markets repository specifically. | ||
|
|
||
| set -euo pipefail | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fixed in |
||
|
|
||
| REPO="petry-projects/markets" | ||
| RULESET_NAME="pr-quality" | ||
|
|
||
| if [ -z "${GH_TOKEN:-}" ]; then | ||
| echo "ERROR: GH_TOKEN is required with administration:write scope" >&2 | ||
| exit 1 | ||
| fi | ||
|
|
||
| export GH_TOKEN | ||
|
|
||
| # Fetch existing rulesets | ||
| EXISTING_ID=$(gh api "repos/$REPO/rulesets" \ | ||
| --jq ".[] | select(.name == \"$RULESET_NAME\") | .id") | ||
|
|
||
| PAYLOAD=$(jq -n '{ | ||
|
Comment on lines
+40
to
+43
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fixed in |
||
| name: "pr-quality", | ||
|
Comment on lines
+43
to
+44
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fixed in |
||
| target: "branch", | ||
| enforcement: "active", | ||
| bypass_actors: [ | ||
| { | ||
| actor_type: "OrganizationAdmin", | ||
| bypass_mode: "always" | ||
| }, | ||
| { | ||
| actor_id: 3167543, | ||
| actor_type: "Integration", | ||
| bypass_mode: "always" | ||
| } | ||
| ], | ||
|
Comment on lines
+47
to
+57
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fixed in |
||
| conditions: { | ||
| ref_name: { | ||
| include: ["~DEFAULT_BRANCH"], | ||
| exclude: [] | ||
| } | ||
| }, | ||
| rules: [ | ||
| { | ||
| type: "pull_request", | ||
| parameters: { | ||
| required_approving_review_count: 1, | ||
| require_code_owner_review: true, | ||
| required_review_thread_resolution: true, | ||
| dismiss_stale_reviews_on_push: true, | ||
| require_last_push_approval: true | ||
| } | ||
| } | ||
| ] | ||
| }') | ||
|
|
||
| if [ -n "$EXISTING_ID" ]; then | ||
| echo "Updating existing $RULESET_NAME ruleset (id=$EXISTING_ID) ..." | ||
| echo "$PAYLOAD" | gh api -X PUT "repos/$REPO/rulesets/$EXISTING_ID" --input - > /dev/null | ||
| echo "Done — ruleset updated: https://github.com/$REPO/rules/$EXISTING_ID" | ||
| else | ||
| echo "Creating $RULESET_NAME ruleset ..." | ||
| RESULT=$(echo "$PAYLOAD" | gh api -X POST "repos/$REPO/rulesets" --input -) | ||
| NEW_ID=$(echo "$RESULT" | jq -r '.id') | ||
| echo "Done — ruleset created: https://github.com/$REPO/rules/$NEW_ID" | ||
| fi | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,45 @@ | ||
| #!/usr/bin/env bats | ||
| # Tests for apply-pr-quality-ruleset.sh — static content assertions, no live API calls. | ||
|
|
||
| SCRIPT="$(cd "$(dirname "$BATS_TEST_FILENAME")/.." && pwd)/apply-pr-quality-ruleset.sh" | ||
|
|
||
| @test "script exists and is executable" { | ||
| [ -f "$SCRIPT" ] | ||
| [ -x "$SCRIPT" ] | ||
| } | ||
|
|
||
| @test "script uses set -euo pipefail" { | ||
| grep -q 'set -euo pipefail' "$SCRIPT" | ||
| } | ||
|
|
||
| @test "script targets petry-projects/markets repo" { | ||
| grep -q 'petry-projects/markets' "$SCRIPT" | ||
| } | ||
|
|
||
| @test "script requires GH_TOKEN" { | ||
| grep -q 'GH_TOKEN' "$SCRIPT" | ||
| } | ||
|
|
||
| @test "script manages the pr-quality ruleset" { | ||
| grep -q 'pr-quality' "$SCRIPT" | ||
| } | ||
|
|
||
| @test "script configures a pull_request rule" { | ||
| grep -q 'pull_request' "$SCRIPT" | ||
| } | ||
|
|
||
| @test "script sets require_code_owner_review to true (issue #323)" { | ||
| grep -qE 'require_code_owner_review["[:space:]:]+true' "$SCRIPT" | ||
| } | ||
|
Comment on lines
+31
to
+33
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fixed in |
||
|
|
||
| @test "script codifies the remaining pr-quality parameters" { | ||
| grep -q 'required_approving_review_count' "$SCRIPT" | ||
| grep -q 'required_review_thread_resolution' "$SCRIPT" | ||
| grep -q 'dismiss_stale_reviews_on_push' "$SCRIPT" | ||
| grep -q 'require_last_push_approval' "$SCRIPT" | ||
| } | ||
|
|
||
| @test "script is idempotent (creates or updates by existing id)" { | ||
| grep -q 'repos/$REPO/rulesets' "$SCRIPT" | ||
| grep -qE 'gh api -X (PUT|POST)' "$SCRIPT" | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed in
.github/scripts/apply-pr-quality-ruleset.sh: added explicit dependency checks immediately afterset -euo pipefail—command -v ghandcommand -v jqeach emit a clearERROR:message to stderr and exit 1 if the tool is absent, before any other logic runs. New bats assertions in.github/scripts/tests/apply-pr-quality-ruleset.batsverify both checks are present.