# Description
#   Message AOs about master or a release branch being force pushed too.
AOHelper = require '../ActiveOwnerHelper'
Push = require '../Push'

module.exports = (robot) ->

  helper = new AOHelper robot
  branchPattern = new RegExp "^#{process.env.FORCE_PUSH_BRANCH_PATTERN}$" #///^refs/heads/(master|release-[0-9.]*$)///

  robot.on 'github.push.forced', (push) ->
    push = new Push push
    if push.branch.match branchPattern
      message = "(gatorproblems) (gatorproblems) (gatorproblems) (gatorproblems) (gatorproblems) (gatorproblems) (gatorproblems)\n"
      + "(gatorproblems)     FORCE PUSH ALERT     (gatorproblems)\n"
      + "(gatorproblems) (gatorproblems) (gatorproblems) (gatorproblems) (gatorproblems) (gatorproblems) (gatorproblems)\n"
      + "#{push.branch} has been forced push by #{push.user} onto #{push.repo}. Last commit hash before the push was #{push.shaBefore}." 
      helper.messageAOs message
