diff options
author | Aleksey Lim <alsroot@sugarlabs.org> | 2013-02-03 08:04:04 (GMT) |
---|---|---|
committer | Aleksey Lim <alsroot@sugarlabs.org> | 2013-02-03 12:59:26 (GMT) |
commit | 87b3dbb1580a7e943ac7dbbd04dfcdcd23254de5 (patch) | |
tree | c3c13627ae64e893ab7d4943f0a40def65a7c35a | |
parent | 949691a14d6c071e6f8f0a08fb25a01c9b63916d (diff) |
Adapt SL notifiers to the recent Gitorious changes
-rw-r--r-- | app/processors/push_processor.rb | 41 | ||||
-rw-r--r-- | lib/emailer.rb | 14 | ||||
-rw-r--r-- | lib/patchwork.rb | 2 |
3 files changed, 46 insertions, 11 deletions
diff --git a/app/processors/push_processor.rb b/app/processors/push_processor.rb index f2f3376..c393746 100644 --- a/app/processors/push_processor.rb +++ b/app/processors/push_processor.rb @@ -26,6 +26,13 @@ class PushProcessor consumes "/queue/GitoriousPush" attr_reader :user, :repository, :spec + include Patchwork + include Emailer + + PUSH_EVENT_GIT_OUTPUT_SEPARATOR = "\t" + PUSH_EVENT_GIT_OUTPUT_SEPARATOR_ESCAPED = "\\\t" + GIT_PRETTY_FORMAT = "format:#{['%H','%cn <%ce>','%at','%s','%an'].join(PUSH_EVENT_GIT_OUTPUT_SEPARATOR)}" + def on_message(message) load_message(message) log_message("Got payload: #{spec} from user #{user && user.login}") @@ -49,12 +56,40 @@ class PushProcessor def process_push ensure_user - logger = PushEventLogger.new(repository, spec, user) - logger.create_push_event if logger.create_push_event? - logger.create_meta_event if logger.create_meta_event? + log = PushEventLogger.new(repository, spec, user) + log.create_push_event if log.create_push_event? + log.create_meta_event if log.create_meta_event? repository.register_push repository.save trigger_hooks unless repository.hooks.blank? + + if spec.head? && spec.action_update? + begin + notify + rescue => e + logger.error("Notification failed: #{e.class.name} #{e.message}:\n #{e.backtrace.join("\n ")}") + end + end + end + + def notify + commits = [] + + repository.git.git.log( + {:pretty => GIT_PRETTY_FORMAT, :s => true, :timeout => false}, + "#{spec.from_sha.sha}..#{spec.to_sha.sha}").split("\n").each do |commit| + sha, email, timestamp, message, author = commit.split(PUSH_EVENT_GIT_OUTPUT_SEPARATOR_ESCAPED) + commits.push({ + :sha => sha, + :timestamp => Time.at(timestamp.to_i).utc, + :user => user, + :author => author, + :message => message, + }) + end + + notify_patchwork(repository, spec.ref.name, commits) if GitoriousConfig["patchwork"] + notify_emailer(repository, spec.ref.name, commits) if GitoriousConfig["emailer"] end def trigger_hooks diff --git a/lib/emailer.rb b/lib/emailer.rb index 8e56c50..b6356ed 100644 --- a/lib/emailer.rb +++ b/lib/emailer.rb @@ -19,10 +19,10 @@ module Emailer def notify_emailer(repository, branch, events) events.each do |event| - next unless event.commit_details[:committer].login == 'pootle' + next unless event[:user].login == 'pootle' - sha = event.commit_details[:id] - author = event.commit_details[:commit_author] + sha = event[:sha] + author = event[:author] begin files = [] @@ -36,7 +36,7 @@ module Emailer langs = "unknown languages" end - event.commit_details[:message] =~ / by user ([^\s:]+)/ + event[:message] =~ / by user ([^\s:]+)/ translator = $1 or '<anonymous>' subject = "Commit to [#{repository.project.title}] by [#{translator}] for [#{langs}]" @@ -46,10 +46,10 @@ Repository: #{repository.title} Branch: #{branch} Author: #{author} -Timestamp: #{event.commit_time} -Url: http://#{GitoriousConfig['gitorious_host']}/#{repository.url_path}/commit/#{event.commit_details[:id]} +Timestamp: #{event[:timestamp]} +Url: http://#{GitoriousConfig['gitorious_host']}/#{repository.url_path}/commit/#{event[:sha]} -#{event.commit_details[:message]} +#{event[:message]} #{files.map {|i| "- #{i}"}.join("\n")} EOF diff --git a/lib/patchwork.rb b/lib/patchwork.rb index 7ff17be..89f6f6a 100644 --- a/lib/patchwork.rb +++ b/lib/patchwork.rb @@ -39,7 +39,7 @@ module Patchwork end events.each do |event| - commit_id = event.commit_details[:id] + commit_id = event[:sha] patch_hash = hash_patch(git.show({}, commit_id)) begin |