Skip to content

Commit

Permalink
feature/NONE Utility Script Quick Change PR (#11)
Browse files Browse the repository at this point in the history
* feat: NONE - Utility Script - Quick Change PR

* Add github login
  • Loading branch information
frinzekt authored Jun 24, 2024
1 parent 4c7c71a commit b030123
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 1 deletion.
5 changes: 4 additions & 1 deletion cfc-devenv-base/.devcontainer/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,7 @@ COPY ./utils /opt/utils
RUN cat "/opt/utils/.zshrc" >> "/home/${USERNAME}/.zshrc"

# Add a display script for every terminal run
RUN echo "/opt/utils/startup_display.sh" >> "/home/${USERNAME}/.zshrc"
RUN echo "/opt/utils/startup_display.sh" >> "/home/${USERNAME}/.zshrc"

# Add /opt/utils to the PATH
RUN echo "export PATH=\$PATH:/opt/utils" >> "/home/${USERNAME}/.zshrc"
57 changes: 57 additions & 0 deletions cfc-devenv-base/.devcontainer/utils/qc.sh
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

0 comments on commit b030123

Please sign in to comment.