diff options
author | Felipe Artur <felipefac@gmail.com> | 2016-07-13 00:19:47 +0300 |
---|---|---|
committer | Felipe Artur <felipefac@gmail.com> | 2016-07-16 02:38:27 +0300 |
commit | 2e9d53586874a83cea7e7d29a49bde1180e15829 (patch) | |
tree | 8118f6c65c9b610f143e34f8b6a1e8f252065ec4 /app | |
parent | 2d96c66d63d480f24fd023fe73bf95e67d5ad257 (diff) |
Allow build email service to be tested
Diffstat (limited to 'app')
-rw-r--r-- | app/controllers/projects/services_controller.rb | 3 | ||||
-rw-r--r-- | app/mailers/emails/builds.rb | 1 | ||||
-rw-r--r-- | app/models/project_services/builds_email_service.rb | 27 | ||||
-rw-r--r-- | app/models/service.rb | 9 | ||||
-rw-r--r-- | app/views/projects/services/_form.html.haml | 2 |
5 files changed, 40 insertions, 2 deletions
diff --git a/app/controllers/projects/services_controller.rb b/app/controllers/projects/services_controller.rb index 739681f4085..1b91882048e 100644 --- a/app/controllers/projects/services_controller.rb +++ b/app/controllers/projects/services_controller.rb @@ -45,8 +45,9 @@ class Projects::ServicesController < Projects::ApplicationController end def test - data = Gitlab::PushDataBuilder.build_sample(project, current_user) + data = @service.test_data(project, current_user) outcome = @service.test(data) + if outcome[:success] message = { notice: 'We sent a request to the provided URL' } else diff --git a/app/mailers/emails/builds.rb b/app/mailers/emails/builds.rb index 2f86d1be576..3853af6201a 100644 --- a/app/mailers/emails/builds.rb +++ b/app/mailers/emails/builds.rb @@ -6,6 +6,7 @@ module Emails add_project_headers add_build_headers('failed') + mail(to: to, subject: subject("Build failed for #{@project.name}", @build.short_sha)) end diff --git a/app/models/project_services/builds_email_service.rb b/app/models/project_services/builds_email_service.rb index 54da4d74fc5..5e166471077 100644 --- a/app/models/project_services/builds_email_service.rb +++ b/app/models/project_services/builds_email_service.rb @@ -42,6 +42,19 @@ class BuildsEmailService < Service end end + def can_test? + project.builds.count > 0 + end + + def disabled_title + "Please setup a build on your repository." + end + + def test_data(project = nil, user = nil) + build = project.builds.last + Gitlab::BuildDataBuilder.build(build) + end + def fields [ { type: 'textarea', name: 'recipients', placeholder: 'Emails separated by comma' }, @@ -50,6 +63,20 @@ class BuildsEmailService < Service ] end + def test(data) + begin + # bypass build status verification when testing + data[:build_status] = "failed" + data[:build_allow_failure] = false + + result = execute(data) + rescue StandardError => error + return { success: false, result: error } + end + + { success: true, result: result } + end + def should_build_be_notified?(data) case data[:build_status] when 'success' diff --git a/app/models/service.rb b/app/models/service.rb index d7a32c28267..5432f8c7ab4 100644 --- a/app/models/service.rb +++ b/app/models/service.rb @@ -76,6 +76,10 @@ class Service < ActiveRecord::Base [] end + def test_data(project, user) + Gitlab::PushDataBuilder.build_sample(project, user) + end + def supported_events %w(push tag_push issue merge_request wiki_page) end @@ -94,6 +98,11 @@ class Service < ActiveRecord::Base !project.empty_repo? end + # reason why service cannot be tested + def disabled_title + "Please setup a project repository." + end + # Provide convenient accessor methods # for each serialized property. # Also keep track of updated properties in a similar way as ActiveModel::Dirty diff --git a/app/views/projects/services/_form.html.haml b/app/views/projects/services/_form.html.haml index 1f13ea28b4e..166dc4a01fc 100644 --- a/app/views/projects/services/_form.html.haml +++ b/app/views/projects/services/_form.html.haml @@ -12,5 +12,5 @@ - if @service.valid? && @service.activated? - disabled = @service.can_test? ? '':'disabled' - = link_to 'Test settings', test_namespace_project_service_path(@project.namespace, @project, @service.to_param), class: "btn #{disabled}" + = link_to 'Test settings', test_namespace_project_service_path(@project.namespace, @project, @service), class: "btn #{disabled}", title: @service.disabled_title = link_to "Cancel", namespace_project_services_path(@project.namespace, @project), class: "btn btn-cancel" |