hubot-github-reminder
Version:
A simple helpful robot for your Company
244 lines (205 loc) • 9.77 kB
text/coffeescript
# Description:
# A hubot script to list and recurrently remind you about open pull requests.
# Optionally receive direct messages when you are assigned to a pull
# request in your organization.
#
# Dependencies:
# - coffeescript
# - cron
# - octokat
# - moment
# - underscore
# - fuse.js
#
# Configuration:
# HUBOT_GITHUB_TOKEN - Github Application Token
# HUBOT_GITHUB_WEBHOOK_SECRET - Optional, if you are using webhooks and have a secret set this for additional security checks on payload delivery
# HUBOT_GITHUB_ORG - Github Organization Name (the one in the url)
#
# Commands:
# hubot github list open pr - Shows a list of open pull requests for the repo of this room [optionally for a specific user]
# hubot github remind hh:mm - I'll remind about open pull requests in this room at hh:mm every weekday.
# hubot github list reminders - See all pull request reminders for this room.
# hubot github delete hh:mm reminder - If you have a reminder at hh:mm, I'll delete it.
# hubot github delete all reminders - Deletes all reminders for this room.
#
# Author:
# Springworks
_ = require 'underscore'
Patterns = require "./patterns"
GitHubDataService = require "./github-services/github-data-service"
PrCacheInitializer = require("./github-services/pr-cache-initializer").PullRequestsCacheInit
GithubWebhookHandler = require("./github-services/github-webhook-handler").WebhookHandler
PrSatusCheckWorker = require("./github-services/pr-status-check-worker").PrStatusCheckWorker
Generic = require("./hubot-message-adapters/generic").GenericAdapter
Reminders = require("./github-services/pr-reminders").Reminders
utils = require "./utils"
class GithubBot
constructor: (@robot) ->
return new GithubBot @robot unless @ instanceof GithubBot
send: (context, message) ->
registerEventListeners: ->
text = "There are failing status checks!!! Please fix them before assignees can be notified."
if statusChecksPassed
if missing_usernames and missing_usernames.length > 0
text = "!!!The following github users can not be matched to slack user " + JSON.stringify(missing_usernames)
else
text = "All assignees and reviewers have been notified"
message =
text: text
attachments: [ pr.toAttachment() ]
text = "PR Review Submitted"
message =
text: text
attachments: [ pr.toAttachment() ]
text = "PR Review Comment"
message =
text: text
attachments: [ pr.toAttachment() ]
text = "PR Assignment Notification"
message =
text: text
attachments: [ pr.toAttachment() ]
text = "PR Review Request"
message =
text: text
attachments: [ pr.toAttachment() ]
if prs.length is 0
message = text: "No open pull requests found"
else
attachments = (pr.toAttachment() for pr in prs)
message = attachments: attachments
text: """
Warining: No Github Username provived, i will use slack username, please provide github username if it is different using #{@robot.name} github I am <user>
"""
if success
text: """
Cache Succesifully Initilized
"""
else
text: """
Cache Initialization failed. Please try again.
"""
registerRobotResponses: ->
[ __, state ] = msg.match
switch state
when "enable"
when "disable"
hubotUser = msg.message.user.name
github_user = msg.match[1]
utils.rememberUser @robot.brain, hubotUser, github_user
hubotUser = msg.message.user
hubotUser = msg.message.user.name
remindersCleared = @reminders.clearAllForUser hubotUser
[__, time] = msg.match
hubotUser = msg.message.user.name
remindersCleared = @reminders.clearForUserAtTime hubotUser, time
if remindersCleared is 0
else
[__, time] = msg.match
hubotUser = msg.message.user.name
githubUserName = utils.lookupUserWithHubot @robot.brain, hubotUser
if githubUserName
else
hubotUser = msg.message.user.name
reminders = @reminders.getForUser hubotUser
if reminders.length is 0
else
hubotUser = msg.message.user
GitHubDataService.openForUser @robot, hubotUser, false
hubotUser = msg.message.user
GitHubDataService.openForUser @robot, hubotUser, true
module.exports = GithubBot