-
Notifications
You must be signed in to change notification settings - Fork 1
fix: add code-quality repository ruleset (closes #51) #77
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,73 @@ | ||||||||||||||||||||||||||||
| #!/usr/bin/env bash | ||||||||||||||||||||||||||||
| # apply-code-quality-ruleset.sh — Idempotently create/update the code-quality ruleset | ||||||||||||||||||||||||||||
| # | ||||||||||||||||||||||||||||
| # This script creates (or updates) the `code-quality` repository ruleset that | ||||||||||||||||||||||||||||
| # enforces required status checks on the default branch of petry-projects/markets. | ||||||||||||||||||||||||||||
| # | ||||||||||||||||||||||||||||
| # Required status checks configured (derived from actual CI check run names): | ||||||||||||||||||||||||||||
| # - SonarCloud sonarcloud.yml, job: sonarcloud (name: SonarCloud) | ||||||||||||||||||||||||||||
| # - Analyze (actions) codeql.yml, job: analyze (name: Analyze), language: actions | ||||||||||||||||||||||||||||
| # - claude-code / claude claude.yml, calling job: claude-code → reusable job: claude | ||||||||||||||||||||||||||||
| # | ||||||||||||||||||||||||||||
| # Standard reference: | ||||||||||||||||||||||||||||
| # https://github.com/petry-projects/.github/blob/main/standards/github-settings.md#code-quality--required-checks-ruleset-all-repositories | ||||||||||||||||||||||||||||
| # | ||||||||||||||||||||||||||||
| # Usage: | ||||||||||||||||||||||||||||
| # GH_TOKEN=<admin-token> bash .github/scripts/apply-code-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="code-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" 2>/dev/null || true) | ||||||||||||||||||||||||||||
|
Comment on lines
+34
to
+36
|
||||||||||||||||||||||||||||
| # Fetch existing rulesets | |
| EXISTING_ID=$(gh api "repos/$REPO/rulesets" \ | |
| --jq ".[] | select(.name == \"$RULESET_NAME\") | .id" 2>/dev/null || true) | |
| # Fetch existing rulesets. If no ruleset matches, --jq returns no output and | |
| # EXISTING_ID remains empty; unexpected gh/api failures should surface. | |
| EXISTING_ID=$(gh api "repos/$REPO/rulesets" \ | |
| --jq ".[] | select(.name == \"$RULESET_NAME\") | .id") |
Copilot
AI
Apr 8, 2026
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.
EXISTING_ID can contain multiple IDs if more than one ruleset shares the same name (the jq filter can emit multiple lines). That would make the subsequent PUT URL invalid. Consider selecting a single ID deterministically (e.g., first match) and/or failing if multiple matches are found.
| EXISTING_ID=$(gh api "repos/$REPO/rulesets" \ | |
| --jq ".[] | select(.name == \"$RULESET_NAME\") | .id" 2>/dev/null || true) | |
| mapfile -t EXISTING_IDS < <( | |
| gh api "repos/$REPO/rulesets" \ | |
| --jq ".[] | select(.name == \"$RULESET_NAME\") | .id" 2>/dev/null || true | |
| ) | |
| if [ "${#EXISTING_IDS[@]}" -gt 1 ]; then | |
| echo "ERROR: Multiple rulesets named $RULESET_NAME found for $REPO: ${EXISTING_IDS[*]}" >&2 | |
| exit 1 | |
| fi | |
| EXISTING_ID="${EXISTING_IDS[0]:-}" |
Copilot
AI
Apr 8, 2026
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.
The ruleset name is defined in RULESET_NAME but the payload hardcodes name: "code-quality". This duplication can lead to drift if the variable is ever updated. Prefer building the payload from RULESET_NAME to keep the script truly idempotent/maintainable.
| PAYLOAD=$(jq -n '{ | |
| name: "code-quality", | |
| PAYLOAD=$(jq -n --arg ruleset_name "$RULESET_NAME" '{ | |
| name: $ruleset_name, |
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.
Consider validating required CLI dependencies up front (e.g.,
ghandjq) and emitting a clear error if missing. Right now the script will fail later with less actionable messages likecommand not found, which makes recovery usage harder.