Permalink
Browse files

initial commit

  • Loading branch information...
0 parents commit 7f89278ad47dc73ba70cc32ac3e870283f2a3b03 @kentaro committed Jun 1, 2012
@@ -0,0 +1,4 @@
+pkg/
+work/
+jar/
+Gemfile.lock
@@ -0,0 +1 @@
+jruby-1.6.7
@@ -0,0 +1,13 @@
+source :rubygems
+
+gem "jenkins-plugin-runtime", "~> 0.2.0"
+gem 'columnize'
+
+group :development do
+ gem 'jpi', '~> 0.3.5'
+ gem 'ruby-debug'
+end
+
+group :test do
+ gem 'rspec'
+end
@@ -0,0 +1,11 @@
+Jenkins::Plugin::Specification.new do |plugin|
+ plugin.name = "ikachan"
+ plugin.display_name = "Ikachan Plugin"
+ plugin.version = '0.0.1'
+ plugin.description = 'Publisher for an IRC bot named Ikachan.'
+ plugin.url = 'https://wiki.jenkins-ci.org/display/JENKINS/Ikachan+Plugin'
+ plugin.developed_by "kentaro", "Kentaro Kuribayashi <kentarok@gmail.com>"
+ plugin.uses_repository :github => "kentaro/jenkins-ikachan-plugin"
+ plugin.depends_on 'ruby-runtime', '0.10'
+ plugin.depends_on 'git', '1.1.11'
+end
@@ -0,0 +1,6 @@
+require 'java'
+import 'hudson.model.Result'
+
+require 'ikachan/client'
+require 'ikachan/message'
+require 'ikachan/message_factory'
@@ -0,0 +1,28 @@
+require 'uri'
+require 'net/http'
+
+module Ikachan
+ class Client
+ attr_reader :base_url, :listener
+
+ def initialize(base_url, listener)
+ @base_url = base_url.match(/^https?:\/\/[^\/]+\//) ? base_url : "http:\/\/#{base_url}\/"
+ @listener = listener
+ end
+
+ def join(channel)
+ dispatch :join, 'channel' => channel
+ end
+
+ def notice(channel, message)
+ dispatch :notice, 'channel' => channel, 'message' => message
+ end
+
+ private
+
+ def dispatch(type, params = {})
+ uri = URI.parse "#{base_url}#{type.to_s}"
+ Net::HTTP.post_form uri, params
+ end
+ end
+end
@@ -0,0 +1,88 @@
+module Ikachan
+ module Message
+ attr_reader :build
+ attr_reader :color
+ attr_reader :notify
+ attr_reader :status
+
+ def message
+ msg = "#{build.full_display_name} - #{status} after #{build.duration_string}"
+ instance = Java::jenkins::model::Jenkins.instance
+ if instance && instance.root_url
+ msg << " (<a href=\"#{instance.root_url.chomp('/')}/#{build.url}\">Open</a>)"
+ end
+ msg
+ end
+ end
+
+ class SuccessMessage
+ include Message
+
+ def initialize(build)
+ @build = build
+ @status = 'Success'
+ @color = 'green'
+ @notify = false
+ end
+ end
+
+ class UnstableMessage
+ include Message
+
+ def initialize(build)
+ @build = build
+ @status = 'Unstable'
+ @color = 'yellow'
+ @notify = true
+ end
+ end
+
+ class FailureMessage
+ include Message
+
+ def initialize(build)
+ @build = build
+ @status = 'FAILURE'
+ @color = 'red'
+ @notify = true
+ end
+
+ def message
+ msg = super
+ items = build.change_set.items
+ unless items.empty?
+ msg << ': changed by '
+ msg << items.map { |i|
+ if i.respond_to? :author_name # GitChangeSet
+ "@\"#{i.author_name}\""
+ else
+ "@#{i.author.full_name}"
+ end
+ }.uniq.join(' ')
+ end
+ msg
+ end
+ end
+
+ class NotBuiltMessage
+ include Message
+
+ def initialize(build)
+ @build = build
+ @status = 'Not Built'
+ @color = 'yellow'
+ @notify = true
+ end
+ end
+
+ class AbortedMessage
+ include Message
+
+ def initialize(build)
+ @build = build
+ @status = 'ABORTED'
+ @color = 'yellow'
+ @notify = false
+ end
+ end
+end
@@ -0,0 +1,22 @@
+module Ikachan
+ class MessageFactory
+ def self.create(build)
+ case build.result
+ when Result::SUCCESS
+ SuccessMessage.new(build)
+
+ when Result::UNSTABLE
+ UnstableMessage.new(build)
+
+ when Result::FAILURE
+ FailureMessage.new(build)
+
+ when Result::NOT_BUILT
+ NotBuiltMessage.new(build)
+
+ when Result::ABORTED
+ AbortedMessage.new(build)
+ end
+ end
+ end
+end
@@ -0,0 +1,22 @@
+require 'ikachan'
+
+class IkachanPublisher < Jenkins::Tasks::Publisher
+
+ display_name "Ikachan publisher"
+ attr_reader :base_url, :channel, :ikachan
+
+ def initialize(attrs = {})
+ @base_url = attrs['base_url']
+ @channel = attrs['channel']
+ end
+
+ def prebuild(build, listener)
+ @ikachan = Ikachan::Client.new @base_url, listener
+ @ikachan.join channel
+ end
+
+ def perform(build, launcher, listener)
+ message = Ikachan::MessageFactory.create(build.native).message
+ ikachan.notice channel, message
+ end
+end
@@ -0,0 +1,6 @@
+require 'spec_helper'
+
+describe Ikachan do
+ let(:ikachan) { Ikachan.new 'http://example.com/' }
+ pending 'how to do it'
+end
@@ -0,0 +1 @@
+require 'ikachan'
@@ -0,0 +1,17 @@
+<%
+f = taglib("/lib/form")
+f.entry(
+ :title => 'Base URL',
+ :field => 'base_url',
+ :description => "Ikachan's Base URL (ex. http://ikachan.example.com/)"
+) do
+ f.textbox
+end
+f.entry(
+ :title => 'Channel',
+ :field => 'channel',
+ :description => "A channel to be published."
+) do
+ f.textbox
+end
+%>

0 comments on commit 7f89278

Please sign in to comment.