diff options
author | Kamil Trzcinski <ayufan@ayufan.eu> | 2015-12-09 16:31:42 +0100 |
---|---|---|
committer | Kamil Trzcinski <ayufan@ayufan.eu> | 2015-12-10 16:04:08 +0100 |
commit | d5c91bb9a601a1a344d94763654f0b0996857497 (patch) | |
tree | eaacc5a25a57c708a428c73cc38b78f4c2c90f13 | |
parent | 2988e1fbf50b3c9e803a9358933e3e969e64dcc3 (diff) | |
download | gitlab-ce-d5c91bb9a601a1a344d94763654f0b0996857497.tar.gz |
Migrate CI WebHooks and Emails to new tables
-rw-r--r-- | app/models/project_services/builds_email_service.rb | 11 | ||||
-rw-r--r-- | app/workers/build_email_worker.rb | 2 | ||||
-rw-r--r-- | db/migrate/20151209144329_migrate_ci_web_hooks.rb | 12 | ||||
-rw-r--r-- | db/migrate/20151209145909_migrate_ci_emails.rb | 16 | ||||
-rw-r--r-- | db/schema.rb | 2 | ||||
-rw-r--r-- | lib/gitlab/database.rb | 18 |
6 files changed, 55 insertions, 6 deletions
diff --git a/app/models/project_services/builds_email_service.rb b/app/models/project_services/builds_email_service.rb index 9c9b5a4d08c..4514f55cf56 100644 --- a/app/models/project_services/builds_email_service.rb +++ b/app/models/project_services/builds_email_service.rb @@ -54,7 +54,7 @@ class BuildsEmailService < Service def fields [ - { type: 'textarea', name: 'recipients', placeholder: 'Emails separated by whitespace' }, + { type: 'textarea', name: 'recipients', placeholder: 'Emails separated by comma' }, { type: 'checkbox', name: 'add_pusher', label: 'Add pusher to recipients list' }, { type: 'checkbox', name: 'notify_only_broken_builds' }, ] @@ -72,10 +72,13 @@ class BuildsEmailService < Service end def all_recipients(data) + all_recipients = [] + all_recipients <<= recipients.split(',') + if add_pusher? && data[:user][:email] - recipients + " #{data[:user][:email]}" - else - recipients + all_recipients << "#{data[:user][:email]}" end + + all_recipients end end diff --git a/app/workers/build_email_worker.rb b/app/workers/build_email_worker.rb index c5c8055bea7..1c7a04a66a8 100644 --- a/app/workers/build_email_worker.rb +++ b/app/workers/build_email_worker.rb @@ -2,7 +2,7 @@ class BuildEmailWorker include Sidekiq::Worker def perform(build_id, recipients, push_data) - recipients.split(' ').each do |recipient| + recipients.each do |recipient| begin case push_data['build_status'] when 'success' diff --git a/db/migrate/20151209144329_migrate_ci_web_hooks.rb b/db/migrate/20151209144329_migrate_ci_web_hooks.rb new file mode 100644 index 00000000000..0293be3f6ce --- /dev/null +++ b/db/migrate/20151209144329_migrate_ci_web_hooks.rb @@ -0,0 +1,12 @@ +class MigrateCiWebHooks < ActiveRecord::Migration + include Gitlab::Database + + def up + execute( + 'INSERT INTO web_hooks (url, project_id, type, created_at, updated_at, push_events, build_events) ' \ + "SELECT ci_web_hooks.url, projects.id, 'ProjectHook', ci_web_hooks.created_at, ci_web_hooks.updated_at, #{false_value}, #{true_value} FROM ci_web_hooks " \ + 'JOIN ci_projects ON ci_web_hooks.project_id = ci_projects.id ' \ + 'JOIN projects ON ci_projects.gitlab_id = projects.id' + ) + end +end diff --git a/db/migrate/20151209145909_migrate_ci_emails.rb b/db/migrate/20151209145909_migrate_ci_emails.rb new file mode 100644 index 00000000000..ebf0e7d264f --- /dev/null +++ b/db/migrate/20151209145909_migrate_ci_emails.rb @@ -0,0 +1,16 @@ +class MigrateCiEmails < ActiveRecord::Migration + include Gitlab::Database + + def up + execute( + 'INSERT INTO services (project_id, type, created_at, updated_at, active, push_events, issues_events, merge_requests_events, tag_push_events, note_events, build_events, properties) ' \ + "SELECT projects.id, 'BuildsEmailService', ci_services.created_at, ci_services.updated_at, #{true_value}, #{false_value}, #{false_value}, #{false_value}, #{false_value}, #{false_value}, #{true_value}, " \ + "CONCAT('{\"notify_only_broken_builds\":\"', ci_projects.email_only_broken_builds, " \ + "'\",\"add_pusher\":\"', ci_projects.email_add_pusher, '\",\"recipients\":\"', ci_projects.email_recipients, '\"}') " \ + 'FROM ci_services ' \ + 'JOIN ci_projects ON ci_services.project_id = ci_projects.id ' \ + 'JOIN projects ON ci_projects.gitlab_id = projects.id ' \ + "WHERE ci_services.type = 'Ci::MailService' AND ci_services.active" + ) + end +end diff --git a/db/schema.rb b/db/schema.rb index 58595f8ae59..50b6650ac40 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,7 +11,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 20151203162134) do +ActiveRecord::Schema.define(version: 20151209145909) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" diff --git a/lib/gitlab/database.rb b/lib/gitlab/database.rb index 71f37f1fef8..de77a6fbff1 100644 --- a/lib/gitlab/database.rb +++ b/lib/gitlab/database.rb @@ -7,5 +7,23 @@ module Gitlab def self.postgresql? ActiveRecord::Base.connection.adapter_name.downcase == 'postgresql' end + + def true_value + case ActiveRecord::Base.connection.adapter_name.downcase + when 'postgresql' + "'t'" + else + 1 + end + end + + def false_value + case ActiveRecord::Base.connection.adapter_name.downcase + when 'postgresql' + "'f'" + else + 0 + end + end end end |