diff --git a/scripts/apply-repo-settings.sh b/scripts/apply-repo-settings.sh index 4d5cc85f..16fd3a69 100755 --- a/scripts/apply-repo-settings.sh +++ b/scripts/apply-repo-settings.sh @@ -170,10 +170,10 @@ PAYLOAD info "Configuring check-suite preferences for $ORG/$REPO ..." if [ "$DRY_RUN" = true ]; then - skip "DRY_RUN — would PATCH repos/$ORG/$REPO/check-suite/preferences:" + skip "DRY_RUN — would PATCH repos/$ORG/$REPO/check-suites/preferences:" echo "$CHECK_SUITE_PAYLOAD" | jq '.' else - echo "$CHECK_SUITE_PAYLOAD" | gh api -X PATCH "repos/$ORG/$REPO/check-suite/preferences" --input - > /dev/null + echo "$CHECK_SUITE_PAYLOAD" | gh api -X PATCH "repos/$ORG/$REPO/check-suites/preferences" --input - > /dev/null ok "check-suite auto-trigger disabled for Claude (ID=$CLAUDE_APP_ID) and CodeRabbit (ID=$CODERABBIT_APP_ID)" fi diff --git a/tests/integration/apply-repo-settings.bats b/tests/integration/apply-repo-settings.bats new file mode 100644 index 00000000..5271c5a1 --- /dev/null +++ b/tests/integration/apply-repo-settings.bats @@ -0,0 +1,62 @@ +#!/usr/bin/env bats +# Integration tests for scripts/apply-repo-settings.sh +# +# These tests stub the `gh` and `jq` CLIs so the script can run without network +# access or real credentials, and assert that it targets the correct GitHub REST +# endpoint for check-suite preferences (`check-suites/preferences`, plural). + +setup() { + REPO_ROOT="$(cd "$BATS_TEST_DIRNAME/../.." && pwd)" + SCRIPT="$REPO_ROOT/scripts/apply-repo-settings.sh" + + BIN_DIR="$BATS_TEST_TMPDIR/bin" + mkdir -p "$BIN_DIR" + CALL_LOG="$BATS_TEST_TMPDIR/gh-calls.log" + + # Mock `gh`: record every invocation, satisfy the repo-identity safety check, + # and succeed on the PATCH without making a network call. + cat > "$BIN_DIR/gh" <> "$CALL_LOG" +if [ "\$1" = "repo" ] && [ "\$2" = "view" ]; then + echo "petry-projects/broodly" + exit 0 +fi +# Drain stdin for the PATCH --input - call so the pipe does not break. +if [ "\$1" = "api" ]; then + cat > /dev/null 2>&1 || true + exit 0 +fi +exit 0 +MOCK + chmod +x "$BIN_DIR/gh" + + # Mock `jq`: pass stdin through to stdout so dry-run output works without + # requiring jq to be installed on the host. + cat > "$BIN_DIR/jq" <