Skip to content

Commit

Permalink
Migrate CI::Services and CI::WebHooks to Services and WebHooks
Browse files Browse the repository at this point in the history
  • Loading branch information
ayufan committed Dec 10, 2015
1 parent 4e5897f commit 2988e1f
Show file tree
Hide file tree
Showing 73 changed files with 602 additions and 1,750 deletions.
1 change: 1 addition & 0 deletions CHANGELOG
Expand Up @@ -16,6 +16,7 @@ v 8.3.0 (unreleased)
- Fire update hook from GitLab
- Style warning about mentioning many people in a comment
- Fix: sort milestones by due date once again (Greg Smethells)
- Migrate all CI::Services and CI::WebHooks to Services and WebHooks
- Don't show project fork event as "imported"
- Add API endpoint to fetch merge request commits list
- Expose events API with comment information and author info
Expand Down
49 changes: 0 additions & 49 deletions app/controllers/projects/ci_services_controller.rb

This file was deleted.

45 changes: 0 additions & 45 deletions app/controllers/projects/ci_web_hooks_controller.rb

This file was deleted.

3 changes: 2 additions & 1 deletion app/controllers/projects/hooks_controller.rb
Expand Up @@ -53,6 +53,7 @@ def hook

def hook_params
params.require(:hook).permit(:url, :push_events, :issues_events,
:merge_requests_events, :tag_push_events, :note_events, :enable_ssl_verification)
:merge_requests_events, :tag_push_events, :note_events,
:build_events, :enable_ssl_verification)
end
end
4 changes: 3 additions & 1 deletion app/controllers/projects/services_controller.rb
Expand Up @@ -6,7 +6,9 @@ class Projects::ServicesController < Projects::ApplicationController
:description, :issues_url, :new_issue_url, :restrict_to_branch, :channel,
:colorize_messages, :channels,
:push_events, :issues_events, :merge_requests_events, :tag_push_events,
:note_events, :send_from_committer_email, :disable_diffs, :external_wiki_url,
:note_events, :build_events,
:notify_only_broken_builds, :add_pusher,
:send_from_committer_email, :disable_diffs, :external_wiki_url,
:notify, :color,
:server_host, :server_port, :default_irc_uri, :enable_ssl_verification]

Expand Down
17 changes: 0 additions & 17 deletions app/mailers/ci/emails/builds.rb

This file was deleted.

46 changes: 0 additions & 46 deletions app/mailers/ci/notify.rb

This file was deleted.

15 changes: 15 additions & 0 deletions app/mailers/emails/builds.rb
@@ -0,0 +1,15 @@
module Emails
module Builds
def build_fail_email(build_id, to)
@build = Ci::Build.find(build_id)
@project = @build.project
mail(to: to, subject: subject("Build failed for #{@project.name}", @build.short_sha))
end

def build_success_email(build_id, to)
@build = Ci::Build.find(build_id)
@project = @build.project
mail(to: to, subject: subject("Build success for #{@project.name}", @build.short_sha))
end
end
end
1 change: 1 addition & 0 deletions app/mailers/notify.rb
Expand Up @@ -7,6 +7,7 @@ class Notify < BaseMailer
include Emails::Projects
include Emails::Profile
include Emails::Groups
include Emails::Builds

add_template_helper MergeRequestsHelper
add_template_helper EmailsHelper
Expand Down
20 changes: 13 additions & 7 deletions app/models/ci/build.rb
Expand Up @@ -96,21 +96,21 @@ def retry(build)
end

state_machine :status, initial: :pending do
after_transition pending: :running do |build, transition|
build.execute_hooks
end

after_transition any => [:success, :failed, :canceled] do |build, transition|
return unless build.gl_project

project = build.project

if project.web_hooks?
Ci::WebHookService.new.build_end(build)
end

build.commit.create_next_builds(build)
project.execute_services(build)

if project.coverage_enabled?
build.update_coverage
end

build.commit.create_next_builds(build)
build.execute_hooks
end
end

Expand Down Expand Up @@ -275,6 +275,12 @@ def download_url
end
end

def execute_hooks
build_data = Gitlab::BuildDataBuilder.build(self)
gl_project.execute_hooks(build_data.dup, :build_hooks)
gl_project.execute_services(build_data.dup, :build_hooks)
end

private

def yaml_variables
Expand Down
4 changes: 4 additions & 0 deletions app/models/ci/commit.rb
Expand Up @@ -178,6 +178,10 @@ def duration
duration_array.reduce(:+).to_i
end

def started_at
@started_at ||= statuses.order('started_at ASC').first.try(:started_at)
end

def finished_at
@finished_at ||= statuses.order('finished_at DESC').first.try(:finished_at)
end
Expand Down
41 changes: 0 additions & 41 deletions app/models/ci/project.rb
Expand Up @@ -35,17 +35,10 @@ class Project < ActiveRecord::Base

has_many :runner_projects, dependent: :destroy, class_name: 'Ci::RunnerProject'
has_many :runners, through: :runner_projects, class_name: 'Ci::Runner'
has_many :web_hooks, dependent: :destroy, class_name: 'Ci::WebHook'
has_many :events, dependent: :destroy, class_name: 'Ci::Event'
has_many :variables, dependent: :destroy, class_name: 'Ci::Variable'
has_many :triggers, dependent: :destroy, class_name: 'Ci::Trigger'

# Project services
has_many :services, dependent: :destroy, class_name: 'Ci::Service'
has_one :hip_chat_service, dependent: :destroy, class_name: 'Ci::HipChatService'
has_one :slack_service, dependent: :destroy, class_name: 'Ci::SlackService'
has_one :mail_service, dependent: :destroy, class_name: 'Ci::MailService'

accepts_nested_attributes_for :variables, allow_destroy: true

delegate :name_with_namespace, :path_with_namespace, :web_url, :http_url_to_repo, :ssh_url_to_repo, to: :gl_project
Expand Down Expand Up @@ -122,14 +115,6 @@ def email_notification?
email_add_pusher || email_recipients.present?
end

def web_hooks?
web_hooks.any?
end

def services?
services.any?
end

def timeout_in_minutes
timeout / 60
end
Expand All @@ -151,32 +136,6 @@ def repo_url_with_auth
end
end

def available_services_names
%w(slack mail hip_chat)
end

def build_missing_services
available_services_names.each do |service_name|
service = services.find { |service| service.to_param == service_name }

# If service is available but missing in db
# we should create an instance. Ex `create_gitlab_ci_service`
self.send :"create_#{service_name}_service" if service.nil?
end
end

def execute_services(data)
services.each do |service|

# Call service hook only if it is active
begin
service.execute(data) if service.active && service.can_execute?(data)
rescue => e
logger.error(e)
end
end
end

def setup_finished?
commits.any?
end
Expand Down

0 comments on commit 2988e1f

Please sign in to comment.