OpenWhisk is an Apache incubator project that provides an open source serverless platform. Its source code is available in GitHub.
OpenWhisk project developers are using actual running OpenWhisk code to improve its continuous development and integration (CD/CI) processes. This post introduces you to GitHub Slack Bot (openwhisk-GitHubSlackBot), a bot that’s designed to post updates to Slack when a GitHub pull request is ready to be merged, or when a list of pull requests are under review for a number of days and haven’t been merged.
Here’s a sample of notifications received on Slack:
The GitHub Slack Bot is built on a set of three actions (like microservices), which are invoked either by some triggers or by another action in a sequence of dependent actions. One action is invoked by regular pull request updates received from a GitHub repository and an action sequence (consisting of two actions) is triggered periodically by an internal OpenWhisk alarm, similar to a cron job.
The following sections describe what each action does within its triggered flow.
Invoked by GitHub repository when a pull request changes
Actions are invoked when any change occurs to a pull request:
- Track pull requests: An action that is subscribed to
pull_requestevents on GitHub repository. The GitHub repository sends the pull request payload using HTTP POST, which is stored in Cloudant to form a data set of pull requests. The data set in Cloudant is updated when a pull request is:
- Labeled “ready” or “review”
- Unlabeled (that is, the “ready” or “review” label is removed)
- Updated due to a new push in the branch that the pull request is tracking
Invoked twice a day by an Alarm trigger
The sequence of actions is invoked by the Alarm trigger, which then starts a chain of microservices to retrieve the list of delayed pull requests and compose notifications, which are posted on Slack.
- Find delayed pull requests: An action that is invoked every 12 hours with the Cloudant data set; it retrieves a list of pull requests that are ready to be merged and older than a certain number of days.
- Post to Slack: An action invoked by the find delayed pull requests action. It takes a list of delayed pull requests and composes a message with pull requests, ID, label, and age in days to post on Slack.
Here’s the high-level workflow diagram:
You can try the GitHub Slack Bot yourself! Follow the step-by-step installation instructions on GitHub, or check out the live demo on YouTube. I’d love to hear how you do with the bot — leave me a comment below or connect with me on GitHub. I hope you find it useful!