Last active
February 12, 2018 14:07
-
-
Save wytrych/822a5e0ef89172bbaf88fe4767ef7a84 to your computer and use it in GitHub Desktop.
A script finding merge commits between two latest tags and posting them to slack.
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
#!/bin/sh | |
HOOK_URL=<SLACK_HOOK_URL> | |
CHANNEL=<TARGET_CHANNEL> | |
REPO_NAME=`git config --get remote.origin.url | awk 'match($0,/\/([a-zA-Z1-9-]*)/) {print substr($0,RSTART+1,RLENGTH-1)}'` | |
REPO_URL=`git config remote.origin.url | sed 's/.*@\(.*\)\.git/\1/g' | sed 's/:/\//'`/pull | |
ESCAPED_REPO_URL=`echo $REPO_URL | sed 's/\//\\\\\//g'` #so many slashes! | |
read a b <<< $(git tag -l --sort=version:refname "v*" | tail -2) | |
read PULL_REQUESTS <<< $(git log --oneline $a...$b | grep "pull request" | awk 'match($0,/#[0-9]*/) {print substr($0,RSTART,RLENGTH)}') | |
PRS_WITH_LINKS=`echo $PULL_REQUESTS | sed -E "s/#([0-9]*)([ ]|$)/<https:\/\/$ESCAPED_REPO_URL\/\1|&> /g"` | |
MESSAGE="~~~ deploying $REPO_NAME $PRS_WITH_LINKS ~~~" | |
echo "Sending message to slack:" | |
echo $MESSAGE | |
curl -X POST --data-urlencode "payload={\"channel\": \"$CHANNEL\", \"username\": \"Pre-deploy bot\", \"text\": \"$MESSAGE\", \"icon_emoji\": \":airplane_departure:\"}" $HOOK_URL |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The git tags are not using natural sort by default when they contain something else than numbers, such as being prepended with
v
in our case. This means for example thatv1.0.2
comes afterv1.0.10
.To fix this issue, change
git tag
togit tag -l --sort=version:refname "v*"
so that line becomes: