From b0301234049168c0bea04621e567f34a6bd7f089 Mon Sep 17 00:00:00 2001 From: Frinze Erin Lapuz <44391389+frinzekt@users.noreply.github.com> Date: Mon, 24 Jun 2024 23:27:31 +0800 Subject: [PATCH] feature/NONE Utility Script Quick Change PR (#11) * feat: NONE - Utility Script - Quick Change PR * Add github login --- cfc-devenv-base/.devcontainer/Dockerfile | 5 +- cfc-devenv-base/.devcontainer/utils/qc.sh | 57 +++++++++++++++++++++++ 2 files changed, 61 insertions(+), 1 deletion(-) create mode 100755 cfc-devenv-base/.devcontainer/utils/qc.sh diff --git a/cfc-devenv-base/.devcontainer/Dockerfile b/cfc-devenv-base/.devcontainer/Dockerfile index dc5fd0c..29c6207 100644 --- a/cfc-devenv-base/.devcontainer/Dockerfile +++ b/cfc-devenv-base/.devcontainer/Dockerfile @@ -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" \ No newline at end of file +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" \ No newline at end of file diff --git a/cfc-devenv-base/.devcontainer/utils/qc.sh b/cfc-devenv-base/.devcontainer/utils/qc.sh new file mode 100755 index 0000000..6999c56 --- /dev/null +++ b/cfc-devenv-base/.devcontainer/utils/qc.sh @@ -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 \ No newline at end of file