Skip to content

Instantly share code, notes, and snippets.

@vctqs1
Created June 2, 2024 04:18
Show Gist options
  • Save vctqs1/eec27ca59b4561bbd08ff8033fbb1ffc to your computer and use it in GitHub Desktop.
Save vctqs1/eec27ca59b4561bbd08ff8033fbb1ffc to your computer and use it in GitHub Desktop.
#!/bin/bash
# This script cherry-picks the commits from a PR
# Usage: ./cherry_pick_pr.sh <pr-number>
set -e
PR_NUMBER=$1
# Check if PR number is provided
if [ -z "$PR_NUMBER" ]; then
echo "Usage: $0 <pr-number>"
exit 1
fi
# Fetch the commit information for the specified PR
COMMIT_INFO=$(gh pr view $PR_NUMBER --json commits)
echo "Commit information for PR $PR_NUMBER:"
echo "$COMMIT_INFO"
while IFS= read -r commit_info; do
id=$(echo $commit_info | jq -r '.oid')
msg=$(echo $commit_info | jq -r '.messageHeadline')
# Ignore if the commit message contains "Merge pull request"
# Ignore if msg is merge develop "Merge branch 'develop' into "
if [[ $msg == Merge* ]]; then
continue
fi
# Cherry-pick the commit
git cherry-pick $id
done < <(echo $COMMIT_INFO | jq -r -c '.commits[]')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment