Created
September 30, 2026 15:41
-
-
Save nixpanic/dd3e9d92cfe7be163ccc39bdb9785ec9 to your computer and use it in GitHub Desktop.
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
| #!/usr/bin/env bash | |
| # force-ci-success.sh — Override a failed CI context to "success" for a PR. | |
| # | |
| # The target URL of the original status is preserved so the failure can | |
| # still be inspected. | |
| # | |
| # Usage: | |
| # ./scripts/force-ci-success.sh <PR-number> <context> <reason> | |
| # | |
| # Example: | |
| # ./scripts/force-ci-success.sh 4900 "ci/jenkins/build" "Flake, retest passed locally" | |
| set -euo pipefail | |
| REPO="$(gh repo view --json nameWithOwner --jq .nameWithOwner)" | |
| usage() { | |
| echo "Usage: $0 <PR-number> <context> <reason>" | |
| echo "" | |
| echo " PR-number GitHub pull request number" | |
| echo " context CI status context to override (e.g. ci/jenkins/build)" | |
| echo " reason Short note explaining why the failure is overridden" | |
| exit 1 | |
| } | |
| [[ $# -lt 3 ]] && usage | |
| PR_NUMBER="$1" | |
| CONTEXT="$2" | |
| REASON="$3" | |
| # Resolve the head SHA for the PR. | |
| SHA=$(gh api "repos/${REPO}/pulls/${PR_NUMBER}" --jq '.head.sha') | |
| if [[ -z "${SHA}" ]]; then | |
| echo "ERROR: could not resolve SHA for PR #${PR_NUMBER}" >&2 | |
| exit 1 | |
| fi | |
| echo "PR #${PR_NUMBER} → SHA: ${SHA}" | |
| # Find the most recent status for this context so we can keep its target_url. | |
| TARGET_URL=$(gh api "repos/${REPO}/commits/${SHA}/statuses" \ | |
| --jq "[.[] | select(.context == \"${CONTEXT}\")] | first | .target_url // empty") | |
| if [[ -z "${TARGET_URL}" ]]; then | |
| echo "WARNING: no existing status found for context '${CONTEXT}'; target_url will be empty." | |
| TARGET_URL="" | |
| fi | |
| echo "Context: ${CONTEXT}" | |
| echo "Target URL: ${TARGET_URL:-<none>}" | |
| echo "Reason: ${REASON}" | |
| echo "" | |
| # Post the new success status. | |
| gh api "repos/${REPO}/statuses/${SHA}" \ | |
| --method POST \ | |
| --field state="success" \ | |
| --field context="${CONTEXT}" \ | |
| --field description="${REASON}" \ | |
| --field target_url="${TARGET_URL}" \ | |
| --jq '"Created status: \(.state) for \(.context) at \(.created_at)"' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment