Skip to content

Instantly share code, notes, and snippets.

@jonico
Last active March 18, 2021 23:58
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jonico/d4b98fca6ed36cdbca72fd4457787bab to your computer and use it in GitHub Desktop.
Save jonico/d4b98fca6ed36cdbca72fd4457787bab to your computer and use it in GitHub Desktop.
Hubot script that will send a direct message to any person that gets assigned to a pull request.
# Description
# Hubot script that will send a direct message to any person that gets assigned to a pull request.
# This came out of a discussion where a customer received too many GitHub notifications and wanted something
# succinct for the pull request assignment event.
#
# Dependencies:
# This script was tested with the slack adapter.
# In order to make use of it, you would have to put into Hubot's script folder and setup a GitHub webhook that points to
# <hubot deployment url>/hubot-pr and is delivering at least the pull requests events of the repositories you are interested
#
# Author:
# jonico
module.exports = (robot) ->
robot.router.post '/hubot-pr', (req, res) ->
switch req.headers['x-github-event']
when "pull_request"
if req.body.action is "assigned"
assignee = req.body.pull_request.assignee.login
pr_number = req.body.number
pr_title = req.body.pull_request.title
pr_url = req.body.pull_request.url
robot.messageRoom assignee, "You got assigned to pull request ##{pr_number} #{pr_title}: #{pr_url}"
res.writeHead 204, {'content-type': 'application/json' }
return res.end(JSON.stringify({message: "PR processed from #{robot.name}. :D"}))
else
res.writeHead 204, {'content-type': 'application/json' }
return res.end(JSON.stringify({message: "Received but not processed."}))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment