Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -64,3 +64,4 @@ yarn-debug.log*
yarn-error.log*
.dev-lead/
.dev-lead/
.dev-lead/
110 changes: 110 additions & 0 deletions scripts/apply-repo-settings.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
#!/usr/bin/env bash
# apply-repo-settings.sh — Apply standard repository settings to petry-projects/broodly
#
# Applies settings defined in:
# https://github.com/petry-projects/.github/blob/main/standards/github-settings.md
#
# Settings managed:
# check-suite preferences — disables auto-trigger for the Claude GitHub App (ID 1236702)
# so that it no longer creates a perpetually-queued check suite on every push,
# which would otherwise block auto-merge indefinitely.
#
# Usage:
# GH_TOKEN=<admin-token> ./scripts/apply-repo-settings.sh [<repo>] [--dry-run] [--force]
#
# Arguments:
# <repo> Repository name (default: broodly). Positional, must come before flags.
#
# Requirements:
# - GH_TOKEN must have administration:write scope on this repo
# - gh CLI must be installed
# - jq must be installed

set -euo pipefail

ORG="petry-projects"
REPO="broodly"
DRY_RUN=false
FORCE=false

info() { echo "[INFO] $*"; }
ok() { echo "[OK] $*"; }
err() { echo "[ERROR] $*" >&2; }
skip() { echo "[SKIP] $*"; }

for arg in "$@"; do
case "$arg" in
--dry-run) DRY_RUN=true ;;
--force) FORCE=true ;;
-h|--help)
echo "Usage: $0 [<repo>] [--dry-run] [--force]"
echo " <repo> Repository name (default: broodly)"
echo " --force Skip repo-identity safety check (use when running from a fork or CI)"
exit 0
;;
-*) err "Unknown flag: $arg"; exit 1 ;;
*) REPO="$arg" ;;
esac
done
Comment on lines +35 to +48

if [ -z "${GH_TOKEN:-}" ]; then

Check failure on line 50 in scripts/apply-repo-settings.sh

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Use '[[' instead of '[' for conditional tests. The '[[' construct is safer and more feature-rich.

See more on https://sonarcloud.io/project/issues?id=petry-projects_broodly&issues=AZ5H83YaOoPJ8sHDBkW2&open=AZ5H83YaOoPJ8sHDBkW2&pullRequest=216
err "GH_TOKEN is required — provide a token with administration:write scope"
exit 1
fi

export GH_TOKEN

# Safety guard: verify the current git remote matches ORG/REPO.
# Prevents accidentally targeting the wrong repository when running from a fork
# or a different checkout that has administration access to petry-projects/broodly.
if [ "$FORCE" = false ]; then

Check failure on line 60 in scripts/apply-repo-settings.sh

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Use '[[' instead of '[' for conditional tests. The '[[' construct is safer and more feature-rich.

See more on https://sonarcloud.io/project/issues?id=petry-projects_broodly&issues=AZ5H83YaOoPJ8sHDBkW3&open=AZ5H83YaOoPJ8sHDBkW3&pullRequest=216
actual_repo=$(gh repo view --json nameWithOwner -q '.nameWithOwner' 2>/dev/null || true)
if [ -z "$actual_repo" ]; then

Check failure on line 62 in scripts/apply-repo-settings.sh

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Use '[[' instead of '[' for conditional tests. The '[[' construct is safer and more feature-rich.

See more on https://sonarcloud.io/project/issues?id=petry-projects_broodly&issues=AZ5H83YaOoPJ8sHDBkW4&open=AZ5H83YaOoPJ8sHDBkW4&pullRequest=216
err "Unable to determine current repo (gh repo view failed)."
err "Run with --force to skip this safety check, or ensure GH_TOKEN has repo read access."
exit 1
fi
if [ "$actual_repo" != "$ORG/$REPO" ]; then

Check failure on line 67 in scripts/apply-repo-settings.sh

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Use '[[' instead of '[' for conditional tests. The '[[' construct is safer and more feature-rich.

See more on https://sonarcloud.io/project/issues?id=petry-projects_broodly&issues=AZ5H83YaOoPJ8sHDBkW5&open=AZ5H83YaOoPJ8sHDBkW5&pullRequest=216
err "Current repo ($actual_repo) does not match target ($ORG/$REPO)."
err "Run with --force to override this safety check."
exit 1
fi
fi

# ---------------------------------------------------------------------------
# check-suite preferences
#
# Disable auto-trigger for the Claude GitHub App (ID 1236702).
#
# When auto-trigger is enabled, GitHub creates a queued check suite on every
# push. Because Claude does not complete these suites on its own, they remain
# in "queued" state permanently and block auto-merge on every PR.
#
# The App ID was obtained via:
# gh api /apps/claude --jq '.id'
# ---------------------------------------------------------------------------
CLAUDE_APP_ID=1236702

CHECK_SUITE_PAYLOAD=$(cat <<PAYLOAD
{
"auto_trigger_checks": [
{
"app_id": ${CLAUDE_APP_ID},
"setting": false
}
]
}
PAYLOAD
)

info "Configuring check-suite preferences for $ORG/$REPO ..."

if [ "$DRY_RUN" = true ]; then

Check failure on line 102 in scripts/apply-repo-settings.sh

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Use '[[' instead of '[' for conditional tests. The '[[' construct is safer and more feature-rich.

See more on https://sonarcloud.io/project/issues?id=petry-projects_broodly&issues=AZ5H83YaOoPJ8sHDBkW6&open=AZ5H83YaOoPJ8sHDBkW6&pullRequest=216
skip "DRY_RUN — would PATCH repos/$ORG/$REPO/check-suite/preferences:"
echo "$CHECK_SUITE_PAYLOAD" | jq '.'
else
echo "$CHECK_SUITE_PAYLOAD" | gh api -X PATCH "repos/$ORG/$REPO/check-suite/preferences" --input - > /dev/null

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Patch the check-suites preferences endpoint path

The script calls gh api -X PATCH repos/$ORG/$REPO/check-suite/preferences, but GitHub’s documented route for this operation is /repos/{owner}/{repo}/check-suites/preferences (plural check-suites). In scripts/apply-repo-settings.sh, this singular path will return a not-found error, and because set -e is enabled the script exits before applying any setting, so the intended auto-trigger disablement never happens outside dry-run mode.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Use check-suites preferences endpoint

Patch the request path to /repos/{owner}/{repo}/check-suites/preferences (plural), because the current check-suite/preferences route does not exist for this API. In non-dry-run mode this causes gh api to fail and, with set -euo pipefail, the script exits before applying any repository setting, so the intended auto-trigger disablement never happens.

Useful? React with 👍 / 👎.

ok "check-suite auto-trigger disabled for Claude app (ID=$CLAUDE_APP_ID)"
fi

ok "Done — repository settings applied to $ORG/$REPO"
Loading