Skip to content

fix: add code-quality repository ruleset (closes #51)#77

Merged
don-petry merged 1 commit intomainfrom
claude/issue-51-20260408-0149
Apr 8, 2026
Merged

fix: add code-quality repository ruleset (closes #51)#77
don-petry merged 1 commit intomainfrom
claude/issue-51-20260408-0149

Conversation

@don-petry
Copy link
Copy Markdown
Contributor

@don-petry don-petry commented Apr 8, 2026

Summary

  • Creates the required code-quality repository ruleset directly via the GitHub API (already active as of this PR — ruleset id 14805963)
  • Adds .github/scripts/apply-code-quality-ruleset.sh for idempotent future maintenance

What was done

The code-quality ruleset is now live on petry-projects/markets and enforces these required status checks on the default branch:

Check Source
SonarCloud sonarcloud.yml, job sonarcloud
Analyze (actions) codeql.yml, matrix job analyze (actions ecosystem)
claude-code / claude claude.yml, calling reusable workflow job

Settings: strict_required_status_checks_policy: true (branch must be up to date before merging).

Why a script in the repo?

The org-level apply-rulesets.sh is the canonical tool for bulk management. This repo-local script exists as a reference and recovery tool specifically for markets — useful if the ruleset is accidentally deleted.

Closes #51

Generated with Claude Code

Summary by CodeRabbit

  • Chores
    • Enhanced infrastructure for automated code quality enforcement and compliance checks.

Copilot AI review requested due to automatic review settings April 8, 2026 01:53
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Apr 8, 2026

📝 Walkthrough

Walkthrough

Adds a new Bash script that idempotently creates or updates a GitHub "code-quality" repository ruleset with required status checks for SonarCloud, Analyze (actions), and claude-code/claude on the default branch using the GitHub CLI and jq.

Changes

Cohort / File(s) Summary
GitHub Ruleset Management Script
.github/scripts/apply-code-quality-ruleset.sh
New executable script that manages code-quality ruleset configuration; performs token validation, queries existing rulesets via GitHub API, constructs JSON payload with three required status checks, and either updates existing ruleset via PUT or creates new one via POST.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

  • Add Claude Code GitHub Action #12 — Introduces Claude Code GitHub Action workflow that provides the "claude-code / claude" status check required by this ruleset configuration.
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title directly and accurately reflects the main change: adding a code-quality repository ruleset and referencing the closed issue #51.
Linked Issues check ✅ Passed The PR successfully implements the compliance remediation required by issue #51: creating the code-quality ruleset with required status checks enforcement as per the organization standard.
Out of Scope Changes check ✅ Passed The single file addition (apply-code-quality-ruleset.sh) is directly in scope, providing an idempotent script for managing the code-quality ruleset required by issue #51.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch claude/issue-51-20260408-0149

Comment @coderabbitai help to get the list of available commands and usage tips.

@don-petry
Copy link
Copy Markdown
Contributor Author

@don-petry — the code-quality ruleset is now active on the default branch (created directly via API, not blocked behind a script this time). Please review and merge when ready.

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds a repo-local, idempotent maintenance script to create/update the GitHub “code-quality” repository ruleset for petry-projects/markets, aligning the repo with the org compliance requirement for required status checks on the default branch.

Changes:

  • Added a Bash script that uses gh api + jq to upsert the code-quality ruleset.
  • Encoded the required status check contexts (SonarCloud, Analyze (actions), claude-code / claude) with strict “branch up-to-date” enforcement.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

echo "ERROR: GH_TOKEN is required with administration:write scope" >&2
exit 1
fi

Copy link

Copilot AI Apr 8, 2026

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., gh and jq) and emitting a clear error if missing. Right now the script will fail later with less actionable messages like command not found, which makes recovery usage harder.

Suggested change
MISSING_DEPENDENCY=0
for cmd in gh jq; do
if ! command -v "$cmd" >/dev/null 2>&1; then
echo "ERROR: Required CLI dependency '$cmd' is not installed or not on PATH" >&2
MISSING_DEPENDENCY=1
fi
done
if [ "$MISSING_DEPENDENCY" -ne 0 ]; then
exit 1
fi

Copilot uses AI. Check for mistakes.
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)
Copy link

