Created
March 28, 2019 16:46
-
-
Save ulmen/86759682cd49d79c1e8b13ca8b125a77 to your computer and use it in GitHub Desktop.
lita semaphore integration
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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