Skip to content
This repository has been archived by the owner on Nov 10, 2017. It is now read-only.

Enable chat adapter with env variable #115

Open
wants to merge 16 commits into
base: master
Choose a base branch
from
33 changes: 25 additions & 8 deletions docs/config-file.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,19 +22,36 @@ Any extra parameters will be passed along to GitHub in the `payload` field. This
"provider": "heroku",
"auto_merge": false,
"repository": "MyOrg/my-org-hubot",
"environments": ["production"],

"heroku_production_name": "my-orgs-hubot"
"environments": [{
"name": "live",
"production": true
}, {
"name": "production",
"provider_env_name": "my-org-www-production"
}, {
"name": "staging",
"provider_env_name": "my-org-www-staging",
"auto_inactive": false
}, {
"name": "test",
"provider_env_name": "my-org-www-test",
"transient": true
}]
},

"dotcom": {
"provider": "heroku",
"repository": "MyOrg/www",
"environments": ["production","staging"],
"required_contexts": ["ci/janky", "security/brakeman"],

"heroku_staging_name": "my-org-www-staging",
"heroku_production_name": "my-org-www"
"environments": [{
"name" : "production",
"provider_env_name": "my-org-www-live"
},
{
"name" : "staging",
"provider_env_name": "my-org-www-live",
"transient" : true
}],
"required_contexts": ["ci/janky", "security/brakeman"]
}
}
```
Expand Down
1 change: 1 addition & 0 deletions docs/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ In order to create deployments on GitHub you need to configure a few things. Fal
| HUBOT_DEPLOY_WEBHOOK_SECRET | The shared webhook secret to check payload signatures from GitHub. |
| HUBOT_DEPLOY_ENCRYPT_PAYLOAD | Encrypt the entire deployment payload in the GitHub API. |
| HUBOT_DEPLOY_WEBHOOK_PREFIX | The URL prefix to be used for receiving webhooks. Default: "/hubot-deploy"
| HUBOT_DEPLOY_ADAPTER | The name of the adapter (slack, hipchat) to use. Adapter needs to be located in src/adapters.

### Robot Users

Expand Down
4 changes: 4 additions & 0 deletions index.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,7 @@ module.exports = (robot, scripts) ->
robot.loadFile(Path.resolve(__dirname, "src", "scripts"), "http.coffee")
robot.loadFile(Path.resolve(__dirname, "src", "scripts"), "token.coffee")
robot.loadFile(Path.resolve(__dirname, "src", "scripts"), "deploy.coffee")

adapter = process.env.HUBOT_DEPLOY_ADAPTER
if adapter?
robot.loadFile(Path.resolve(__dirname, "src", "adapters"), "#{adapter}.coffee")
6 changes: 5 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "hubot-deploy",
"version": "0.13.24",
"version": "0.13.24-fork",
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we do 0.14.0.pre1?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

"author": "Corey Donohoe <atmos@atmos.org>",
"description": "hubot script for GitHub Flow",
"main": "index.coffee",
Expand All @@ -25,6 +25,10 @@
{
"name": "Corey Donohoe",
"email": "atmos@atmos.org"
},
{
"name": "Alain Hélaïli",
"email": "helaili@github.com"
}
],
"dependencies": {
Expand Down
6 changes: 4 additions & 2 deletions docs/examples/hipchat.coffee → src/adapters/hipchat.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ module.exports = (robot) ->
# This is what happens with a '/deploy' request is accepted.
#
# msg - The hubot message that triggered the deployment. msg.reply and msg.send post back immediately
# deployment - The deployment captured from a chat interaction. You can modify it before it's passed on to the GitHub API.
# deployment - The deployment captured from a chat interaction.
# You can modify it before it's passed on to the GitHub API.
robot.on "github_deployment", (msg, deployment) ->
# Handle the difference between userIds and roomIds in hipchat
user = robot.brain.userForId deployment.user
Expand Down Expand Up @@ -41,7 +42,8 @@ module.exports = (robot) ->
# deployment - The deployed app that matched up with the request.
# formatter - A basic formatter for the deployments that should work everywhere even though it looks gross.
robot.on "hubot_deploy_available_environments", (msg, deployment) ->
msg.send "#{deployment.name} can be deployed to #{deployment.environments.join(', ')}."
environments = (envName for envName, envValue of deployment.environments)
msg.send "#{deployment.name} can be deployed to #{environments.join(', ')}."

# An incoming webhook from GitHub for a deployment.
#
Expand Down
6 changes: 4 additions & 2 deletions docs/examples/slack.coffee → src/adapters/slack.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ module.exports = (robot) ->
# This is what happens with a '/deploy' request is accepted.
#
# msg - The hubot message that triggered the deployment. msg.reply and msg.send post back immediately
# deployment - The deployment captured from a chat interaction. You can modify it before it's passed on to the GitHub API.
# deployment - The deployment captured from a chat interaction.
# You can modify it before it's passed on to the GitHub API.
robot.on "github_deployment", (msg, deployment) ->
user = robot.brain.userForId deployment.user

Expand Down Expand Up @@ -35,7 +36,8 @@ module.exports = (robot) ->
# deployment - The deployed app that matched up with the request.
# formatter - A basic formatter for the deployments that should work everywhere even though it looks gross.
robot.on "hubot_deploy_available_environments", (msg, deployment) ->
msg.send "#{deployment.name} can be deployed to #{deployment.environments.join(', ')}."
environments = (envName for envName, envValue of deployment.environments)
msg.send "#{deployment.name} can be deployed to #{environments.join(', ')}."

# An incoming webhook from GitHub for a deployment.
#
Expand Down
30 changes: 26 additions & 4 deletions src/github/api/deployment.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,12 @@ class Deployment
@user = 'unknown'
@adapter = 'unknown'
@userName = 'unknown'
@robotName = 'hubot'
@autoMerge = true
@environments = [ "production" ]
@robotName = 'hubot'
@autoMerge = true
@transientEnvironment = undefined
@productionEnvironment = undefined
@environments = { "production" : {}}
@originalEnvValue = @env
@requiredContexts = null
@caFile = Fs.readFileSync(process.env['HUBOT_CA_FILE']) if process.env['HUBOT_CA_FILE']

Expand All @@ -37,14 +40,16 @@ class Deployment
@configureAutoMerge()
@configureRequiredContexts()
@configureEnvironments()
@configureTransientEnvironment()
@configureProductionEnvironment()

@allowedRooms = @application['allowed_rooms']

isValidApp: ->
@application?

isValidEnv: ->
@env in @environments
@environments[@originalEnvValue]?

isAllowedRoom: (room) ->
!@allowedRooms? || room in @allowedRooms
Expand All @@ -56,6 +61,11 @@ class Deployment
if body?.payload?.config?
delete(body.payload.config.github_api)
delete(body.payload.config.github_token)
unless body?.transient_environment?
delete(body.transient_environment)
unless body?.production_environment?
delete(body.production_environment)

if process.env.HUBOT_DEPLOY_ENCRYPT_PAYLOAD and process.env.HUBOT_DEPLOY_FERNET_SECRETS
payload = body.payload
fernetSecret = new Fernet.Secret(process.env.HUBOT_DEPLOY_FERNET_SECRETS)
Expand All @@ -71,6 +81,8 @@ class Deployment
force: @force
auto_merge: @autoMerge
environment: @env
transient_environment: @transientEnvironment
production_environment: @productionEnvironment
required_contexts: @requiredContexts
description: "#{@task} on #{@env} from hubot-deploy-v#{Version}"
payload:
Expand All @@ -96,6 +108,7 @@ class Deployment
api: ->
api = Octonode.client(@apiConfig().token, { hostname: @apiConfig().hostname })
api.requestDefaults.agentOptions = { ca: @caFile } if @caFile
api.requestDefaults.headers.Accept = 'application/vnd.github.ant-man-preview+json'
api

latest: (callback) ->
Expand Down Expand Up @@ -168,6 +181,7 @@ class Deployment
env = @env
ref = @ref


@api().post path, @requestBody(), (err, status, body, headers) ->
callback(err, status, body, headers)

Expand All @@ -185,6 +199,14 @@ class Deployment
if @force
@autoMerge = false

configureTransientEnvironment: ->
if @isValidEnv() and @environments[@originalEnvValue]['transient']?
@transientEnvironment = @environments[@originalEnvValue]['transient']

configureProductionEnvironment: ->
if @isValidEnv() and @environments[@originalEnvValue]['production']?
@productionEnvironment = @environments[@originalEnvValue]['production']

configureRequiredContexts: ->
if @application['required_contexts']?
@requiredContexts = @application['required_contexts']
Expand Down
5 changes: 4 additions & 1 deletion src/github/api/deployment_status.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,11 @@ class DeploymentStatus
JSON.stringify(data)

create: (callback) ->
#accept = "application/vnd.github+json"
accept = "application/vnd.github.ant-man-preview+json"

ScopedClient.create("https://api.github.com").
header("Accept", "application/vnd.github+json").
header("Accept", accept).
header("User-Agent", "hubot-deploy-v#{Version}").
header("Authorization", "token #{@apiToken}").
path("/repos/#{@repoName}/deployments/#{@number}/statuses").
Expand Down
5 changes: 3 additions & 2 deletions src/models/formatters.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,9 @@ class WhereFormatter extends Formatter
output += Sprintf "%-15s\n", "Environment"
output += "-----------------------------------------------------------------\n"

for environment in @deployment.environments
output += "#{environment}\n"
for envName, envValue of @deployment.environments
console.log envName
output += "#{envName}\n"
output += "-----------------------------------------------------------------\n"

output
Expand Down
Loading