This repository has been archived by the owner on Aug 25, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathbin
executable file
·63 lines (53 loc) · 2.31 KB
/
bin
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#!/usr/bin/env bash
# _ _
# | | | |
# | |__ _ _ _ __ ___ _ __ ___| |__
# | '_ \| | | | '_ ` _ \| '_ \ / __| '_ \
# | |_) | |_| | | | | | | |_) |\__ \ | | |
# |_.__/ \__,_|_| |_| |_| .__(_)___/_| |_|
# | |
# |_|
# by @rakshazi
PREFIX="\033[0;32m[bump.sh]\033[0m"
# help
if [[ "$1" == "-h" ]] || [[ "$1" == "--help" ]]; then
echo -e "$PREFIX Release, changelog and merge request generator for GitLab. Usefull magic in one string :)
Usage: `basename $0` [branch_from] [branch_to]
Example: `basename $0` develop master"
exit 0
fi
# Define vars
BRANCH_CURRENT=$(git rev-parse --abbrev-ref HEAD)
BRANCH_1="${1:-$BRANCH_CURRENT}"
BRANCH_2="${2:-master}"
CHANGES=$(git log --oneline --no-merges --full-history $BRANCH_1...$BRANCH_2 | sed -u 's/^/\* /g')
REPO_URL=$(git remote get-url origin | sed -u 's/git@//g; s/:/\//g; s/.git//g')
# Fetch origin headers (to avoid duplicates and outdated versions)
echo -e "$PREFIX Fetching tags..."
git fetch --tags --force -q
PREVIOUS_VERSION=$(git describe --tags $(git rev-list --tags --max-count=1))
# Work with user input
printf "CHANGES:\n$CHANGES\n\n"
echo -n "Enter new version (Current branch: $BRANCH_CURRENT | Previous version: $PREVIOUS_VERSION): "
read NEW_VERSION
# Update changelog
if [[ $REPO_URL == *"gitlab"* ]]; then
TAG_URL="https://$REPO_URL/tags/$NEW_VERSION"
elif [[ $REPO_URL == *"github"* ]]; then
TAG_URL="https://$REPO_URL/tree/$NEW_VERSION"
fi
echo -e "# Release v[$NEW_VERSION]($TAG_URL)\n\n$CHANGES\n\n$(cat CHANGELOG.md)" > CHANGELOG.md
git add CHANGELOG.md
git commit -q -m "Release v$NEW_VERSION"
# Create new tag with changes
git tag $NEW_VERSION -m $"$CHANGES"
echo -e "$PREFIX Pushing..."
# Push changes with new tag
git push origin --follow-tags
# Open merge request url with preset changes
if [[ $REPO_URL == *"gitlab"* ]]; then
xdg-open "https://$REPO_URL/merge_requests/new?utf8=✓&merge_request[source_branch]=$BRANCH_1&merge_request[target_branch]=$BRANCH_2&merge_request[title]=$NEW_VERSION"
elif [[ $REPO_URL == *"github"* ]]; then
xdg-open "https://$REPO_URL/compare/$BRANCH_1...$BRANCH_2&pull_request[title]=$NEW_VERSION"
fi
echo -e "$PREFIX Don't forget to notify your teammates about new release!"