Skip to content

Instantly share code, notes, and snippets.

@BlueBeret
Created May 21, 2025 11:10
Show Gist options
  • Save BlueBeret/be91d5485145aff80528c2c792f25293 to your computer and use it in GitHub Desktop.
Save BlueBeret/be91d5485145aff80528c2c792f25293 to your computer and use it in GitHub Desktop.
Script to open hotfixes PR
#!/bin/zsh
# CONFIG
REPO_BASE_URL="https://github.com/StackGuardian/dashboard" # Change this to your repo
CODE_EDITOR="code" # or "code", "vim", etc.
PR_TEMPLATE_FILE="/tmp/pr_template.md" # Temporary file for PR template
DASH_BASE_BRANCH="develop" # Change as needed
PROD_BASE_BRANCH="main" # Change as needed
# REQUIRED COMMANDS CHECK
for cmd in git gh $CODE_EDITOR; do
if ! command -v $cmd >/dev/null 2>&1; then
echo "❌ Required command '$cmd' not found. Please install it."
exit 1
fi
done
# CHECK CURRENT BRANCH
current_branch=$(git symbolic-ref --short HEAD)
echo "Current branch: $current_branch"
# CHECK IF ALREADY PUSHED
echo "Checking if remote branch '$current_branch' exists..."
if ! git ls-remote --exit-code --heads origin "$current_branch" > /dev/null 2>&1; then
echo "❌ Remote branch '$current_branch' does not exist."
exit 1
fi
# ASK TO PROCEED
read "use_current?Do you want to use this branch ($current_branch)? [Y/n]: "
if [[ "$use_current" =~ ^[Nn]$ ]]; then
echo "Aborted by user."
exit 0
fi
# COLLECT PR INFO
read "pr_title?Enter pull request title: "
read "bug_link?Enter bug link (Notion/jam): "
# SELECT BLAST RADIUS
echo "Select blast radius (1-5):"
echo "1. 🟒 Very Low"
echo "2. 🟑 Low"
echo "3. 🟠 Medium"
echo "4. πŸ”΄ High"
echo "5. ⚠️ Very High"
read "blast_radius?Enter choice (1-5): "
# GENERATE PR TEMPLATE
blast_list=(
"- [x] **🟒 Very Low** – Isolated change, minimal impact, affects a single, non-critical component."
"- [x] **🟑 Low** – Minor changes, limited impact, affects a small number of components."
"- [x] **🟠 Medium** – Moderate changes, potential impact on several components, requires careful review."
"- [x] **πŸ”΄ High** – Significant changes, widespread impact, affects critical systems, requires extensive testing."
"- [x] **⚠️ Very High** – Major changes, potentially disruptive, affects core infrastructure, requires immediate attention and a rollback plan."
)
blast_radius_output="${blast_list[$blast_radius]}"
if [[ -z "$blast_radius_output" ]]; then
echo "❌ Invalid blast radius selection."
exit 1
fi
cat > "$PR_TEMPLATE_FILE" <<EOF
## Pull Request Description
### Description
<!-- Provide a detailed description of the changes. What problem does it solve? -->
### Bug link
$bug_link
### What type of change is this? (check all that apply)
- [x] πŸ› Bug fix (non-breaking change which fixes an issue)
- [ ] πŸ”§ Technical debt/refactoring
### Blast Radius
Please select the expected impact level of your changes by marking the appropriate option:
${blast_radius_output}
### Screenshots/Recordings
<!-- If applicable, add screenshots or recordings to help explain your changes -->
### Additional Notes
<!-- Any additional information that reviewers should know -->
EOF
# OPEN EDITOR
echo "Opening PR template in $CODE_EDITOR..."
echo "Waiting for you to close the file..."
if [[ "$CODE_EDITOR" == "code" ]]; then
code --wait "$PR_TEMPLATE_FILE"
elif [[ "$CODE_EDITOR" == "nvim" || "$CODE_EDITOR" == "vim" ]]; then
"$CODE_EDITOR" -c "autocmd VimLeave * qa!" "$PR_TEMPLATE_FILE"
else
"$CODE_EDITOR" "$PR_TEMPLATE_FILE"
echo "⚠️ Warning: Might not wait if your editor forks. Use 'code' or 'vim/nvim'."
fi
echo "Editor closed."
# CREATE PRs AND CAPTURE LINKS
prod_pr_output=$(gh pr create --base "$PROD_BASE_BRANCH" --head "$current_branch" \
--title "Hotfix(prod): $pr_title" \
--body-file "$PR_TEMPLATE_FILE" 2>&1)
if [[ $? -ne 0 ]]; then
echo "❌ Failed to create PROD PR:"
echo "$prod_pr_output"
exit 1
fi
prod_pr_url=$(echo "$prod_pr_output" | tail -n1)
dash_pr_output=$(gh pr create --base "$DASH_BASE_BRANCH" --head "$current_branch" \
--title "Hotfix(dash): $pr_title" \
--body-file "$PR_TEMPLATE_FILE" 2>&1)
if [[ $? -ne 0 ]]; then
echo "❌ Failed to create DASH PR:"
echo "$dash_pr_output"
exit 1
fi
dash_pr_url=$(echo "$dash_pr_output" | tail -n1)
# FINAL OUTPUT
echo ""
echo "Hotfix for: $bug_link"
echo "DASH: $dash_pr_url"
echo "PROD: $prod_pr_url"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment