This is a short article on how we integrate stash and slack in openmind
First of all i assume you have:
- a working stash installation
- a repository you to notify slack on pushes
- stash user with administration priviledges
- full access to the server (linux) where stash is installed on
- a team configured on slack
- slack user with administration priviledges
Access your stash server and create a script
vim /home/appuser/stash_slack.sh
Paste the following:
#!/bin/bash
echo "Notify commits to slack"
channel=$2
icon=$4
payload="payload={\"channel\":\"$channel\",\"username\":\"webhookbot\",\"text\":\"Push on ${STASH_REPO_NAME} by ${STASH_USER_NAME} <$STASH_USER_EMAIL>\",\"icon_emoji\":\"$icon\",\"attachments\":["
while read from_ref to_ref ref_name; do
message=`git log --format=%B -n 1 ${to_ref}`
title="[$STASH_REPO_NAME:$ref_name] <$3/commits/$to_ref|$to_ref>: $message"
payload="$payload{\"fallback\":\"$title\",\"pretext\":\"$title\"},"
done
payload="${payload%?}]}"
curl -X POST --data-urlencode "$payload" $1
and save.
Make it executable
chmod +x /home/appuser/stash_slack.sh
- Access to slack: https://YOUR_TEAM.slack.com/services/new (replace YOUR_TEAM with your team name)
- Select "Incoming WebHooks"
- Choose a channel from drop-down and click "Add incoming WebHook"
- You have a new webhook configured! Copy the URL under "Your Unique Webhook URL"
- Access to stash web interface
- Go to your repository
- Click on Settings
- Click on Hooks
- Click on "Add Hook" button and then on "Search"
- Search for "External Hooks" and click "Install"
- Once installed, go back to Hooks page in your repository
- Click on "Enable" on the "External Post Receive Hook" row (not pre-receive)
- Put the full path to the stash_slack.sh executable script in "Executable" field:
/home/appuser/stash_slack.sh
- Fill "Positional Parameters" with:
- 1st line: Web hook url you copied at last point in previous paragraph
- 2nd line: Channel name (#general)
- 3rd line: full path to your web interface repository page (without trailing slash)
- 4th line: emoji for your notification (:rocket:)
https://openmindonline.slack.com/services/hooks/incoming-webhook?token=6PPy9nEngOuRhl79XbSPrRCK
#general
https://your_stash_server/projects/ACME/repos/foo
:rocket:
Everything should work! Try to push something!
HTH
May I suggest also explaining that when you copy the URL for the repo, to not include /browse :) Thank you so much, this works perfectly 👍