 # Configuration:
 #   HUBOT_DEPLOY_CONFIG
 #
-#   CONFIG should be in JSON i.e. '{ "foo": {"job": "deploy-foo", "role": "deploy" } }'
+#   CONFIG should be in JSON i.e. '{ "foo": {"job": "deploy-foo", "role": "deploy", "param": "BRANCH" } }'
+#
+#   The "job" field represents the name of the Jenkins job you want to invoke.
 #
 #   The "role" field uses the [auth.coffee][1] module for restricting access via user
 #   configurable roles. You can set "role" to "*" if you don't care about restricting access.
 #
 #   [1]: https://github.com/github/hubot/blob/master/src/scripts/auth.coffee
+#
+#   The "param" field represents the name of the string parameter passed to the Jenkins
+#   job.
 #
 # Commands:
 #   hubot deploy <environment> <branch> - deploys the specified branch to the specified environment


querystring = require 'querystring'

jenkinsDeploy = (msg, robot) ->
  CONFIG = JSON.parse process.env.HUBOT_DEPLOY_CONFIG

  userHasRole = (user, role) ->
    if role is "*"

    msg.send "Error: jenkins plugin not installed."
    return

  environment = querystring.escape msg.match[2]
  branch = querystring.escape msg.match[3]
  user = msg.message.user

  if environment not of CONFIG