Copilot AI Apr 8, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

gh api repos/$REPO/rulesets errors are currently suppressed (2>/dev/null || true). This can mask real failures (bad auth, missing permissions, API changes) and cause the script to behave as if no ruleset exists. Prefer surfacing errors, or explicitly handle only the expected “not found/empty list” cases.

Suggested change
# 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 uses AI. Check for mistakes.
Comment on lines +35 to +37
EXISTING_ID=$(gh api "repos/$REPO/rulesets" \
--jq ".[] | select(.name == \"$RULESET_NAME\") | .id" 2>/dev/null || true)

Copy link

Copilot AI Apr 8, 2026

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.

Suggested change
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 uses AI. Check for mistakes.
Comment on lines +38 to +39
PAYLOAD=$(jq -n '{
name: "code-quality",
Copy link

Copilot AI Apr 8, 2026

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.

Suggested change
PAYLOAD=$(jq -n '{
name: "code-quality",
PAYLOAD=$(jq -n --arg ruleset_name "$RULESET_NAME" '{
name: $ruleset_name,

Copilot uses AI. Check for mistakes.
Adds .github/scripts/apply-code-quality-ruleset.sh — an idempotent
script that creates or updates the required `code-quality` repository
ruleset for petry-projects/markets.

The ruleset itself has already been created directly via the GitHub API
(ruleset id 14805963) and is now active on the default branch, enforcing
these required status checks:
  - SonarCloud
  - Analyze (actions)  (CodeQL, actions ecosystem)
  - claude-code / claude

The script serves as a repo-local reference and allows re-creation if
the ruleset is ever accidentally deleted or needs updating.

Closes #51

Co-authored-by: don-petry <don-petry@users.noreply.github.com>
@don-petry don-petry force-pushed the claude/issue-51-20260408-0149 branch from e9f5ddc to 4943fa8 Compare April 8, 2026 02:25
@sonarqubecloud
Copy link
Copy Markdown

sonarqubecloud Bot commented Apr 8, 2026

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (1)
.github/scripts/apply-code-quality-ruleset.sh (1)

35-36: Consider preserving error details for debugging.

Suppressing stderr with 2>/dev/null hides auth or network errors. For a maintenance script, capturing errors while still allowing the script to continue would improve troubleshooting.

🔧 Optional improvement to log errors
-EXISTING_ID=$(gh api "repos/$REPO/rulesets" \
-  --jq ".[] | select(.name == \"$RULESET_NAME\") | .id" 2>/dev/null || true)
+EXISTING_ID=$(gh api "repos/$REPO/rulesets" \
+  --jq ".[] | select(.name == \"$RULESET_NAME\") | .id" || true)
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In @.github/scripts/apply-code-quality-ruleset.sh around lines 35 - 36, The
current gh API call that sets EXISTING_ID hides stderr with 2>/dev/null; change
it to capture stderr into a variable and preserve the existing || true so the
script continues—run the gh api command for EXISTING_ID (using REPO and
RULESET_NAME), redirect or capture stderr into a separate variable (e.g., ERR),
keep the jq extraction, and after the call log or echo the ERR content to stderr
if non-empty so authentication/network errors are visible for debugging while
still allowing the script to proceed.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In @.github/scripts/apply-code-quality-ruleset.sh:
- Around line 35-36: The current gh API call that sets EXISTING_ID hides stderr
with 2>/dev/null; change it to capture stderr into a variable and preserve the
existing || true so the script continues—run the gh api command for EXISTING_ID
(using REPO and RULESET_NAME), redirect or capture stderr into a separate
variable (e.g., ERR), keep the jq extraction, and after the call log or echo the
ERR content to stderr if non-empty so authentication/network errors are visible
for debugging while still allowing the script to proceed.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 22ce9980-e42f-42e9-a81a-6cb99a920958

📥 Commits

Reviewing files that changed from the base of the PR and between 5bb65c2 and 4943fa8.

📒 Files selected for processing (1)
  • .github/scripts/apply-code-quality-ruleset.sh

@don-petry don-petry merged commit 92b306a into main Apr 8, 2026
15 checks passed
@don-petry don-petry deleted the claude/issue-51-20260408-0149 branch April 8, 2026 02:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Compliance: missing-code-quality

2 participants