-
-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(script): create pull request against develop script (#40)
- Loading branch information
1 parent
c115626
commit 1a4a964
Showing
5 changed files
with
80 additions
and
23 deletions.
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
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 |
---|---|---|
@@ -1,32 +1,31 @@ | ||
#!/bin/bash | ||
PS3="Are you starting a feature or a fix ? "; | ||
select option in "feat" "fix"; | ||
do | ||
PS3="Are you starting a feature or a fix ? " | ||
select option in "feat" "fix"; do | ||
case $option in | ||
feat|fix) | ||
SELECTED_OPTION=$option; | ||
break; | ||
;; | ||
*) | ||
echo "Invalid option: \"$REPLY\". Please choose between 1 or 2 you ding-dong."; | ||
;; | ||
feat | fix) | ||
SELECTED_OPTION=$option | ||
break | ||
;; | ||
*) | ||
echo "❌ Invalid option: \"$REPLY\". Please choose between 1 or 2 you ding-dong." | ||
;; | ||
esac | ||
done | ||
|
||
while true; do | ||
echo "Please provide your branch name, it must be kebab-case (like: 'my-feature') : "; | ||
read -r FEATURE_NAME; | ||
echo "Please provide your branch name, it must be kebab-case (like: 'my-feature') : " | ||
read -r FEATURE_NAME | ||
if [[ -z "$FEATURE_NAME" ]]; then | ||
echo "You must provide a branch name."; | ||
continue; | ||
echo "You must provide a branch name." | ||
continue | ||
fi | ||
if ! [[ "$FEATURE_NAME" =~ ^[a-z]+(-[a-z]+)*$ ]]; then | ||
echo "Your branch name must be in kebab-case."; | ||
continue; | ||
echo "❌ Your branch name must be in kebab-case." | ||
continue | ||
fi | ||
break; | ||
break | ||
done | ||
|
||
BRANCH_NAME="$SELECTED_OPTION/$FEATURE_NAME"; | ||
git checkout -b "$BRANCH_NAME"; | ||
echo "You're all set 🚀"; | ||
BRANCH_NAME="$SELECTED_OPTION/$FEATURE_NAME" | ||
git checkout -b "$BRANCH_NAME" | ||
echo "You're all set 🚀" |
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,47 @@ | ||
#!/bin/bash | ||
|
||
base_branch=${1:-develop} | ||
current_branch=$(git rev-parse --abbrev-ref HEAD) | ||
|
||
if [ "$(git rev-list --count "$base_branch".."$current_branch")" -gt 0 ]; then | ||
echo "Opening pull request for $current_branch against $base_branch..." | ||
else | ||
echo "❌ Current branch ($current_branch) has no commits yet. Please make at least one commit." | ||
exit 1 | ||
fi | ||
|
||
remote_url=$(git config --get remote.origin.url) | ||
|
||
if [[ "$remote_url" =~ github\.com\/(.+)\/(.+)\.git$ ]]; then | ||
username=${BASH_REMATCH[1]} | ||
repository=${BASH_REMATCH[2]} | ||
elif [[ "$remote_url" =~ git@github\.com:(.+)\/(.+)\.git$ ]]; then | ||
username=${BASH_REMATCH[1]} | ||
repository=${BASH_REMATCH[2]} | ||
else | ||
echo "❌ Unable to extract username and repository from the remote URL: $remote_url" | ||
exit 1 | ||
fi | ||
|
||
if [ "$current_branch" = "$base_branch" ]; then | ||
echo "❌ The current branch is already the same as the base branch." | ||
exit 1 | ||
fi | ||
|
||
pr_url=$(curl -s "https://api.github.com/repos/$username/$repository/pulls?head=$username:$current_branch&base=$base_branch" | grep -Eo "https://github.com/$username/$repository/pull/[0-9]+" | head -n 1) | ||
|
||
if [ -n "$pr_url" ]; then | ||
echo "❌ A pull request already exists for $current_branch against $base_branch: $pr_url" | ||
exit 1 | ||
else | ||
git push -u origin "$current_branch" | ||
|
||
if [[ "$OSTYPE" == "darwin"* ]]; then | ||
open "https://github.com/$username/$repository/compare/$base_branch...$current_branch?expand=1" | ||
elif [[ "$OSTYPE" == "linux-gnu"* ]]; then | ||
xdg-open "https://github.com/$username/$repository/compare/$base_branch...$current_branch?expand=1" | ||
else | ||
echo "❌ Unsupported OS for automatically open the pull request creation page" | ||
exit 1 | ||
fi | ||
fi |