Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 36 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ What does it do?
- Prevent merge marker commits.
- Automatically bump versions when starting a release or hotfix. Versions are generated, written to file and committed.
- Automatically specify tag messages.
- Send notifications in Slack, Hipchat.

Usage
=====
Expand Down Expand Up @@ -111,7 +112,14 @@ If that isn't found, it assumes the current version is `0.0.0`.
Alternatively you may use `patch`, `minor` and `major` as version.
A bump of that level will take place.

If the commands are run with version, that version will be used (no bumping).
You can avoid writing into the version-file by specifying in your config file:

VERSION_WRITE=false

If the commands are run with version, that version will be used (no bumping):

git flow release start 1.1.0
git flow hostfix start 1.1.2

Bump messages
-------------
Expand All @@ -132,6 +140,33 @@ git config gitflow.release.finish.message "Release %tag%"

If you like, you can change the tag-placeholder (`%tag%` in the example above) in the git-flow-hooks configuration.

Sending notifications
---------------------

You can also send notifications into your messengers:

### Slack

![Slack notification](./notification_slack.png)

Set in `git-flow-hooks-config.sh` file your [Slack webhook](https://my.slack.com/services/new/incoming-webhook/) url:

```sh
SLACK_WEBHOOK_URL="https://hooks.slack.com/services/S07B1234/A0E0J1234/F1uyuHs91IJhJwlgHaPw1234"
```

### Hipchat

![Hipchat notification](./notification_hipchat.png)

Set in `git-flow-hooks-config.sh` file your Hipchat credentials (API Version 2 Access from your Account Settings):

```sh
HIPCHAT_URL="https://messenger.your.domain"
HIPCHAT_ROOM_ID=123
HIPCHAT_AUTH_TOKEN="jmaFPoAiAWuj78ugGNfLa12ihLoG0bA9ilQW1234"
```

License
=======

Expand Down
4 changes: 4 additions & 0 deletions modules/bump-version.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
#!/usr/bin/env bash

if [[ $(__write_version) == false ]]; then
return 0
fi

if [ -z "$VERSION" ]; then
if [ "$1" == "hotfix" ]; then
VERSION=$(__get_hotfix_version_bumplevel)
Expand Down
24 changes: 24 additions & 0 deletions modules/functions.sh
Original file line number Diff line number Diff line change
Expand Up @@ -55,3 +55,27 @@ function __is_binary {

return 1
}

function __write_version {
if [ "${VERSION_WRITE}" == true ]; then
echo true
else
echo false
fi
}

function __notify_to_slack {
if [ -n "${SLACK_WEBHOOK_URL}" ]; then
echo true
else
echo false
fi
}

function __notify_to_hipchat {
if [ -n "${HIPCHAT_URL}" ] && [ -n "${HIPCHAT_ROOM_ID}" ] && [ -n "${HIPCHAT_AUTH_TOKEN}" ]; then
echo true
else
echo false
fi
}
5 changes: 5 additions & 0 deletions modules/git-flow-hooks-config.sh.dist
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,8 @@ VERSION_BUMPLEVEL_HOTFIX="PATCH"
VERSION_BUMPLEVEL_RELEASE="MINOR"
VERSION_BUMP_MESSAGE="Bump version to %version%"
VERSION_TAG_PLACEHOLDER="%tag%"
VERSION_WRITE=false
SLACK_WEBHOOK_URL=""
HIPCHAT_URL=""
HIPCHAT_ROOM_ID=""
HIPCHAT_AUTH_TOKEN=""
23 changes: 23 additions & 0 deletions modules/notify-hipchat.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#!/usr/bin/env bash

if [ $# -gt 5 ]; then
exit 1
fi

if [[ $(__notify_to_hipchat) == false ]]; then
return 0
fi

COMMAND=$1
CURRENT_VERSION=$2
ACTION=$3
USER=$4
CHANGES=$5

CHANGES=`echo $CHANGES | sed -e 's/^/<li>/' -e 's/\\\\n[ ]*/<li>/g' -e 's/<li>$//'`
HIPCHAT_MESSAGE="<strong>$COMMAND/$CURRENT_VERSION</strong> $ACTION by $USER<br /><br />Changes:<br /><ul>$CHANGES</ul>"

curl -H "Content-Type: application/json" \
-X POST \
-d "{\"color\": \"yellow\", \"message_format\": \"html\", \"message\": \"$HIPCHAT_MESSAGE\"}" \
$HIPCHAT_URL/v2/room/$HIPCHAT_ROOM_ID/notification?auth_token=$HIPCHAT_AUTH_TOKEN
20 changes: 20 additions & 0 deletions modules/notify-slack.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#!/usr/bin/env bash

if [ $# -gt 5 ]; then
exit 1
fi

if [[ $(__notify_to_slack) == false ]]; then
return 0
fi

COMMAND=$1
CURRENT_VERSION=$2
ACTION=$3
USER=$4
CHANGES=$5

CHANGES=`echo $CHANGES | sed "s/\"/'/g"`
SLACK_MESSAGE="\`$COMMAND/$CURRENT_VERSION\` $ACTION by $USER\n\nChanges:\n$CHANGES"

curl -X POST -s --data-urlencode "payload={\"text\":\"$SLACK_MESSAGE\"}" $SLACK_WEBHOOK_URL
32 changes: 32 additions & 0 deletions modules/notify.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#!/usr/bin/env bash

function __print_usage {
echo "Usage: $(basename $0) [<command>] [<version>] [<action>]"
echo " <command>: release/hotfix"
echo " <version>: version"
echo " <action>: started/finished"
exit 1
}

if [ $# -gt 3 ]; then
__print_usage
fi

COMMAND=$1
CURRENT_VERSION=$2
ACTION=$3

USER=`git config user.name`

if [[ $ACTION == "finished" ]]; then
PREV_VERSION=$(git describe --abbrev=0 --tags $(git rev-list --tags --max-count=2) | $VERSION_SORT -V | head -1)
CHANGES=$(git log --no-merges --pretty=format:"%s (%an)\n" "$CURRENT_VERSION"..."$PREV_VERSION")
fi

if [[ $ACTION == "started" ]]; then
PREV_VERSION=$(git describe --abbrev=0 --tags $(git rev-list --tags --max-count=1))
CHANGES=$(git log --no-merges --pretty=format:"%s (%an)\n" "$COMMAND/$CURRENT_VERSION"..."$PREV_VERSION")
fi

. "$HOOKS_DIR/modules/notify-slack.sh" $COMMAND $CURRENT_VERSION $ACTION "$USER" "$CHANGES"
. "$HOOKS_DIR/modules/notify-hipchat.sh" $COMMAND $CURRENT_VERSION $ACTION "$USER" "$CHANGES"
4 changes: 4 additions & 0 deletions modules/write-version.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
#!/usr/bin/env bash

if [[ $(__write_version) == false ]]; then
return 0
fi

VERSION_FILE=$(__get_version_file)
VERSION_PREFIX=$(git config --get gitflow.prefix.versiontag)

Expand Down
Binary file added notification_hipchat.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added notification_slack.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
31 changes: 31 additions & 0 deletions post-flow-hotfix-finish
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#!/usr/bin/env bash

# Runs at the end of git flow hotfix start
#
# Positional arguments:
# $1 The version (including the version prefix)
# $2 The origin remote
# $3 The full branch name (including the feature prefix)
#
# The following variables are available as they are exported by git-flow:
#
# MASTER_BRANCH - The branch defined as Master
# DEVELOP_BRANCH - The branch defined as Develop

VERSION=$1
ORIGIN=$2
BRANCH=$3

# Implement your script here.

SCRIPT_PATH="$0"; while [ -h "$SCRIPT_PATH" ]; do SCRIPT_PATH=$(readlink "$SCRIPT_PATH"); done
. "$(dirname $SCRIPT_PATH)/modules/functions.sh"

. "$HOOKS_DIR/modules/write-version.sh"
. "$HOOKS_DIR/modules/notify.sh" hotfix $VERSION finished
if [ $? -ne 0 ]; then
exit 1
fi

# To terminate the git-flow action, return a non-zero exit code.
exit 0
2 changes: 2 additions & 0 deletions post-flow-hotfix-start
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,10 @@ SCRIPT_PATH="$0"; while [ -h "$SCRIPT_PATH" ]; do SCRIPT_PATH=$(readlink "$SCRIP
. "$(dirname $SCRIPT_PATH)/modules/functions.sh"

. "$HOOKS_DIR/modules/write-version.sh"
. "$HOOKS_DIR/modules/notify.sh" hotfix $VERSION started
if [ $? -ne 0 ]; then
exit 1
fi

# To terminate the git-flow action, return a non-zero exit code.
exit 0
31 changes: 31 additions & 0 deletions post-flow-release-finish
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#!/usr/bin/env bash

# Runs at the end of git flow release start
#
# Positional arguments:
# $1 The version (including the version prefix)
# $2 The origin remote
# $3 The full branch name (including the release prefix)
#
# The following variables are available as they are exported by git-flow:
#
# MASTER_BRANCH - The branch defined as Master
# DEVELOP_BRANCH - The branch defined as Develop

VERSION=$1
ORIGIN=$2
BRANCH=$3

# Implement your script here.

SCRIPT_PATH="$0"; while [ -h "$SCRIPT_PATH" ]; do SCRIPT_PATH=$(readlink "$SCRIPT_PATH"); done
. "$(dirname $SCRIPT_PATH)/modules/functions.sh"

. "$HOOKS_DIR/modules/write-version.sh"
. "$HOOKS_DIR/modules/notify.sh" release $VERSION finished
if [ $? -ne 0 ]; then
exit 1
fi

# To terminate the git-flow action, return a non-zero exit code.
exit 0
2 changes: 2 additions & 0 deletions post-flow-release-start
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,10 @@ SCRIPT_PATH="$0"; while [ -h "$SCRIPT_PATH" ]; do SCRIPT_PATH=$(readlink "$SCRIP
. "$(dirname $SCRIPT_PATH)/modules/functions.sh"

. "$HOOKS_DIR/modules/write-version.sh"
. "$HOOKS_DIR/modules/notify.sh" release $VERSION started
if [ $? -ne 0 ]; then
exit 1
fi

# To terminate the git-flow action, return a non-zero exit code.
exit 0