Skip to content

Commit

Permalink
Merge pull request suer#28 from serpi90/admantic-changes
Browse files Browse the repository at this point in the history
Fixes and merges from other repos
  • Loading branch information
suer authored Nov 30, 2019
2 parents 9acb467 + 82ce30a commit 57ece2f
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 2 deletions.
4 changes: 3 additions & 1 deletion app/controllers/webhook_settings_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@ def update
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)
Expand Down
25 changes: 24 additions & 1 deletion lib/redmine_webhook/webhook_listener.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ def controller_issues_new_after_save(context = {})
controller = context[:controller]
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, issue_to_json(issue, controller))
end
Expand All @@ -26,10 +27,32 @@ def controller_issues_edit_after_save(context = {})
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 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)
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)
{
Expand All @@ -47,7 +70,7 @@ def journal_to_json(issue, journal, controller)
: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
Expand Down

0 comments on commit 57ece2f

Please sign in to comment.