From b90cbfd21ec9bd366ee931d246d51f8821b2a023 Mon Sep 17 00:00:00 2001 From: Dmitriy Zaporozhets Date: Tue, 17 Dec 2013 12:20:36 +0200 Subject: [PATCH 01/12] Move project services models to own subdirectory Signed-off-by: Dmitriy Zaporozhets --- app/models/project.rb | 7 +++++++ app/models/{ => project_services}/assembla_service.rb | 0 app/models/{ => project_services}/campfire_service.rb | 0 app/models/{ => project_services}/flowdock_service.rb | 0 app/models/{ => project_services}/gitlab_ci_service.rb | 0 app/models/{ => project_services}/hipchat_service.rb | 0 .../{ => project_services}/pivotaltracker_service.rb | 0 7 files changed, 7 insertions(+) rename app/models/{ => project_services}/assembla_service.rb (100%) rename app/models/{ => project_services}/campfire_service.rb (100%) rename app/models/{ => project_services}/flowdock_service.rb (100%) rename app/models/{ => project_services}/gitlab_ci_service.rb (100%) rename app/models/{ => project_services}/hipchat_service.rb (100%) rename app/models/{ => project_services}/pivotaltracker_service.rb (100%) diff --git a/app/models/project.rb b/app/models/project.rb index 1bfc27d723d..2843d560360 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -23,6 +23,13 @@ # visibility_level :integer default(0), not null # +require_relative "project_services/assembla_service" +require_relative "project_services/campfire_service" +require_relative "project_services/flowdock_service" +require_relative "project_services/gitlab_ci_service" +require_relative "project_services/hipchat_service" +require_relative "project_services/pivotaltracker_service" + class Project < ActiveRecord::Base include Gitlab::ShellAdapter include Gitlab::VisibilityLevel diff --git a/app/models/assembla_service.rb b/app/models/project_services/assembla_service.rb similarity index 100% rename from app/models/assembla_service.rb rename to app/models/project_services/assembla_service.rb diff --git a/app/models/campfire_service.rb b/app/models/project_services/campfire_service.rb similarity index 100% rename from app/models/campfire_service.rb rename to app/models/project_services/campfire_service.rb diff --git a/app/models/flowdock_service.rb b/app/models/project_services/flowdock_service.rb similarity index 100% rename from app/models/flowdock_service.rb rename to app/models/project_services/flowdock_service.rb diff --git a/app/models/gitlab_ci_service.rb b/app/models/project_services/gitlab_ci_service.rb similarity index 100% rename from app/models/gitlab_ci_service.rb rename to app/models/project_services/gitlab_ci_service.rb diff --git a/app/models/hipchat_service.rb b/app/models/project_services/hipchat_service.rb similarity index 100% rename from app/models/hipchat_service.rb rename to app/models/project_services/hipchat_service.rb diff --git a/app/models/pivotaltracker_service.rb b/app/models/project_services/pivotaltracker_service.rb similarity index 100% rename from app/models/pivotaltracker_service.rb rename to app/models/project_services/pivotaltracker_service.rb -- GitLab From 5ac57305477ed90bf416b3c795516e9b9135bf5b Mon Sep 17 00:00:00 2001 From: Dmitriy Zaporozhets Date: Tue, 17 Dec 2013 12:42:13 +0200 Subject: [PATCH 02/12] Sort project services by title. Add textarea support to it Signed-off-by: Dmitriy Zaporozhets --- app/views/projects/services/_form.html.haml | 2 ++ app/views/projects/services/index.html.haml | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/app/views/projects/services/_form.html.haml b/app/views/projects/services/_form.html.haml index 202bf327217..e220d6a3185 100644 --- a/app/views/projects/services/_form.html.haml +++ b/app/views/projects/services/_form.html.haml @@ -33,6 +33,8 @@ .controls - if type == 'text' = f.text_field name, class: "input-xlarge", placeholder: placeholder + - elsif type == 'textarea' + = f.textarea name, rows: 5 - elsif type == 'checkbox' = f.check_box name diff --git a/app/views/projects/services/index.html.haml b/app/views/projects/services/index.html.haml index 190aa69dab7..9543d97b7f7 100644 --- a/app/views/projects/services/index.html.haml +++ b/app/views/projects/services/index.html.haml @@ -3,7 +3,7 @@ %hr %ul.bordered-list - - @services.each do |service| + - @services.sort_by(&:title).each do |service| %li %h4 = link_to edit_project_service_path(@project, service.to_param) do -- GitLab From 86a8796b1322879d01e9cea8fb728458e0e328cb Mon Sep 17 00:00:00 2001 From: Dmitriy Zaporozhets Date: Tue, 17 Dec 2013 12:42:40 +0200 Subject: [PATCH 03/12] Create EmailsOnPushService model Signed-off-by: Dmitriy Zaporozhets --- app/models/project.rb | 4 +- .../emails_on_push_service.rb | 45 +++++++++++++++++++ ...0131217102743_add_recipients_to_service.rb | 5 +++ db/schema.rb | 32 +++++++------ 4 files changed, 71 insertions(+), 15 deletions(-) create mode 100644 app/models/project_services/emails_on_push_service.rb create mode 100644 db/migrate/20131217102743_add_recipients_to_service.rb diff --git a/app/models/project.rb b/app/models/project.rb index 2843d560360..d55714662b2 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -25,6 +25,7 @@ require_relative "project_services/assembla_service" require_relative "project_services/campfire_service" +require_relative "project_services/emails_on_push_service" require_relative "project_services/flowdock_service" require_relative "project_services/gitlab_ci_service" require_relative "project_services/hipchat_service" @@ -55,6 +56,7 @@ class Project < ActiveRecord::Base has_one :last_event, -> {order 'events.created_at DESC'}, class_name: 'Event', foreign_key: 'project_id' has_one :gitlab_ci_service, dependent: :destroy has_one :campfire_service, dependent: :destroy + has_one :emails_on_push_service, dependent: :destroy has_one :pivotaltracker_service, dependent: :destroy has_one :hipchat_service, dependent: :destroy has_one :flowdock_service, dependent: :destroy @@ -244,7 +246,7 @@ class Project < ActiveRecord::Base end def available_services_names - %w(gitlab_ci campfire hipchat pivotaltracker flowdock assembla) + %w(gitlab_ci campfire hipchat pivotaltracker flowdock assembla emails_on_push) end def gitlab_ci? diff --git a/app/models/project_services/emails_on_push_service.rb b/app/models/project_services/emails_on_push_service.rb new file mode 100644 index 00000000000..c01748a81b0 --- /dev/null +++ b/app/models/project_services/emails_on_push_service.rb @@ -0,0 +1,45 @@ +# == Schema Information +# +# Table name: services +# +# id :integer not null, primary key +# type :string(255) +# title :string(255) +# token :string(255) +# project_id :integer not null +# created_at :datetime not null +# updated_at :datetime not null +# active :boolean default(FALSE), not null +# project_url :string(255) +# subdomain :string(255) +# room :string(255) +# + +class EmailsOnPushService < Service + attr_accessible :recipients + + validates :recipients, presence: true, if: :activated? + + def title + 'Emails on push' + end + + def description + 'Send emails to recipients on push' + end + + def to_param + 'emails_on_push' + end + + def execute + true + end + + def fields + [ + { type: 'textarea', name: 'recipients', placeholder: 'Recipients' }, + ] + end +end + diff --git a/db/migrate/20131217102743_add_recipients_to_service.rb b/db/migrate/20131217102743_add_recipients_to_service.rb new file mode 100644 index 00000000000..9695c251352 --- /dev/null +++ b/db/migrate/20131217102743_add_recipients_to_service.rb @@ -0,0 +1,5 @@ +class AddRecipientsToService < ActiveRecord::Migration + def change + add_column :services, :recipients, :text + end +end diff --git a/db/schema.rb b/db/schema.rb index 77d245913e2..f6a2bc0ebc3 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,7 +11,10 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 20131214224427) do +ActiveRecord::Schema.define(version: 20131217102743) do + + # These are extensions that must be enabled in order to support this database + enable_extension "plpgsql" create_table "broadcast_messages", force: true do |t| t.text "message", null: false @@ -94,20 +97,20 @@ ActiveRecord::Schema.define(version: 20131214224427) do add_index "keys", ["user_id"], name: "index_keys_on_user_id", using: :btree create_table "merge_requests", force: true do |t| - t.string "target_branch", null: false - t.string "source_branch", null: false - t.integer "source_project_id", null: false + t.string "target_branch", null: false + t.string "source_branch", null: false + t.integer "source_project_id", null: false t.integer "author_id" t.integer "assignee_id" t.string "title" - t.datetime "created_at", null: false - t.datetime "updated_at", null: false - t.text "st_commits", limit: 2147483647 - t.text "st_diffs", limit: 2147483647 + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + t.text "st_commits" + t.text "st_diffs" t.integer "milestone_id" t.string "state" t.string "merge_status" - t.integer "target_project_id", null: false + t.integer "target_project_id", null: false t.integer "iid" t.text "description" end @@ -219,20 +222,21 @@ ActiveRecord::Schema.define(version: 20131214224427) do t.string "project_url" t.string "subdomain" t.string "room" + t.text "recipients" end add_index "services", ["project_id"], name: "index_services_on_project_id", using: :btree create_table "snippets", force: true do |t| t.string "title" - t.text "content", limit: 2147483647 - t.integer "author_id", null: false + t.text "content" + t.integer "author_id", null: false t.integer "project_id" - t.datetime "created_at", null: false - t.datetime "updated_at", null: false + t.datetime "created_at", null: false + t.datetime "updated_at", null: false t.string "file_name" t.datetime "expires_at" - t.boolean "private", default: true, null: false + t.boolean "private", default: true, null: false t.string "type" end -- GitLab From 2428a0b2dd8e84e285df4b356ee6f1593204cd34 Mon Sep 17 00:00:00 2001 From: Dmitriy Zaporozhets Date: Tue, 17 Dec 2013 12:58:44 +0200 Subject: [PATCH 04/12] Add project_services dir to autoload path Signed-off-by: Dmitriy Zaporozhets --- app/models/project.rb | 8 -------- app/models/project_services/emails_on_push_service.rb | 2 +- app/views/projects/services/_form.html.haml | 2 +- config/application.rb | 2 +- 4 files changed, 3 insertions(+), 11 deletions(-) diff --git a/app/models/project.rb b/app/models/project.rb index d55714662b2..51f7e949535 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -23,14 +23,6 @@ # visibility_level :integer default(0), not null # -require_relative "project_services/assembla_service" -require_relative "project_services/campfire_service" -require_relative "project_services/emails_on_push_service" -require_relative "project_services/flowdock_service" -require_relative "project_services/gitlab_ci_service" -require_relative "project_services/hipchat_service" -require_relative "project_services/pivotaltracker_service" - class Project < ActiveRecord::Base include Gitlab::ShellAdapter include Gitlab::VisibilityLevel diff --git a/app/models/project_services/emails_on_push_service.rb b/app/models/project_services/emails_on_push_service.rb index c01748a81b0..5ead0f2b730 100644 --- a/app/models/project_services/emails_on_push_service.rb +++ b/app/models/project_services/emails_on_push_service.rb @@ -38,7 +38,7 @@ class EmailsOnPushService < Service def fields [ - { type: 'textarea', name: 'recipients', placeholder: 'Recipients' }, + { type: 'textarea', name: 'recipients', placeholder: 'Emails separated by whitespace' }, ] end end diff --git a/app/views/projects/services/_form.html.haml b/app/views/projects/services/_form.html.haml index e220d6a3185..2e2e5f41dd8 100644 --- a/app/views/projects/services/_form.html.haml +++ b/app/views/projects/services/_form.html.haml @@ -34,7 +34,7 @@ - if type == 'text' = f.text_field name, class: "input-xlarge", placeholder: placeholder - elsif type == 'textarea' - = f.textarea name, rows: 5 + = f.text_area name, rows: 5, class: "input-xlarge", placeholder: placeholder - elsif type == 'checkbox' = f.check_box name diff --git a/config/application.rb b/config/application.rb index dec1940a4a3..1c91134f524 100644 --- a/config/application.rb +++ b/config/application.rb @@ -12,7 +12,7 @@ module Gitlab # -- all .rb files in that directory are automatically loaded. # Custom directories with classes and modules you want to be autoloadable. - config.autoload_paths += %W(#{config.root}/lib #{config.root}/app/models/concerns) + config.autoload_paths += %W(#{config.root}/lib #{config.root}/app/models/concerns #{config.root}/app/models/project_services) # Only load the plugins named here, in the order given (default is alphabetical). # :all can be used as a placeholder for all plugins not explicitly named. -- GitLab From d550933907a51aa6cf5ed8b042db2f7e3323fa8c Mon Sep 17 00:00:00 2001 From: Dmitriy Zaporozhets Date: Tue, 17 Dec 2013 14:45:55 +0200 Subject: [PATCH 05/12] Add new method to mailer for deliver emails with push info Signed-off-by: Dmitriy Zaporozhets --- app/mailers/emails/projects.rb | 10 ++++++++++ .../project_services/emails_on_push_service.rb | 12 ++++++++++-- app/views/projects/services/_form.html.haml | 2 +- 3 files changed, 21 insertions(+), 3 deletions(-) diff --git a/app/mailers/emails/projects.rb b/app/mailers/emails/projects.rb index 0e40450bfee..beecf15399c 100644 --- a/app/mailers/emails/projects.rb +++ b/app/mailers/emails/projects.rb @@ -13,5 +13,15 @@ module Emails mail(to: @user.email, subject: subject("Project was moved")) end + + def repository_push_email(project_id, recipient, branch, compare) + @project = Project.find project_id + @commits = compare.commits + @commit = compare.commit + @diffs = compare.diffs + @branch = branch + + mail(to: recipient, subject: subject("New push to repository")) + end end end diff --git a/app/models/project_services/emails_on_push_service.rb b/app/models/project_services/emails_on_push_service.rb index 5ead0f2b730..1d4828fe720 100644 --- a/app/models/project_services/emails_on_push_service.rb +++ b/app/models/project_services/emails_on_push_service.rb @@ -32,8 +32,16 @@ class EmailsOnPushService < Service 'emails_on_push' end - def execute - true + def execute(push_data) + before_sha = push_data[:before] + after_sha = push_data[:after] + branch = push_data[:ref] + + compare = Gitlab::Git::Compare.new(project.repository.raw_repository, before_sha, after_sha) + + recipients.split(" ").each do |recipient| + Notify.delay.repository_push_email(project_id, recipient, branch, compare) + end end def fields diff --git a/app/views/projects/services/_form.html.haml b/app/views/projects/services/_form.html.haml index 2e2e5f41dd8..34ba55fc4cd 100644 --- a/app/views/projects/services/_form.html.haml +++ b/app/views/projects/services/_form.html.haml @@ -34,7 +34,7 @@ - if type == 'text' = f.text_field name, class: "input-xlarge", placeholder: placeholder - elsif type == 'textarea' - = f.text_area name, rows: 5, class: "input-xlarge", placeholder: placeholder + = f.text_area name, rows: 5, class: "input-xxlarge", placeholder: placeholder - elsif type == 'checkbox' = f.check_box name -- GitLab From 0b59af49cb80a27ac188532c8de2bfec8a1c1d8b Mon Sep 17 00:00:00 2001 From: Dmitriy Zaporozhets Date: Tue, 17 Dec 2013 14:50:19 +0200 Subject: [PATCH 06/12] Fix db schema Signed-off-by: Dmitriy Zaporozhets --- db/schema.rb | 29 +++++++++++++---------------- 1 file changed, 13 insertions(+), 16 deletions(-) diff --git a/db/schema.rb b/db/schema.rb index f6a2bc0ebc3..cda5c3cf946 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -13,9 +13,6 @@ ActiveRecord::Schema.define(version: 20131217102743) do - # These are extensions that must be enabled in order to support this database - enable_extension "plpgsql" - create_table "broadcast_messages", force: true do |t| t.text "message", null: false t.datetime "starts_at" @@ -97,20 +94,20 @@ ActiveRecord::Schema.define(version: 20131217102743) do add_index "keys", ["user_id"], name: "index_keys_on_user_id", using: :btree create_table "merge_requests", force: true do |t| - t.string "target_branch", null: false - t.string "source_branch", null: false - t.integer "source_project_id", null: false + t.string "target_branch", null: false + t.string "source_branch", null: false + t.integer "source_project_id", null: false t.integer "author_id" t.integer "assignee_id" t.string "title" - t.datetime "created_at", null: false - t.datetime "updated_at", null: false - t.text "st_commits" - t.text "st_diffs" + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + t.text "st_commits", limit: 2147483647 + t.text "st_diffs", limit: 2147483647 t.integer "milestone_id" t.string "state" t.string "merge_status" - t.integer "target_project_id", null: false + t.integer "target_project_id", null: false t.integer "iid" t.text "description" end @@ -229,14 +226,14 @@ ActiveRecord::Schema.define(version: 20131217102743) do create_table "snippets", force: true do |t| t.string "title" - t.text "content" - t.integer "author_id", null: false + t.text "content", limit: 2147483647 + t.integer "author_id", null: false t.integer "project_id" - t.datetime "created_at", null: false - t.datetime "updated_at", null: false + t.datetime "created_at", null: false + t.datetime "updated_at", null: false t.string "file_name" t.datetime "expires_at" - t.boolean "private", default: true, null: false + t.boolean "private", default: true, null: false t.string "type" end -- GitLab From 8b89ef8639b2b6ee69d991fb0d6089f9437bbee2 Mon Sep 17 00:00:00 2001 From: Dmitriy Zaporozhets Date: Tue, 17 Dec 2013 15:30:15 +0200 Subject: [PATCH 07/12] Add templates for Emails on push Signed-off-by: Dmitriy Zaporozhets --- app/mailers/emails/projects.rb | 2 +- .../notify/repository_push_email.html.haml | 23 +++++++++++++++++++ .../notify/repository_push_email.text.haml | 20 ++++++++++++++++ 3 files changed, 44 insertions(+), 1 deletion(-) create mode 100644 app/views/notify/repository_push_email.html.haml create mode 100644 app/views/notify/repository_push_email.text.haml diff --git a/app/mailers/emails/projects.rb b/app/mailers/emails/projects.rb index beecf15399c..809ce323958 100644 --- a/app/mailers/emails/projects.rb +++ b/app/mailers/emails/projects.rb @@ -16,7 +16,7 @@ module Emails def repository_push_email(project_id, recipient, branch, compare) @project = Project.find project_id - @commits = compare.commits + @commits = Commit.decorate compare.commits @commit = compare.commit @diffs = compare.diffs @branch = branch diff --git a/app/views/notify/repository_push_email.html.haml b/app/views/notify/repository_push_email.html.haml new file mode 100644 index 00000000000..48c3b3277bf --- /dev/null +++ b/app/views/notify/repository_push_email.html.haml @@ -0,0 +1,23 @@ +%h3 New push to #{@branch} at #{@project.name_with_namespace} + +%h4 Commits: + +%ul + - @commits.each do |commit| + %li + #{commit.short_id} - #{commit.title} + +%h4 Diff: +- @diffs.each do |diff| + %li + %strong + - if diff.old_path == diff.new_path + = diff.new_path + - elsif diff.new_path && diff.old_path + #{diff.old_path} → #{diff.new_path} + - else + = diff.new_path || diff.old_path + %hr + %pre + = diff.diff + %br diff --git a/app/views/notify/repository_push_email.text.haml b/app/views/notify/repository_push_email.text.haml new file mode 100644 index 00000000000..0da5b9513ee --- /dev/null +++ b/app/views/notify/repository_push_email.text.haml @@ -0,0 +1,20 @@ +New push to #{@branch} at #{@project.name_with_namespace} + +\ +Commits: +- @commits.each do |commit| + #{commit.short_id} - #{truncate(commit.title, length: 40)} +\ +\ +Diff: +- @diffs.each do |diff| + \ + \===================================== + - if diff.old_path == diff.new_path + = diff.new_path + - elsif diff.new_path && diff.old_path + #{diff.old_path} → #{diff.new_path} + - else + = diff.new_path || diff.old_path + \===================================== + = diff.diff -- GitLab From 074efd8fd57736bcec25b2f08324b9d25aa886d5 Mon Sep 17 00:00:00 2001 From: Dmitriy Zaporozhets Date: Tue, 17 Dec 2013 16:20:45 +0200 Subject: [PATCH 08/12] Email on push: dont send email if new branch was pushed or branch was removed Signed-off-by: Dmitriy Zaporozhets --- app/mailers/emails/projects.rb | 8 ++++---- app/models/project_services/emails_on_push_service.rb | 11 ++++++++++- app/views/notify/repository_push_email.html.haml | 2 +- app/views/notify/repository_push_email.text.haml | 2 +- 4 files changed, 16 insertions(+), 7 deletions(-) diff --git a/app/mailers/emails/projects.rb b/app/mailers/emails/projects.rb index 809ce323958..df21d7b5b02 100644 --- a/app/mailers/emails/projects.rb +++ b/app/mailers/emails/projects.rb @@ -14,10 +14,10 @@ module Emails subject: subject("Project was moved")) end - def repository_push_email(project_id, recipient, branch, compare) - @project = Project.find project_id - @commits = Commit.decorate compare.commits - @commit = compare.commit + def repository_push_email(project_id, recipient, author_id, branch, compare) + @project = Project.find(project_id) + @author = User.find(author_id) + @commits = Commit.decorate(compare.commits) @diffs = compare.diffs @branch = branch diff --git a/app/models/project_services/emails_on_push_service.rb b/app/models/project_services/emails_on_push_service.rb index 1d4828fe720..8df7313f987 100644 --- a/app/models/project_services/emails_on_push_service.rb +++ b/app/models/project_services/emails_on_push_service.rb @@ -36,11 +36,20 @@ class EmailsOnPushService < Service before_sha = push_data[:before] after_sha = push_data[:after] branch = push_data[:ref] + author_id = push_data[:user_id] + + if before_sha =~ /^000000/ || after_sha =~ /^000000/ + # skip if new branch was pushed or branch was removed + return true + end compare = Gitlab::Git::Compare.new(project.repository.raw_repository, before_sha, after_sha) + # Do not send emails if git compare failed + return false unless compare && compare.commits.present? + recipients.split(" ").each do |recipient| - Notify.delay.repository_push_email(project_id, recipient, branch, compare) + Notify.delay.repository_push_email(project_id, recipient, author_id, branch, compare) end end diff --git a/app/views/notify/repository_push_email.html.haml b/app/views/notify/repository_push_email.html.haml index 48c3b3277bf..d0b30c08338 100644 --- a/app/views/notify/repository_push_email.html.haml +++ b/app/views/notify/repository_push_email.html.haml @@ -1,4 +1,4 @@ -%h3 New push to #{@branch} at #{@project.name_with_namespace} +%h3 #{@author.name} pushed to #{@branch} at #{@project.name_with_namespace} %h4 Commits: diff --git a/app/views/notify/repository_push_email.text.haml b/app/views/notify/repository_push_email.text.haml index 0da5b9513ee..6718ca68359 100644 --- a/app/views/notify/repository_push_email.text.haml +++ b/app/views/notify/repository_push_email.text.haml @@ -1,4 +1,4 @@ -New push to #{@branch} at #{@project.name_with_namespace} +#{@author.name} pushed to #{@branch} at #{@project.name_with_namespace} \ Commits: -- GitLab From 68f8ffb55164a97bae4efec30646ee6cb0036f5a Mon Sep 17 00:00:00 2001 From: Dmitriy Zaporozhets Date: Tue, 17 Dec 2013 16:29:08 +0200 Subject: [PATCH 09/12] Add spinach tests for email on push service Signed-off-by: Dmitriy Zaporozhets --- features/project/service.feature | 8 +++- features/steps/project/project_services.rb | 47 ++++++++++++++-------- 2 files changed, 37 insertions(+), 18 deletions(-) diff --git a/features/project/service.feature b/features/project/service.feature index f8684f3b3b7..46b983e8f9a 100644 --- a/features/project/service.feature +++ b/features/project/service.feature @@ -35,4 +35,10 @@ Feature: Project Services When I visit project "Shop" services page And I click Assembla service link And I fill Assembla settings - Then I should see Assembla service settings saved \ No newline at end of file + Then I should see Assembla service settings saved + + Scenario: Activate email on push service + When I visit project "Shop" services page + And I click email on push service link + And I fill email on push settings + Then I should see email on push service settings saved diff --git a/features/steps/project/project_services.rb b/features/steps/project/project_services.rb index 2f248090831..549968dce55 100644 --- a/features/steps/project/project_services.rb +++ b/features/steps/project/project_services.rb @@ -3,11 +3,11 @@ class ProjectServices < Spinach::FeatureSteps include SharedProject include SharedPaths - When 'I visit project "Shop" services page' do + step 'I visit project "Shop" services page' do visit project_services_path(@project) end - Then 'I should see list of available services' do + step 'I should see list of available services' do page.should have_content 'Services' page.should have_content 'Campfire' page.should have_content 'Hipchat' @@ -15,76 +15,89 @@ class ProjectServices < Spinach::FeatureSteps page.should have_content 'Assembla' end - And 'I click gitlab-ci service link' do + step 'I click gitlab-ci service link' do click_link 'GitLab CI' end - And 'I fill gitlab-ci settings' do + step 'I fill gitlab-ci settings' do check 'Active' fill_in 'Project url', with: 'http://ci.gitlab.org/projects/3' fill_in 'Token', with: 'verySecret' click_button 'Save' end - Then 'I should see service settings saved' do + step 'I should see service settings saved' do find_field('Project url').value.should == 'http://ci.gitlab.org/projects/3' end - And 'I click hipchat service link' do + step 'I click hipchat service link' do click_link 'Hipchat' end - And 'I fill hipchat settings' do + step 'I fill hipchat settings' do check 'Active' fill_in 'Room', with: 'gitlab' fill_in 'Token', with: 'verySecret' click_button 'Save' end - Then 'I should see hipchat service settings saved' do + step 'I should see hipchat service settings saved' do find_field('Room').value.should == 'gitlab' end - And 'I click pivotaltracker service link' do + step 'I click pivotaltracker service link' do click_link 'PivotalTracker' end - And 'I fill pivotaltracker settings' do + step 'I fill pivotaltracker settings' do check 'Active' fill_in 'Token', with: 'verySecret' click_button 'Save' end - Then 'I should see pivotaltracker service settings saved' do + step 'I should see pivotaltracker service settings saved' do find_field('Token').value.should == 'verySecret' end - And 'I click Flowdock service link' do + step 'I click Flowdock service link' do click_link 'Flowdock' end - And 'I fill Flowdock settings' do + step 'I fill Flowdock settings' do check 'Active' fill_in 'Token', with: 'verySecret' click_button 'Save' end - Then 'I should see Flowdock service settings saved' do + step 'I should see Flowdock service settings saved' do find_field('Token').value.should == 'verySecret' end - And 'I click Assembla service link' do + step 'I click Assembla service link' do click_link 'Assembla' end - And 'I fill Assembla settings' do + step 'I fill Assembla settings' do check 'Active' fill_in 'Token', with: 'verySecret' click_button 'Save' end - Then 'I should see Assembla service settings saved' do + step 'I should see Assembla service settings saved' do find_field('Token').value.should == 'verySecret' end + + step 'I click email on push service link' do + click_link 'Emails on push' + end + + step 'I fill email on push settings' do + fill_in 'Recipients', with: 'qa@company.name' + click_button 'Save' + end + + step 'I should see email on push service settings saved' do + find_field('Recipients').value.should == 'qa@company.name' + end end -- GitLab From 5f85d6d1cea2e9f3557206b97cef15676ea2d14c Mon Sep 17 00:00:00 2001 From: Dmitriy Zaporozhets Date: Tue, 17 Dec 2013 16:31:12 +0200 Subject: [PATCH 10/12] Better description to EmailsOnPush service Signed-off-by: Dmitriy Zaporozhets --- app/models/project_services/emails_on_push_service.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/models/project_services/emails_on_push_service.rb b/app/models/project_services/emails_on_push_service.rb index 8df7313f987..73458098400 100644 --- a/app/models/project_services/emails_on_push_service.rb +++ b/app/models/project_services/emails_on_push_service.rb @@ -25,7 +25,7 @@ class EmailsOnPushService < Service end def description - 'Send emails to recipients on push' + 'Email the commits and diff of each push to a list of recipients.' end def to_param -- GitLab From fc3878c03461a1b75a30332756544b2e10b77917 Mon Sep 17 00:00:00 2001 From: Dmitriy Zaporozhets Date: Wed, 18 Dec 2013 13:30:04 +0200 Subject: [PATCH 11/12] Email on push mailer spec Signed-off-by: Dmitriy Zaporozhets --- spec/mailers/notify_spec.rb | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/spec/mailers/notify_spec.rb b/spec/mailers/notify_spec.rb index d287239cfe3..b1e53486816 100644 --- a/spec/mailers/notify_spec.rb +++ b/spec/mailers/notify_spec.rb @@ -391,4 +391,28 @@ describe Notify do should have_body_text /#{example_site_path}/ end end + + describe 'email on push' do + let(:example_site_path) { root_path } + let(:user) { create(:user) } + let(:compare) { Gitlab::Git::Compare.new(project.repository.raw_repository, 'cd5c4bac', 'b1e6a9db') } + + subject { Notify.repository_push_email(project.id, 'devs@company.name', user.id, 'master', compare) } + + it 'is sent to recipient' do + should deliver_to 'devs@company.name' + end + + it 'has the correct subject' do + should have_subject /New push to repository/ + end + + it 'includes commits list' do + should have_body_text /tree css fixes/ + end + + it 'includes diffs' do + should have_body_text /Checkout wiki pages for installation information/ + end + end end -- GitLab From 6ac73f45f0d88b4a7fded64260a8d6ea1cff7400 Mon Sep 17 00:00:00 2001 From: Dmitriy Zaporozhets Date: Wed, 18 Dec 2013 13:42:12 +0200 Subject: [PATCH 12/12] Move EmailOnPush logic to async worker Signed-off-by: Dmitriy Zaporozhets --- .../emails_on_push_service.rb | 20 +-------------- app/workers/emails_on_push_worker.rb | 25 +++++++++++++++++++ 2 files changed, 26 insertions(+), 19 deletions(-) create mode 100644 app/workers/emails_on_push_worker.rb diff --git a/app/models/project_services/emails_on_push_service.rb b/app/models/project_services/emails_on_push_service.rb index 73458098400..2a46eff7846 100644 --- a/app/models/project_services/emails_on_push_service.rb +++ b/app/models/project_services/emails_on_push_service.rb @@ -33,24 +33,7 @@ class EmailsOnPushService < Service end def execute(push_data) - before_sha = push_data[:before] - after_sha = push_data[:after] - branch = push_data[:ref] - author_id = push_data[:user_id] - - if before_sha =~ /^000000/ || after_sha =~ /^000000/ - # skip if new branch was pushed or branch was removed - return true - end - - compare = Gitlab::Git::Compare.new(project.repository.raw_repository, before_sha, after_sha) - - # Do not send emails if git compare failed - return false unless compare && compare.commits.present? - - recipients.split(" ").each do |recipient| - Notify.delay.repository_push_email(project_id, recipient, author_id, branch, compare) - end + EmailsOnPushWorker.perform_async(project_id, recipients, push_data) end def fields @@ -59,4 +42,3 @@ class EmailsOnPushService < Service ] end end - diff --git a/app/workers/emails_on_push_worker.rb b/app/workers/emails_on_push_worker.rb new file mode 100644 index 00000000000..9982b362a10 --- /dev/null +++ b/app/workers/emails_on_push_worker.rb @@ -0,0 +1,25 @@ +class EmailsOnPushWorker + include Sidekiq::Worker + + def perform(project_id, recipients, push_data) + project = Project.find(project_id) + before_sha = push_data["before"] + after_sha = push_data["after"] + branch = push_data["ref"] + author_id = push_data["user_id"] + + if before_sha =~ /^000000/ || after_sha =~ /^000000/ + # skip if new branch was pushed or branch was removed + return true + end + + compare = Gitlab::Git::Compare.new(project.repository.raw_repository, before_sha, after_sha) + + # Do not send emails if git compare failed + return false unless compare && compare.commits.present? + + recipients.split(" ").each do |recipient| + Notify.delay.repository_push_email(project_id, recipient, author_id, branch, compare) + end + end +end -- GitLab