Connect systems with Reshuffle.
The GitLab Slack application is only configurable for GitLab.com. It will not work for on-premises installations where you can configure the Slack slash commands service instead. We’re planning to make this configurable for all GitLab installations, but there’s no ETA - see #28164. :tada:✨ Slack API client for Node and browsers. Contribute to smallwins/slack development by creating an account on GitHub.
The Github integration for Slack is great for team productivity. Having the ability to give Slack channels full visibility into Github projects, for real-time notifications, is an amazing way to keep the development team on the same page. However, this can become a double-edged sword. Developers may decide to ignore these messages being sent because it may be information overload.
I’ve been in a similar situation where pull requests needed approval from reviewers but they wouldn’t check the channels or their emails. The only thing that got their attention were direct messages. This hindered delivery and having to ping the reviewer myself was becoming a pain.
As great as the Github app for Slack is, I wanted something more custom that would suit my needs. For example, whenever a pull request is made with reviewers, only send direct messages to those who have been requested.
In this article, we will use Github, Slack, and Reshuffle to create the workflow to directly message the reviewers on a pull request.
How to Build It
Before getting started with the code, we’ll need to get credentials set up with Github and Slack.
Github
- Log in and generate a token here
- Save the token somewhere, as you'll need it soon
Slack Sky go app kodi funktioniert nicht.
- Create a new Slack App here
- Enter the App name and select the workspace
- Click on
Create App
- Click on your new App
- The signing secret is under
Basic Information
>App Credentials
- The token is under
Settings
>Install App
>OAuth Access Token
- Save the token and signing secret somewhere, as you'll need it soon
See links for full documentation:
Dreamweaver cc session 3 pre-assessment. With the credentials saved somewhere safe, we can begin by instantiating a Reshuffle app and configuring the connectors.
Note: The Github Connector requires a runTimeBaseUrl. A tool like ngrok can be used to generate a url that exposes your localhost over SSL.
Reshuffle Connectors provide events and actions that allow developers to easily build custom workflows and integrations. We’re now able to take advantage of what they can do.
We’ll continue by getting a list of the user’s Github handles and their Slack IDs. In order to get this data, we use a method on Slack Connector that exposes Slack's web client actions.
Note: In this example, display_name is being assumed to be the same as the Github handle. You can definitely add your own profile fields that suit your team.
Next, we’ll write a helper function to handle the event when a pull request is created, this will take in a list of reviewers from Github, the user list from Slack, and the link url to the pull request. If there are no reviewers, we’ll simply post to the general channel, otherwise, we match the reviewers to the slack members list and send them a direct message.
To tie everything together, we configure the Github Connector to trigger an event anytime a pull request is created.
Note: See the full list of available events here
We can get the list of requested reviewers from the event object, passing onto our helper, which is only called if the event action matches “opened” or “reopened”.
Note: For more information on the parameters of postMessage check the docs.
With that, we’re finished, any time a pull requests is created with reviewers, they are directly messaged.
As a bonus, if the reviewers forget about the pull request, we can use the Cron Connector as a scheduler to check for any open PRs on the repository and message the reviewers.
This example provides a good starting point to how you can easily create a custom workflow for your team's needs using Reshuffle.
Slack Github Notifications
Now, Make it Happen
As your developers and project management teams experience the ease of working with integrated applications, we encourage you to consider where else integrating workflows would benefit your teams. With so many different tools, the more you can consolidate them into one common interface, the easier people can get work done.
Reshuffle is continually listening to what our customers need and desire. Don't see a Connector to a service you'd like to integrate? Send a tweet to @ReshuffleHQ to let us know which Connector you'd like us to develop next.
Slack Github Actions
#!/bin/bash |
# $1 => Slack hook URL |
# $2 => Channel name |
# $3 => URL to web repo browser for base project |
slack_url='$1' |
channel='$2' |
browser_url='$3' |
# Debugging output in /tmp/stash_slack.txt |
# pwd > /tmp/stash_slack.txt |
text='' |
# Each column shown in the payload. |
comm_desc_col='{'title':'Commit','short':true,'value':'' |
author_time_col='{'title':'Author','short':true,'value':'' |
first=1 |
# For every ref updated. |
whileread from_ref to_ref ref_name;do |
echo${from_ref}${to_ref}${ref_name}>> /tmp/stash_slack.txt |
args=('log''--format=%H %h '%an' '%s' '%ar'''${from_ref}.${to_ref}') |
commits=$(git '${args[@]}') |
# echo '${commits}' >> /tmp/stash_slack.txt |
commit_count=`echo '${commits}'| wc -l` |
if [ ${first}-eq 1 ];then |
first=0 |
text='[<${browser_url}|${STASH_REPO_NAME}>] ${STASH_USER_NAME} <$STASH_USER_EMAIL> pushed: $commit_count commit' |
else |
text='${text}, ${commit_count} commit' |
fi |
if [ $commit_count-gt 1 ];then text='${text}s';fi |
text='${text} to ${ref_name#*/}' |
# Indexes |
# [0] Full hash |
# [1] Abbrev hash |
# [2] Author name |
# [3] Commit message |
# [4] Author relative date |
whileread -r line;do |
eval array=($line) |
commit_link='<${browser_url}/commits/${array[0]}|${array[1]}>' |
comm_desc_col='${comm_desc_col}${commit_link}: ${array[3]}n' |
author_time_col='${author_time_col}${array[2]}, ${array[4]}n' |
done<<<'$commits' |
done |
payload='payload={'channel':'${channel}','text':'${text}','attachments':[{'fallback':'Table of commits in this push.','color':'good','fields':[' |
# Close off all remaining blocks |
comm_desc_col='${comm_desc_col}'},' |
author_time_col='${author_time_col}'}' |
payload='${payload}${comm_desc_col}${author_time_col}]}]}' |
# Deliver! |
# echo '$payload' >> /tmp/stash_slack.txt |
curl -X POST --data-urlencode '$payload'${slack_url} |
# cat /tmp/stash_slack.txt |