Merge pull request #329 from abf/rosa-build:328-post-commit-hooks-to-email-updates
#328: post-commit hooks to email updates
This commit is contained in:
commit
e40c076a38
|
@ -11,7 +11,7 @@ module ActivityFeedsHelper
|
|||
feed_title = feed_title.gsub(/\s{2,}/, ' ').strip
|
||||
end
|
||||
|
||||
def user_link user, user_name
|
||||
user.persisted? ? link_to(user_name, user_path(user)) : user_name
|
||||
def user_link(user, user_name, full_url = false)
|
||||
user.persisted? ? link_to(user_name, full_url ? user_url(user) : user_path(user)) : user_name
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,6 +1,9 @@
|
|||
# -*- encoding : utf-8 -*-
|
||||
|
||||
class UserMailer < ActionMailer::Base
|
||||
add_template_helper ActivityFeedsHelper
|
||||
add_template_helper CommitHelper
|
||||
|
||||
default :from => "\"#{APP_CONFIG['project_name']}\" <#{APP_CONFIG['do-not-reply-email']}>"
|
||||
default_url_options.merge!(:protocol => 'https') if APP_CONFIG['mailer_https_url']
|
||||
|
||||
|
@ -52,7 +55,7 @@ class UserMailer < ActionMailer::Base
|
|||
end
|
||||
|
||||
def build_list_notification(build_list, user)
|
||||
I18n.locale = user.language if user.language
|
||||
set_locale user
|
||||
@user, @build_list = user, build_list
|
||||
|
||||
subject = "[№ #{build_list.id}] "
|
||||
|
@ -69,7 +72,7 @@ class UserMailer < ActionMailer::Base
|
|||
end
|
||||
|
||||
def invite_approve_notification(register_request)
|
||||
I18n.locale = register_request.language if register_request.language
|
||||
set_locale register_request
|
||||
@register_request = register_request
|
||||
mail(
|
||||
:to => register_request.email,
|
||||
|
@ -79,8 +82,32 @@ class UserMailer < ActionMailer::Base
|
|||
end
|
||||
end
|
||||
|
||||
def git_delete_branch_notification(user, options)
|
||||
set_locale user
|
||||
mail(
|
||||
:to => user.email,
|
||||
:subject => I18n.t('notifications.subjects.update_code', :project_name => "#{options[:project_owner]}/#{options[:project_name]}")
|
||||
) do |format|
|
||||
format.html { render 'git_delete_branch_notification', :locals => options }
|
||||
end
|
||||
end
|
||||
|
||||
def git_new_push_notification(user, options)
|
||||
set_locale user
|
||||
mail(
|
||||
:to => user.email,
|
||||
:subject => I18n.t('notifications.subjects.update_code', :project_name => "#{options[:project_owner]}/#{options[:project_name]}")
|
||||
) do |format|
|
||||
format.html { render 'git_new_push_notification', :locals => options }
|
||||
end
|
||||
end
|
||||
|
||||
protected
|
||||
|
||||
def set_locale(user)
|
||||
I18n.locale = user.language if user.language
|
||||
end
|
||||
|
||||
def email_with_name(user, email = APP_CONFIG['do-not-reply-email'])
|
||||
"\"#{user.user_appeal}\" <#{email}>"
|
||||
end
|
||||
|
|
|
@ -1,7 +1,8 @@
|
|||
json.user do
|
||||
json.(@user, :id)
|
||||
json.notifiers do
|
||||
json.(@user.notifier, :can_notify, :new_comment, :new_comment_reply, :new_issue, :issue_assign, :new_comment_commit_owner, :new_comment_commit_repo_owner, :new_comment_commit_commentor, :new_build, :new_associated_build)
|
||||
json.(@user.notifier, :can_notify, :new_comment, :new_comment_reply, :new_issue, :issue_assign, :new_comment_commit_owner, :new_comment_commit_repo_owner, :new_comment_commit_commentor, :new_build, :new_associated_build,
|
||||
:update_code)
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -0,0 +1,8 @@
|
|||
- user = User.where(:email => user_email).first || User.new(:email => user_email) if defined?(user_email)
|
||||
|
||||
%p
|
||||
- _user_link = defined?(user_email) ? user_link(user, defined?(user_name) ? user_name : user_email, true) : nil
|
||||
= t('notifications.bodies.delete_branch', :branch_name => branch_name, :user_link => _user_link).html_safe
|
||||
= raw t("notifications.bodies.project", :project_link => link_to("#{project_owner}/#{project_name}", project_url(project_owner, project_name)) )
|
||||
|
||||
= render 'footer'
|
|
@ -0,0 +1,20 @@
|
|||
- user = User.where(:email => user_email).first || User.new(:email => user_email) if defined?(user_email)
|
||||
|
||||
|
||||
%p
|
||||
- _user_link = defined?(user_email) ? user_link(user, defined?(user_name) ? user_name : user_email, true) : nil
|
||||
= raw t("notifications.bodies.#{change_type}_branch", {:branch_name => branch_name, :user_link => _user_link})
|
||||
= raw t("notifications.bodies.project", :project_link => link_to("#{project_owner}/#{project_name}", project_url(project_owner, project_name)) )
|
||||
|
||||
|
||||
%p
|
||||
- last_commits.each do |commit|
|
||||
= link_to shortest_hash_id(commit[0]), commit_url(project_owner, project_name, commit[0])
|
||||
= commit[1]
|
||||
%br
|
||||
- if defined? other_commits
|
||||
%br
|
||||
=link_to t('notifications.bodies.more_commits', :count => other_commits_count, :commits => commits_pluralize(other_commits_count)),
|
||||
diff_url(project_owner, project_name, :diff => other_commits)
|
||||
|
||||
= render 'footer'
|
|
@ -9,7 +9,7 @@
|
|||
= form_for @user.notifier, :url => notifiers_settings_path, :html => {:class => :form} do |f|
|
||||
= render 'notifier', :f => f, :field => :can_notify
|
||||
%h3= t("layout.settings.notifiers.code_header")
|
||||
- [:new_comment_commit_owner, :new_comment_commit_repo_owner, :new_comment_commit_commentor].each do |field|
|
||||
- [:update_code, :new_comment_commit_owner, :new_comment_commit_repo_owner, :new_comment_commit_commentor].each do |field|
|
||||
= render 'notifier', :f => f, :field => field
|
||||
%h3= t("layout.settings.notifiers.tracker_header")
|
||||
- [:new_comment, :new_comment_reply, :new_issue, :issue_assign].each do |field|
|
||||
|
|
|
@ -154,11 +154,11 @@ en:
|
|||
group_already_added: Group already added
|
||||
successfully_added: Member %s successfully added
|
||||
error_in_adding: Member %s adding error
|
||||
wrong_user: User with nickname '%{uname}' not found!
|
||||
wrong_user: "User with nickname '%{uname}' not found!"
|
||||
|
||||
blob:
|
||||
successfully_updated: File '%{name}' successfully updated
|
||||
updating_error: Error updating file '%{name}'
|
||||
successfully_updated: "File '%{name}' successfully updated"
|
||||
updating_error: "Error updating file '%{name}'"
|
||||
|
||||
attributes:
|
||||
password: Password
|
||||
|
@ -188,6 +188,7 @@ en:
|
|||
new_comment_reply: New reply of comment notifications
|
||||
new_issue: New task notifications
|
||||
issue_assign: New task assignment notifications
|
||||
update_code: Notify about changes of code in my projects
|
||||
new_comment_commit_owner: Notify about comments to my commit
|
||||
new_comment_commit_repo_owner: Notify about comments to my repository commits
|
||||
new_comment_commit_commentor: Notify about comments after my commit
|
||||
|
|
|
@ -12,6 +12,7 @@ en:
|
|||
|
||||
notifications:
|
||||
subjects:
|
||||
update_code: "[%{project_name}] Update of project"
|
||||
new_comment_notification: New comment to your task
|
||||
new_commit_comment_notification: New comment to commit
|
||||
new_issue_notification: New task added to project
|
||||
|
|
|
@ -12,6 +12,7 @@ ru:
|
|||
|
||||
notifications:
|
||||
subjects:
|
||||
update_code: "[%{project_name}] Обновление проекта"
|
||||
new_comment_notification: Новый комментарий к Вашей задаче
|
||||
new_commit_comment_notification: Новый комментарий к коммиту
|
||||
new_issue_notification: Новая задача добавлена к проекту
|
||||
|
|
|
@ -154,11 +154,11 @@ ru:
|
|||
group_already_added: Группа уже добавлена
|
||||
successfully_added: Участник %s успешно добавлен
|
||||
error_in_adding: Ошибка при добавлении участника %s
|
||||
wrong_user: Пользователь с ником '%{uname}' не найден.
|
||||
wrong_user: "Пользователь с ником '%{uname}' не найден."
|
||||
|
||||
blob:
|
||||
successfully_updated: Файл '%{name}' успешно обновлен
|
||||
updating_error: Ошибка обновления файла '%{name}'
|
||||
successfully_updated: "Файл '%{name}' успешно обновлен"
|
||||
updating_error: "Ошибка обновления файла '%{name}'"
|
||||
|
||||
attributes:
|
||||
password: Пароль
|
||||
|
@ -188,6 +188,7 @@ ru:
|
|||
new_comment_reply: Оповещать о новом ответе на мой комментарий
|
||||
new_issue: Оповещать о новых задачах в моих проектах
|
||||
issue_assign: Оповещать, когда на меня выставляют задачу
|
||||
update_code: Оповещать об изменении кода в моих проектах
|
||||
new_comment_commit_owner: Оповещать о комментариях к моему коммиту
|
||||
new_comment_commit_repo_owner: Оповещать о комментариях к коммитам в моем репозитории
|
||||
new_comment_commit_commentor: Оповещать о комментариях к коммиту после моего
|
||||
|
|
|
@ -0,0 +1,5 @@
|
|||
class AddNewCommitToSettingsNotifier < ActiveRecord::Migration
|
||||
def change
|
||||
add_column :settings_notifiers, :update_code, :boolean, :default => false
|
||||
end
|
||||
end
|
|
@ -11,7 +11,7 @@
|
|||
#
|
||||
# It's strongly recommended to check this file into your version control system.
|
||||
|
||||
ActiveRecord::Schema.define(:version => 20131107152408) do
|
||||
ActiveRecord::Schema.define(:version => 20131126154305) do
|
||||
|
||||
create_table "activity_feeds", :force => true do |t|
|
||||
t.integer "user_id", :null => false
|
||||
|
@ -21,6 +21,8 @@ ActiveRecord::Schema.define(:version => 20131107152408) do
|
|||
t.datetime "updated_at"
|
||||
end
|
||||
|
||||
add_index "activity_feeds", ["user_id", "kind"], :name => "index_activity_feeds_on_user_id_and_kind"
|
||||
|
||||
create_table "advisories", :force => true do |t|
|
||||
t.string "advisory_id"
|
||||
t.text "description", :default => ""
|
||||
|
@ -522,6 +524,7 @@ ActiveRecord::Schema.define(:version => 20131107152408) do
|
|||
t.boolean "new_comment_commit_commentor", :default => true
|
||||
t.boolean "new_build", :default => true
|
||||
t.boolean "new_associated_build", :default => true
|
||||
t.boolean "update_code", :default => false
|
||||
end
|
||||
|
||||
create_table "ssh_keys", :force => true do |t|
|
||||
|
|
|
@ -44,6 +44,9 @@ module Modules::Observers::ActivityFeed::Git
|
|||
:kind => kind,
|
||||
:data => options
|
||||
)
|
||||
if recipient.notifier.can_notify && recipient.notifier.update_code
|
||||
UserMailer.send(kind, recipient, options).deliver
|
||||
end
|
||||
end
|
||||
|
||||
when 'Hash' # 'Gollum::Committer'
|
||||
|
|
|
@ -124,6 +124,7 @@ describe Repository do
|
|||
end
|
||||
|
||||
it '#remove_projects' do
|
||||
stub_redis
|
||||
repository = FactoryGirl.create(:repository)
|
||||
project = FactoryGirl.create(:project)
|
||||
repository.projects << project
|
||||
|
|
Loading…
Reference in New Issue