Created
February 6, 2025 11:55
-
-
Save dims/01303202e5a71e37e8dfad40eb48e63b to your computer and use it in GitHub Desktop.
Script to skip certain jobs in a PR
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 | |
# Default repository and job name | |
REPO="google/cadvisor" | |
JOB_NAME="pull-cadvisor-e2e" | |
# Function to display usage | |
usage() { | |
echo "Usage: $0 -p <PR_NUMBER> [-j <JOB_NAME>] [-s <SHA>] [-r <REPOSITORY>]" | |
echo "Example: $0 -p 3615" | |
echo "Example: $0 -p 3615 -j custom-job-name" | |
echo "Example: $0 -p 3615 -s 631710f1652d62c72c714a760f66b2f55291243e" | |
echo "Example: $0 -p 3615 -r yourusername/yourrepo" | |
exit 1 | |
} | |
# Parse command-line arguments | |
while getopts ":p:j:s:r:" opt; do | |
case ${opt} in | |
p) PR_NUMBER="$OPTARG" ;; | |
j) JOB_NAME="$OPTARG" ;; | |
s) SHA="$OPTARG" ;; | |
r) REPO="$OPTARG" ;; | |
*) usage ;; | |
esac | |
done | |
# Check if required parameters are provided | |
if [ -z "$PR_NUMBER" ]; then | |
usage | |
fi | |
# If SHA is not provided, fetch it from the PR | |
if [ -z "$SHA" ]; then | |
echo "SHA not provided. Fetching the latest commit SHA from PR #${PR_NUMBER}..." | |
SHA=$(gh pr view "$PR_NUMBER" --repo "$REPO" --json commits --jq '.commits[-1].oid') | |
if [ -z "$SHA" ]; then | |
echo "Error: Unable to fetch SHA from PR #${PR_NUMBER}." | |
exit 1 | |
fi | |
echo "Using SHA: $SHA" | |
fi | |
# Construct the target URL | |
TARGET_URL="https://github.com/${REPO}/pull/${PR_NUMBER}/checks" | |
# Make the API request | |
gh api \ | |
--method POST \ | |
-H "Accept: application/vnd.github+json" \ | |
-H "X-GitHub-Api-Version: 2022-11-28" \ | |
-f "state=success" \ | |
-f "target_url=${TARGET_URL}" \ | |
-f "description=Skipped this prow build!" \ | |
-f "context=${JOB_NAME}" \ | |
"/repos/${REPO}/statuses/${SHA}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment