]> git.netwichtig.de Git - user/henk/code/ruby/rbot.git/commitdiff
webhook: include target ref for pull/merge requests
authorGiuseppe Bilotta <giuseppe.bilotta@gmail.com>
Mon, 31 May 2021 10:49:40 +0000 (12:49 +0200)
committerGiuseppe Bilotta <giuseppe.bilotta@gmail.com>
Mon, 31 May 2021 11:20:43 +0000 (13:20 +0200)
Also add a TODO about a possible event-based output filter.

data/rbot/plugins/webhook.rb

index 6e8acb9278a8bd2115ee943dcdc7b111ca016298..cf93d9a732678cb28ac88f8e2df048b09150eb90 100644 (file)
 # TODO for the repo matchers in the built-in filters we might want to support
 # both the whole user/repo or just the repo name
 
+# TODO specialized output filter by event/event_key, with some kind of automatic selection
+# e.g. if :default_pull_request exists, then it's automatically used if :event => "pull_request"
+# and :default is the current output filter.
+# The big question is what we should fallback to if the specific filter doesn't exist..
+#
+# If :custom exists, :default_pull_request exists and :custom_pull_request does not,
+# should we fall back to :custom or to :default_pull_request?
+
+
 require 'json'
 
 class WebHookPlugin < Plugin
@@ -211,6 +220,8 @@ class WebHookPlugin < Plugin
                     :link => link
     }
 
+    stream_hash[:ref] ||= json[:base][:ref] if json[:base]
+
     num = json[:number] || obj[:number] rescue nil
     stream_hash[:number] = '%{object} #%{num}' % { :num => num, :object => event_key.to_s.gsub('_', ' ') } if num
     num = json[:size] || json[:commits].size rescue nil
@@ -279,6 +290,8 @@ class WebHookPlugin < Plugin
                     :text => obj ? (obj[:note] || obj[:description]) : nil
     }
 
+    stream_hash[:ref] ||= obj[:target_branch] if obj
+
     num = notable ? (notable[:iid] || notable[:id]) : obj ? obj[:iid] || obj[:id] : nil
     stream_hash[:number] = '%{object} #%{num}' % { :num => num, :object => (obj[:noteable_type] || event).to_s.gsub('_', ' ') } if num
     num = json[:total_commits_count]