Skip to content

Instantly share code, notes, and snippets.

@ulmen
Created March 28, 2019 16:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ulmen/86759682cd49d79c1e8b13ca8b125a77 to your computer and use it in GitHub Desktop.
Save ulmen/86759682cd49d79c1e8b13ca8b125a77 to your computer and use it in GitHub Desktop.
lita semaphore integration
require 'faraday'
require 'faraday_middleware'
require 'json'
module Lita
module Handlers
class SemaphoreDeploy < Handler
route(/^!deploy\s+(?<app>(demo|prod))/, :deploy, command: false, help: {
"!deploy app" => "deploy demo or prod via semaphore"
})
def deploy(response)
app = response.match_data[:app]
run_on_semaphore(app)
response.reply "#{app.upcase} deployment started"
end
private
def run_on_semaphore(app)
# a bit of hardcode
templates_ids = {
'demo' => 1,
'prod' => 2
}
conn = Faraday.new('https://semaphore.host.com/') do |conn|
conn.response :json, content_type: 'application/json'
conn.adapter Faraday.default_adapter
conn.authorization :Bearer, 'semaphore-token'
end
conn.post do |req|
req.url '/api/project/1/tasks'
req.headers['Content-Type'] = 'application/json'
req.body = {
template_id: templates_ids[app],
debug: false,
dry_run: false,
playbook: "",
environment: ""
}.to_json
end
end
Lita.register_handler(self)
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment