Skip to content

Commit

Permalink
feat: Add commands to create PR, tag and untag
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewscwei committed Jul 8, 2024
1 parent db30df8 commit 3fd7b8a
Showing 1 changed file with 63 additions and 1 deletion.
64 changes: 63 additions & 1 deletion mu.sh
Original file line number Diff line number Diff line change
Expand Up @@ -581,6 +581,9 @@ function cmd_directory() {
echo
echo -e " GitHub:"
echo -e "${COLOR_CYAN} gist${COLOR_RESET} - Downloads all files from a gist to the working directory"
echo -e "${COLOR_CYAN} pr${COLOR_RESET} - Creates a local branch from the provided title, pushes it to remote and creates a PR from it with the same title"
echo -e "${COLOR_CYAN} tag${COLOR_RESET} - Creates a tag in both local and remote Git repository"
echo -e "${COLOR_CYAN} untag${COLOR_RESET} - Deletes a tag from both local and remote Git repository"
}

# Downloads all files from a Gist to the working directory individually. This
Expand All @@ -600,19 +603,78 @@ function cmd_gist() {
curl -sS --remote-name-all $(curl -sS https://api.github.com/gists/$1 | jq -r '.files[].raw_url')
}

# Creates a tag in both local and remote Git repository.
#
# @param $1 The tag to create.
function cmd_tag() {
if [[ "$1" == "-h" ]]; then
echo -e "${COLOR_PURPLE}HELP: ${COLOR_BLUE}mu ${COLOR_CYAN}tag <tag>${COLOR_RESET}"
echo
echo -e "Creates a ${COLOR_CYAN}<tag>${COLOR_RESET} in local and remote Git repository."
return
fi

git tag $1
git push --tags
}

# Deletes a tag from both local and remote Git repository.
#
# @param $1 The tag to delete.
function cmd_untag() {
if [[ "$1" == "-h" ]]; then
echo -e "${COLOR_PURPLE}HELP: ${COLOR_BLUE}mu ${COLOR_CYAN}untag <tag>${COLOR_RESET}"
echo
echo -e "Deletes ${COLOR_CYAN}<tag>${COLOR_RESET} from local and remote Git repository."
return
fi

git tag -d $1
git push -d origin $1
}

# Creates a local branch from the provided title, pushes it to remote and
# creates a PR from it with the same title.
#
# @param $1 The title of the PR.
function cmd_pr() {
if [[ "$1" == "-h" ]]; then
echo -e "${COLOR_PURPLE}HELP: ${COLOR_BLUE}mu ${COLOR_CYAN}pr <title>${COLOR_RESET}"
echo
echo -e "Creates a new local branch derived from ${COLOR_CYAN}<title>${COLOR_RESET}, pushes it to remote and creates a PR from it with the same ${COLOR_CYAN}<title>${COLOR_RESET}."
return
fi

local branch_name=$(echo "$1" |
sed 's/\([^:]*\):\{0,1\} \{0,1\}\(.*\)/\1\/\2/' | # Parse type
tr '[:upper:]' '[:lower:]' | # Convert to lowercase
tr -s ' ' | # Comporess consecutive spaces into one
tr ' ' '-' | # Replace spaces with hyphens
sed 's/^-//' | # Remove leading hyphen if any
sed 's/\/-/\//g' # Remove hyphen after / if any
)

git checkout -b $branch_name
git push origin $branch_name
gh pr create -t $1
}

# Main process.
if [[ "$1" == "" ]] || [[ "$1" == "help" ]] || [[ "$1" == "h" ]]; then cmd_directory $2
elif [[ "$1" == "add" ]] || [[ "$1" == "a" ]]; then cmd_add $2
elif [[ "$1" == "cache" ]]; then cmd_cache $2
elif [[ "$1" == "cd" ]]; then cmd_cd $2
elif [[ "$1" == "clean" ]]; then cmd_clean $2
elif [[ "$1" == "gist" ]]; then cmd_gist $2
elif [[ "$1" == "list" ]] || [[ "$1" == "ls" ]] || [[ "$1" == "l" ]]; then cmd_list $2
elif [[ "$1" == "edit" ]]; then cmd_edit_registry $2
elif [[ "$1" == "open" ]] || [[ "$1" == "o" ]]; then cmd_open $2
elif [[ "$1" == "remove" ]] || [[ "$1" == "rm" ]] || [[ "$1" == "r" ]]; then cmd_remove $2
elif [[ "$1" == "project" ]] || [[ "$1" == "p" ]]; then cmd_project $2
elif [[ "$1" == "version" ]] || [[ "$1" == "-v" ]]; then echo -e "v$VERSION"
elif [[ "$1" == "gist" ]]; then cmd_gist $2
elif [[ "$1" == "pr" ]]; then cmd_pr $2
elif [[ "$1" == "tag" ]]; then cmd_tag $2
elif [[ "$1" == "untag" ]]; then cmd_untag $2
else echo -e "${COLOR_BLUE}mu: ${COLOR_RESET}Unsupported command:" $1
fi

Expand Down

0 comments on commit 3fd7b8a

Please sign in to comment.