Last active
May 13, 2025 10:24
-
-
Save michael-rubel/32315e60b55ca215da871a575a93d017 to your computer and use it in GitHub Desktop.
Oro Product | Maintenance script
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
#!/bin/bash | |
set -e | |
# --- Configuration --- | |
# Define the list of target branches. | |
branches=("master" "maintenance/6.1" "maintenance/6.0") | |
# Build an array of branch suffixes from the defined branches. | |
suffixes=() | |
for b in "${branches[@]}"; do | |
suffix="${b//\//-}" | |
suffixes+=("$suffix") | |
done | |
# Get the current branch name (assumed to be your feature/bugfix branch) | |
current_branch=$(git rev-parse --abbrev-ref HEAD) | |
echo "Current branch: $current_branch" | |
# Extract the most recent commit's title from the current branch. | |
recent_commit_title=$(git log -1 --pretty=%B "$current_branch" | head -n 1) | |
echo "Recent commit title: $recent_commit_title" | |
# Get the commits that match recent commit title. | |
get_commits() { | |
git log --grep="$recent_commit_title" --format="%H" "$current_branch" --reverse | |
} | |
commits=$(get_commits) | |
echo "Commits to cherry-pick:" | |
echo "$commits" | |
# --- Loop over each target branch --- | |
for target in "${branches[@]}"; do | |
echo "=======================================" | |
echo "Processing target branch: $target" | |
# Checkout and update the target branch. | |
git checkout "$target" | |
git pull origin "$target" | |
# Build the branch suffix for this target (e.g. maintenance/6.1 becomes maintenance-6.1) | |
target_suffix="${target//\//-}" | |
new_branch="${current_branch}-${target_suffix}" | |
echo "Creating new branch: $new_branch from $target" | |
git checkout -b "$new_branch" | |
# Cherry-pick each commit onto the new branch. | |
# The commits are applied in the order returned by get_commits. | |
for commit in $commits; do | |
echo "Cherry-picking commit: $commit" | |
git cherry-pick "$commit" | |
done | |
# Push the branch (whether new or already existing) to the remote repository. | |
echo "Pushing branch $new_branch to origin" | |
git push -u origin "$new_branch" | |
# Create a new Pull Request using gh CLI. | |
pr_title="${recent_commit_title} (${target_suffix})" | |
pr_body="Automated PR to apply commits from '$current_branch' to '$target'." | |
echo "Creating PR: Base: $target, Head: $new_branch" | |
pr_url=$(gh pr create --base "$target" --head "$new_branch" --title "$pr_title" --body "$pr_body") | |
echo "Created PR: $pr_url" | |
# # Run the tests: post a comment on the PR. | |
# sleep 3 | |
# comment1="Test it please" | |
# gh pr comment "$pr_url" --body "$comment1" | |
done | |
# Return to the original branch. | |
git checkout "$current_branch" | |
echo "=======================================" | |
echo "Process completed!" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment