           ]
 
       # Declined
-      if type is 'pullrequest:rejected' && ('declined' in announce_options)
+      if type is 'pullrequest:rejected' && ('declined' in ANNOUNCE_OPTIONS)
         content = branch_action(resp, 'Declined', cached_vars, red)
 
       # Merged
-      if type is 'pullrequest:fulfilled' && ('merged' in announce_options)
+      if type is 'pullrequest:fulfilled' && ('merged' in ANNOUNCE_OPTIONS)
         content = branch_action(resp, 'Merged', cached_vars, green)
 
       # Updated
-      if type is 'pullrequest:updated' && ('updated' in announce_options)
+      if type is 'pullrequest:updated' && ('updated' in ANNOUNCE_OPTIONS)
         content = branch_action(resp, 'Updated', cached_vars, purple)
 
       # Approved
-      if type is 'pullrequest:approved' && ('approve' in announce_options)
+      if type is 'pullrequest:approved' && ('approve' in ANNOUNCE_OPTIONS)
         encourage_array = [':thumbsup:', 'That was a nice thing you did.', 'Boomtown', 'BOOM', 'Finally.', 'And another request bites the dust.']
         encourage_me = encourage_array[Math.floor(Math.random()*encourage_array.length)];
         content =


DEFAULT_ROOM = process.env.HUBOT_BITBUCKET_PULLREQUEST_ROOM


module.exports = (robot) ->
  robot.router.post '/hubot/bitbucket-pr', (req, res) ->

    # Set default actions to announce
    announce_options = ['created', 'updated', 'declined', 'merged', 'comment_created', 'approve', 'unapprove']

    # Replace announce options if set in the environment
    if process.env.HUBOT_BITBUCKET_PULLREQUEST_ANNOUNCE
      announce_options = process.env.HUBOT_BITBUCKET_PULLREQUEST_ANNOUNCE.replace(/[^a-z\,]+/, '').split(',')


    resp = req.body

    # Really don't understand why this isn't in the response body

        msg += "\n#{cached_vars.pr_link}"

      # Unapproved
      if type is 'pullrequest:unapproved' && ('unapprove' in ANNOUNCE_OPTIONS)
        msg = "A pull request on `#{cached_vars.repo_name}` has been unapproved by #{cached_vars.actor}"
        msg += "\n#{cached_vars.pr_link}"

