Last active
August 29, 2015 14:25
-
-
Save june29/43109a1c007e53befcfe to your computer and use it in GitHub Desktop.
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
Gem::Specification.new do |spec| | |
spec.name = "ruboty-drone" | |
spec.version = "0.0.1" | |
spec.authors = ["Jun OHWADA"] | |
spec.email = ["[email protected]"] | |
spec.summary = "Access to Drone.io" | |
spec.files = ["ruboty-drone.rb"] | |
spec.require_path = "." | |
spec.add_dependency "drone-ruby" | |
end |
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 "drone" | |
module Ruboty | |
module Handlers | |
class Drone < Base | |
env :DRONE_HOST, "Set your Drone host" | |
env :DRONE_TOKEN, "Set your Drone token" | |
on( | |
/drone rebuild\s+(?<repos>.*)\s+(?<branch>.*)/i, | |
name: "rebuild", | |
description: "Rebuild target repositories latest commit" | |
) | |
def rebuild(message) | |
client = ::Drone::Client.new( | |
host: ENV["DRONE_HOST"], | |
access_token: ENV["DRONE_TOKEN"] | |
) | |
client.http.ssl_config.verify_mode = nil | |
repos = client.repository(message[:repos]) | |
commits = client.commits(repos: repos) | |
latest_commit = commits.select { |c| c.branch == message[:branch] }.sort_by(&:created_at).last | |
if latest_commit | |
client.rebuild(repos: repos, branch: message[:branch], commit: latest_commit) | |
message.reply("Rebuild commit: #{latest_commit.sha}") | |
else | |
message.reply("Commit not found on target repository") | |
end | |
end | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment