Created
November 19, 2013 10:46
-
-
Save pgmot/7543587 to your computer and use it in GitHub Desktop.
IRCからJenkinsおじさん叩き起こすよう
This file contains hidden or 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 "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