Skip to content

Instantly share code, notes, and snippets.

@pgmot
Created November 19, 2013 10: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 pgmot/7543587 to your computer and use it in GitHub Desktop.
Save pgmot/7543587 to your computer and use it in GitHub Desktop.
IRCからJenkinsおじさん叩き起こすよう
require "sinatra"
require "cinch"
require "yaml"
require "json"
config_file = ARGV.shift || "config.yml"
if not File.exist? config_file
puts "error: Can't find config file #{config_file}"
exit
end
$config = YAML.load_file config_file
# bot setting
$bot = Cinch::Bot.new do
configure do |c|
c.nick = $config["irc"]["nick"]
c.user = $config["irc"]["nick"]
c.realname = $config["irc"]["nick"]
c.server = $config["irc"]["server"]
c.port = $config["irc"]["port"]
c.channels = $config["irc"]["channels"]
c.password = $config["irc"]["password"]
end
end
Thread.new do
$bot.start
end
# sinatra setting
configure do
set :bind, $config["http"]["host"]
set :port, $config["http"]["port"]
end
def say(chan, msg)
if $config["irc"]["channels"].include? chan
$bot.Channel(chan).send msg
end
end
get "/" do
say("#mot_test", "http test")
"available"
end
post "/bitbucket" do
data = JSON.parse(params[:payload])
p data
project = data["repository"]["slug"]
branch = data["commits"][0]["branch"]
msg = "!jenkins build #{project} now BRANCH=#{branch}"
say("#jenkins", msg)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment