Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: add change base branch script #2082

Merged
merged 3 commits into from
Sep 6, 2024
Merged
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
57 changes: 57 additions & 0 deletions scripts/change_base_branch.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
#!/bin/bash

lklimek marked this conversation as resolved.
Show resolved Hide resolved
set -e -o pipefail

# Function to display help
show_help() {
echo "Usage: $0 OLD_BASE NEW_BASE"
echo ""
echo "Change the base branch for all open PRs from OLD_BASE to NEW_BASE."
echo ""
echo "Arguments:"
echo " OLD_BASE The current base branch to change from."
echo " NEW_BASE The new base branch to change to."
echo ""
echo "Options:"
echo " -h Display this help message."
}

# Parse command-line options
while getopts "h" opt; do
case $opt in
h) show_help
exit 0 ;;
\?) echo "Invalid option: -$OPTARG" >&2
show_help
exit 1 ;;
esac
done

# Shift the parsed options away to handle positional arguments
shift $((OPTIND -1))

# Check if the correct number of arguments are provided
if [ "$#" -ne 2 ]; then
echo "Error: OLD_BASE and NEW_BASE are required."
show_help
exit 1
fi

# Assign positional arguments to variables
old_base_branch="$1"
new_base_branch="$2"

# List PRs and change base branch
prs=$(gh pr list --base "$old_base_branch" --json number --jq '.[].number')

if [ -z "$prs" ]; then
echo "No PRs found with base branch '$old_base_branch'."
exit 0
fi

for pr in $prs; do
echo "Updating PR #$pr from base '$old_base_branch' to '$new_base_branch'..."
gh pr edit "$pr" --base "$new_base_branch"
done

echo "Base branch update complete."
Loading