Skip to content

Instantly share code, notes, and snippets.

@june29
Last active August 29, 2015 14:25
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 june29/43109a1c007e53befcfe to your computer and use it in GitHub Desktop.
Save june29/43109a1c007e53befcfe to your computer and use it in GitHub Desktop.
Gem::Specification.new do |spec|
spec.name = "ruboty-drone"
spec.version = "0.0.1"
spec.authors = ["Jun OHWADA"]
spec.email = ["june29.jp@gmail.com"]
spec.summary = "Access to Drone.io"
spec.files = ["ruboty-drone.rb"]
spec.require_path = "."
spec.add_dependency "drone-ruby"
end
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