Commit 85af3e82 authored by Douwe Maan's avatar Douwe Maan

Add option to disable code diffs to EmailOnPush.

See #1950
parent e0c186c3
......@@ -46,7 +46,7 @@ class Admin::ServicesController < Admin::ApplicationController
:user_key, :device, :priority, :sound, :bamboo_url, :username, :password,
:build_key, :server, :teamcity_url, :build_type,
:description, :issues_url, :new_issue_url, :restrict_to_branch,
:send_from_committer_email
:send_from_committer_email, :disable_diffs
])
end
end
......@@ -51,7 +51,7 @@ class Projects::ServicesController < Projects::ApplicationController
:user_key, :device, :priority, :sound, :bamboo_url, :username, :password,
:build_key, :server, :teamcity_url, :build_type,
:description, :issues_url, :new_issue_url, :restrict_to_branch,
:send_from_committer_email
:send_from_committer_email, :disable_diffs
)
end
end
......@@ -16,13 +16,14 @@ module Emails
subject: subject("Project was moved"))
end
def repository_push_email(project_id, recipient, author_id, branch, compare, send_from_committer_email = false)
def repository_push_email(project_id, recipient, author_id, branch, compare, send_from_committer_email = false, disable_diffs = false)
@project = Project.find(project_id)
@author = User.find(author_id)
@compare = compare
@commits = Commit.decorate(compare.commits)
@diffs = compare.diffs
@branch = branch.gsub("refs/heads/", "")
@disable_diffs = disable_diffs
@subject = "[#{@project.path_with_namespace}][#{@branch}] "
......
......@@ -15,6 +15,7 @@
class EmailsOnPushService < Service
prop_accessor :send_from_committer_email
prop_accessor :disable_diffs
prop_accessor :recipients
validates :recipients, presence: true, if: :activated?
......@@ -34,13 +35,18 @@ class EmailsOnPushService < Service
self.send_from_committer_email == "1"
end
def disable_diffs?
self.disable_diffs == "1"
end
def execute(push_data)
EmailsOnPushWorker.perform_async(project_id, recipients, push_data, self.send_from_committer_email?)
EmailsOnPushWorker.perform_async(project_id, recipients, push_data, send_from_committer_email?, disable_diffs?)
end
def fields
[
{ type: 'checkbox', name: 'send_from_committer_email', title: "Send from committer email if domain matches" },
{ type: 'checkbox', name: 'disable_diffs', title: "Disable code diffs" },
{ type: 'textarea', name: 'recipients', placeholder: 'Emails separated by whitespace' },
]
end
......
......@@ -16,7 +16,7 @@
%ul
- @diffs.each_with_index do |diff, i|
%li.file-stats
%a{href: "#diff-#{i}"}
%a{href: "#{@target_url if @disable_diffs}#diff-#{i}" }
- if diff.deleted_file
%span.deleted-file
&minus;
......@@ -32,8 +32,9 @@
- else
= diff.new_path
%h4 Changes:
- @diffs.each_with_index do |diff, i|
- unless @disable_diffs
%h4 Changes:
- @diffs.each_with_index do |diff, i|
%li{id: "diff-#{i}"}
%a{href: @target_url + "#diff-#{i}"}
- if diff.deleted_file
......
......@@ -19,10 +19,11 @@ Commits:
\- + #{diff.new_path}
- else
\- #{diff.new_path}
\
\
Changes:
- @diffs.each do |diff|
- unless @disable_diffs
\
\
Changes:
- @diffs.each do |diff|
\
\=====================================
- if diff.deleted_file
......@@ -33,6 +34,7 @@ Changes:
= diff.new_path
\=====================================
!= diff.diff
\
- if @compare.timeout
\
\
Huge diff. To prevent performance issues it was hidden
class EmailsOnPushWorker
include Sidekiq::Worker
def perform(project_id, recipients, push_data, send_from_committer_email = false)
def perform(project_id, recipients, push_data, send_from_committer_email = false, disable_diffs = false)
project = Project.find(project_id)
before_sha = push_data["before"]
after_sha = push_data["after"]
......@@ -19,7 +19,15 @@ class EmailsOnPushWorker
return false unless compare && compare.commits.present?
recipients.split(" ").each do |recipient|
Notify.repository_push_email(project_id, recipient, author_id, branch, compare, send_from_committer_email).deliver
Notify.repository_push_email(
project_id,
recipient,
author_id,
branch,
compare,
send_from_committer_email,
disable_diffs
).deliver
end
ensure
compare = nil
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment