Last active
February 28, 2017 12:32
-
-
Save mtyurt/730cada4a0a28f5f32972a92351d3984 to your computer and use it in GitHub Desktop.
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/bash -ex | |
sendSlackMsg(){ | |
curl -X POST --data-urlencode "payload={\"channel\": \"$1\", \"attachments\": [{\"title\":\"Merged branches report:\", \"text\":\"$2\",\"mrkdwn_in\":[\"text\"]}], \"icon_emoji\":\":shipit:\"}" https://hooks.slack.com/services/incoming-webhook-url | |
} | |
#user-defined | |
cd $REPO | |
git fetch -a --prune | |
declare -a textArray | |
git branch -r --merged origin/master | \ | |
awk '{branch=substr($1,8); if(branch!="HEAD" && branch!="master") {print branch}}' | { | |
while read branch; do | |
git fetch origin $branch | |
author=$(git log origin/$branch --format="%an" -n 1) | |
branchTxt='*'$branch'*, last committer: *'$author'*' | |
textArray+=("$branchTxt") | |
done | |
printf '%s\n' "${textArray[@]}" > branchtmp.out | |
} | |
text=$(cat branchtmp.out) | |
rm branchtmp.out | |
sendSlackMsg "#engineering" "$text" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Explanation: http://mtyurt.net/2017/02/28/bash-script-to-notify-slack-channel-for-merged-branches/