-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feature/NONE Utility Script Quick Change PR (#11)
* feat: NONE - Utility Script - Quick Change PR * Add github login
- Loading branch information
Showing
2 changed files
with
61 additions
and
1 deletion.
There are no files selected for viewing
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
#!/bin/bash | ||
|
||
set -euxo pipefail | ||
|
||
# Make sure gh is setup | ||
# gh auth status returns 0 if the user is logged in and 1 if the user is not logged in | ||
if ! gh auth status; then | ||
echo "Please login to GitHub using gh auth login" | ||
gh auth login -p ssh -w | ||
fi | ||
|
||
# This script is used to do a quick change | ||
# Usage: qc.sh "Issue number" "Description" | ||
|
||
ISSUE_NUMBER=$1 | ||
DESCRIPTION=$2 | ||
|
||
# Validate input | ||
if [ -z "$ISSUE_NUMBER" ]; then | ||
echo "Issue number is required" | ||
exit 1 | ||
fi | ||
|
||
# Description cannot have special characters except "-" | ||
if [[ ! "$DESCRIPTION" =~ ^[a-zA-Z0-9\ -]+$ ]]; then | ||
echo "Description can only have alphabets, numbers, and hyphen" | ||
exit 1 | ||
fi | ||
|
||
# Reset to root directory | ||
cd "$(git rev-parse --show-toplevel || echo .)" | ||
|
||
# Stash all change | ||
git stash --include-untracked | ||
|
||
# Checkout to main branch | ||
git checkout main | ||
|
||
# Pull latest changes | ||
git pull | ||
|
||
# Checkout to the branch | ||
DESCRIPTION_HYPHEN=$(echo $DESCRIPTION | tr ' ' '-') | ||
git checkout -b "feature/$ISSUE_NUMBER-$DESCRIPTION_HYPHEN" | ||
|
||
# Apply the stash | ||
git stash pop | ||
|
||
# Commit the changes | ||
git add . | ||
git commit -m "feat: $ISSUE_NUMBER - $DESCRIPTION" | ||
|
||
# Push the changes | ||
git push --set-upstream origin "feature/$ISSUE_NUMBER-$DESCRIPTION_HYPHEN" | ||
|
||
# Open the PR | ||
gh pr create --title "feat: $ISSUE_NUMBER - $DESCRIPTION" --body "Closes #$ISSUE_NUMBER" --base main |