From fba2c2bb706aa383334ca81100ec7e3c2fc31d5f Mon Sep 17 00:00:00 2001 From: Darius Kramer Date: Thu, 21 Sep 2017 10:09:05 +0200 Subject: [PATCH 1/5] Add default webhook configuration if absent from project --- lib/redmine_webhook/webhook_listener.rb | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lib/redmine_webhook/webhook_listener.rb b/lib/redmine_webhook/webhook_listener.rb index acc7537..4c1a6eb 100644 --- a/lib/redmine_webhook/webhook_listener.rb +++ b/lib/redmine_webhook/webhook_listener.rb @@ -15,6 +15,7 @@ module RedmineWebhook controller = context[:controller] project = issue.project webhooks = Webhook.where(:project_id => project.project.id) + webhooks = Webhook.where(:project_id => 0) unless webhooks return unless webhooks post(webhooks, issue_to_json(issue, controller)) end @@ -26,6 +27,7 @@ module RedmineWebhook issue = context[:issue] project = issue.project webhooks = Webhook.where(:project_id => project.project.id) + webhooks = Webhook.where(:project_id => 0) unless webhooks return unless webhooks post(webhooks, journal_to_json(issue, journal, controller)) end From cf9978008884deac6129096ad68bcf5809e67486 Mon Sep 17 00:00:00 2001 From: Benjamin MALYNOVYTCH Date: Thu, 21 Sep 2017 14:24:30 +0200 Subject: [PATCH 2/5] Fix default configuration not being used --- lib/redmine_webhook/webhook_listener.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/redmine_webhook/webhook_listener.rb b/lib/redmine_webhook/webhook_listener.rb index 4c1a6eb..c78158e 100644 --- a/lib/redmine_webhook/webhook_listener.rb +++ b/lib/redmine_webhook/webhook_listener.rb @@ -15,7 +15,7 @@ module RedmineWebhook controller = context[:controller] project = issue.project webhooks = Webhook.where(:project_id => project.project.id) - webhooks = Webhook.where(:project_id => 0) unless webhooks + webhooks = Webhook.where(:project_id => 0) unless webhooks && webhooks.length > 0 return unless webhooks post(webhooks, issue_to_json(issue, controller)) end @@ -27,7 +27,7 @@ module RedmineWebhook issue = context[:issue] project = issue.project webhooks = Webhook.where(:project_id => project.project.id) - webhooks = Webhook.where(:project_id => 0) unless webhooks + webhooks = Webhook.where(:project_id => 0) unless webhooks && webhooks.length > 0 return unless webhooks post(webhooks, journal_to_json(issue, journal, controller)) end From fa020e1d10ecc38c8f8e4c0a302945b54f357544 Mon Sep 17 00:00:00 2001 From: Donovan JEAN Date: Thu, 28 Sep 2017 11:12:21 +0200 Subject: [PATCH 3/5] Added: emit webhook for bulk edit --- lib/redmine_webhook/webhook_listener.rb | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/lib/redmine_webhook/webhook_listener.rb b/lib/redmine_webhook/webhook_listener.rb index c78158e..96bfd20 100644 --- a/lib/redmine_webhook/webhook_listener.rb +++ b/lib/redmine_webhook/webhook_listener.rb @@ -32,6 +32,17 @@ module RedmineWebhook post(webhooks, journal_to_json(issue, journal, controller)) end + def controller_issues_bulk_edit_after_save(context = {}) + return if skip_webhooks(context) + journal = context[:journal] + controller = context[:controller] + issue = context[:issue] + project = issue.project + webhooks = Webhook.where(:project_id => project.project.id) + return unless webhooks + post(webhooks, journal_to_json(issue, journal, controller)) + end + private def issue_to_json(issue, controller) { From 4a1bddcf74f3d30f876e8320ad869c0568041922 Mon Sep 17 00:00:00 2001 From: Donovan JEAN Date: Thu, 5 Oct 2017 15:43:50 +0200 Subject: [PATCH 4/5] Added: emit webhook when fetching changeset --- lib/redmine_webhook/webhook_listener.rb | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/lib/redmine_webhook/webhook_listener.rb b/lib/redmine_webhook/webhook_listener.rb index 96bfd20..28756bc 100644 --- a/lib/redmine_webhook/webhook_listener.rb +++ b/lib/redmine_webhook/webhook_listener.rb @@ -39,10 +39,20 @@ module RedmineWebhook issue = context[:issue] project = issue.project webhooks = Webhook.where(:project_id => project.project.id) + webhooks = Webhook.where(:project_id => 0) unless webhooks && webhooks.length > 0 return unless webhooks post(webhooks, journal_to_json(issue, journal, controller)) end + def model_changeset_scan_commit_for_issue_ids_pre_issue_update(context = {}) + issue = context[:issue] + journal = issue.current_journal + webhooks = Webhook.where(:project_id => issue.project.project.id) + webhooks = Webhook.where(:project_id => 0) unless webhooks && webhooks.length > 0 + return unless webhooks + post(webhooks, journal_to_json(issue, journal, nil)) + end + private def issue_to_json(issue, controller) { @@ -60,7 +70,7 @@ module RedmineWebhook :action => 'updated', :issue => RedmineWebhook::IssueWrapper.new(issue).to_hash, :journal => RedmineWebhook::JournalWrapper.new(journal).to_hash, - :url => controller.issue_url(issue) + :url => controller.nil? ? 'not yet implemented' : controller.issue_url(issue) } }.to_json end From 82ce30a0c37a2894456993301e7d9f3cfb4de615 Mon Sep 17 00:00:00 2001 From: Julian Maestri Date: Wed, 24 Jul 2019 20:03:44 -0300 Subject: [PATCH 5/5] fix: handle empty webhook url --- app/controllers/webhook_settings_controller.rb | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/app/controllers/webhook_settings_controller.rb b/app/controllers/webhook_settings_controller.rb index 4b84697..e512413 100644 --- a/app/controllers/webhook_settings_controller.rb +++ b/app/controllers/webhook_settings_controller.rb @@ -20,7 +20,9 @@ class WebhookSettingsController < ApplicationController id = params[:webhook_id] webhook = Webhook.where(:project_id => @project.id).where(:id => id).first webhook.url = params[:url] - if webhook.save + if webhook.url.empty? + webhook.destroy + elsif webhook.save flash[:notice] = l(:notice_successful_update_webhook) else flash[:error] = l(:notice_fail_update_webhook)