-
Notifications
You must be signed in to change notification settings - Fork 1
feat: implement issue #324 — Compliance: ruleset-drift-pr-quality-dismiss_stale_reviews_on_push #353
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
Merged
Merged
feat: implement issue #324 — Compliance: ruleset-drift-pr-quality-dismiss_stale_reviews_on_push #353
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
401fa7f
feat: implement issue #324 — Compliance: ruleset-drift-pr-quality-dis…
donpetry-bot 2e7c71e
chore: dev-lead update (review-changes) [skip ci-relay]
donpetry-bot 0eddcda
chore: dev-lead update (review-changes) [skip ci-relay]
donpetry-bot 012881e
Merge branch 'main' into dev-lead/issue-324-20260721-1926
don-petry 618baaf
chore: dev-lead update (review-changes) [skip ci-relay]
donpetry-bot 06f463c
Merge branch 'main' into dev-lead/issue-324-20260721-1926
donpetry-bot File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,102 @@ | ||
| #!/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 quality gates on the default branch of | ||
| # petry-projects/markets. | ||
| # | ||
| # Pull-request rule parameters configured (codified standard, source of truth: | ||
| # petry-projects/.github/standards/rulesets/pr-quality.json — see #324): | ||
| # - required_approving_review_count: 1 | ||
| # - require_code_owner_review: true | ||
| # - required_review_thread_resolution: true | ||
| # - dismiss_stale_reviews_on_push: true (the drifted parameter — issue #324) | ||
| # - require_last_push_approval: true | ||
| # - allowed_merge_methods: ["squash"] | ||
| # | ||
| # 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 | ||
|
|
||
| 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") | ||
|
don-petry marked this conversation as resolved.
|
||
|
|
||
| PAYLOAD=$(jq -n '{ | ||
| name: "pr-quality", | ||
| target: "branch", | ||
| enforcement: "active", | ||
| 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, | ||
| allowed_merge_methods: ["squash"] | ||
| } | ||
| } | ||
| ], | ||
| bypass_actors: [ | ||
| { | ||
| actor_type: "OrganizationAdmin", | ||
| bypass_mode: "always" | ||
| }, | ||
| { | ||
| actor_id: 3167543, | ||
| actor_type: "Integration", | ||
| bypass_mode: "always" | ||
| } | ||
| ] | ||
| }') | ||
|
|
||
| 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 ..." | ||
| # Capture stderr so a 422 conflict from concurrent creation doesn't terminate the script. | ||
| # On conflict, re-fetch the ID created by the concurrent run and update instead. | ||
| if RESULT=$(echo "$PAYLOAD" | gh api -X POST "repos/$REPO/rulesets" --input - 2>&1); then | ||
| NEW_ID=$(echo "$RESULT" | jq -r '.id') | ||
| echo "Done — ruleset created: https://github.com/$REPO/rules/$NEW_ID" | ||
| else | ||
| EXISTING_ID=$(gh api "repos/$REPO/rulesets" \ | ||
| --jq ".[] | select(.name == \"$RULESET_NAME\") | .id") | ||
| if [ -z "$EXISTING_ID" ]; then | ||
| echo "ERROR: POST failed and no existing $RULESET_NAME ruleset found" >&2 | ||
| echo "$RESULT" >&2 | ||
| exit 1 | ||
| fi | ||
| echo "Concurrent creation detected — updating $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" | ||
| fi | ||
| fi | ||
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,49 @@ | ||
| #!/usr/bin/env bats | ||
| # Tests for apply-pr-quality-ruleset.sh — static content assertions, no live API calls. | ||
| # | ||
| # The pull_request rule parameters asserted below are the codified standard | ||
| # (petry-projects/.github/standards/rulesets/pr-quality.json), the source of | ||
| # truth referenced by issue #324. | ||
|
|
||
| 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 -qE '^REPO="petry-projects/markets"$' "$SCRIPT" | ||
| } | ||
|
|
||
| @test "script declares the pr-quality ruleset" { | ||
| grep -qE '^[[:space:]]+name[[:space:]]*:[[:space:]]*"pr-quality"' "$SCRIPT" | ||
| } | ||
|
don-petry marked this conversation as resolved.
|
||
|
|
||
| @test "script sets dismiss_stale_reviews_on_push to true (issue #324)" { | ||
| grep -qE '^[[:space:]]+dismiss_stale_reviews_on_push[[:space:]]*:[[:space:]]*true[[:space:]]*,?[[:space:]]*$' "$SCRIPT" | ||
| } | ||
|
don-petry marked this conversation as resolved.
|
||
|
|
||
| @test "script requires one approving review" { | ||
| grep -qE '^[[:space:]]+required_approving_review_count[[:space:]]*:[[:space:]]*1[[:space:]]*,?[[:space:]]*$' "$SCRIPT" | ||
| } | ||
|
|
||
| @test "script requires code owner review" { | ||
| grep -qE '^[[:space:]]+require_code_owner_review[[:space:]]*:[[:space:]]*true[[:space:]]*,?[[:space:]]*$' "$SCRIPT" | ||
| } | ||
|
|
||
| @test "script requires review thread resolution" { | ||
| grep -qE '^[[:space:]]+required_review_thread_resolution[[:space:]]*:[[:space:]]*true[[:space:]]*,?[[:space:]]*$' "$SCRIPT" | ||
| } | ||
|
|
||
| @test "script requires last push approval" { | ||
| grep -qE '^[[:space:]]+require_last_push_approval[[:space:]]*:[[:space:]]*true[[:space:]]*,?[[:space:]]*$' "$SCRIPT" | ||
| } | ||
|
|
||
| @test "script allows only the squash merge method" { | ||
| grep -qE '^[[:space:]]+allowed_merge_methods[[:space:]]*:[[:space:]]*\[[[:space:]]*"squash"[[:space:]]*\][[:space:]]*$' "$SCRIPT" | ||
| } | ||
|
don-petry marked this conversation as resolved.
coderabbitai[bot] marked this conversation as resolved.
|
||
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
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
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.