Skip to content
Snippets Groups Projects
Commit 984367f9 authored by Lin Jen-Shin's avatar Lin Jen-Shin
Browse files

Move those builders to their own namespace, feedback:

parent 80671bf7
No related branches found
No related tags found
No related merge requests found
Showing
with 44 additions and 30 deletions
Loading
Loading
@@ -349,7 +349,7 @@ module Ci
 
def execute_hooks
return unless project
build_data = Gitlab::BuildDataBuilder.build(self)
build_data = Gitlab::DataBuilder::BuildDataBuilder.build(self)
project.execute_hooks(build_data.dup, :build_hooks)
project.execute_services(build_data.dup, :build_hooks)
project.running_or_pending_build_count(force: true)
Loading
Loading
@@ -461,7 +461,7 @@ module Ci
 
def build_attributes_from_config
return {} unless pipeline.config_processor
pipeline.config_processor.build_attributes(name)
end
end
Loading
Loading
Loading
Loading
@@ -52,7 +52,7 @@ class BuildsEmailService < Service
 
def test_data(project = nil, user = nil)
build = project.builds.last
Gitlab::BuildDataBuilder.build(build)
Gitlab::DataBuilder::BuildDataBuilder.build(build)
end
 
def fields
Loading
Loading
Loading
Loading
@@ -80,7 +80,7 @@ class Service < ActiveRecord::Base
end
 
def test_data(project, user)
Gitlab::PushDataBuilder.build_sample(project, user)
Gitlab::DataBuilder::PushDataBuilder.build_sample(project, user)
end
 
def event_channel_names
Loading
Loading
Loading
Loading
@@ -39,7 +39,7 @@ class DeleteBranchService < BaseService
end
 
def build_push_data(branch)
Gitlab::PushDataBuilder
Gitlab::DataBuilder::PushDataBuilder
.build(project, current_user, branch.target.sha, Gitlab::Git::BLANK_SHA, "#{Gitlab::Git::BRANCH_REF_PREFIX}#{branch.name}", [])
end
end
Loading
Loading
@@ -33,7 +33,7 @@ class DeleteTagService < BaseService
end
 
def build_push_data(tag)
Gitlab::PushDataBuilder
Gitlab::DataBuilder::PushDataBuilder
.build(project, current_user, tag.target.sha, Gitlab::Git::BLANK_SHA, "#{Gitlab::Git::TAG_REF_PREFIX}#{tag.name}", [])
end
end
Loading
Loading
@@ -138,12 +138,12 @@ class GitPushService < BaseService
end
 
def build_push_data
@push_data ||= Gitlab::PushDataBuilder.
@push_data ||= Gitlab::DataBuilder::PushDataBuilder.
build(@project, current_user, params[:oldrev], params[:newrev], params[:ref], push_commits)
end
 
def build_push_data_system_hook
@push_data_system ||= Gitlab::PushDataBuilder.
@push_data_system ||= Gitlab::DataBuilder::PushDataBuilder.
build(@project, current_user, params[:oldrev], params[:newrev], params[:ref], [])
end
 
Loading
Loading
Loading
Loading
@@ -34,12 +34,12 @@ class GitTagPushService < BaseService
end
end
 
Gitlab::PushDataBuilder.
Gitlab::DataBuilder::PushDataBuilder.
build(project, current_user, params[:oldrev], params[:newrev], params[:ref], commits, message)
end
 
def build_system_push_data
Gitlab::PushDataBuilder.
Gitlab::DataBuilder::PushDataBuilder.
build(project, current_user, params[:oldrev], params[:newrev], params[:ref], [], '')
end
end
Loading
Loading
@@ -16,7 +16,7 @@ module Notes
end
 
def hook_data
Gitlab::NoteDataBuilder.build(@note, @note.author)
Gitlab::DataBuilder::NoteDataBuilder.build(@note, @note.author)
end
 
def execute_note_hooks
Loading
Loading
class TestHookService
def execute(hook, current_user)
data = Gitlab::PushDataBuilder.build_sample(hook.project, current_user)
data = Gitlab::DataBuilder::PushDataBuilder.
build_sample(hook.project, current_user)
hook.execute(data, 'push_hooks')
end
end
module Gitlab
class BuildDataBuilder
class << self
module DataBuilder
module BuildDataBuilder
module_function
def build(build)
project = build.project
commit = build.pipeline
Loading
Loading
module Gitlab
class NoteDataBuilder
class << self
module DataBuilder
module NoteDataBuilder
module_function
# Produce a hash of post-receive data
#
# For all notes:
Loading
Loading
module Gitlab
class PushDataBuilder
class << self
module DataBuilder
module PushDataBuilder
module_function
# Produce a hash of post-receive data
#
# data = {
Loading
Loading
require 'spec_helper'
 
describe 'Gitlab::BuildDataBuilder' do
describe Gitlab::DataBuilder::BuildDataBuilder do
let(:build) { create(:ci_build) }
 
describe '.build' do
let(:data) do
Gitlab::BuildDataBuilder.build(build)
Gitlab::DataBuilder::BuildDataBuilder.build(build)
end
 
it { expect(data).to be_a(Hash) }
Loading
Loading
require 'spec_helper'
 
describe 'Gitlab::NoteDataBuilder', lib: true do
describe Gitlab::DataBuilder::NoteDataBuilder, lib: true do
let(:project) { create(:project) }
let(:user) { create(:user) }
let(:data) { Gitlab::NoteDataBuilder.build(note, user) }
let(:data) { Gitlab::DataBuilder::NoteDataBuilder.build(note, user) }
let(:fixed_time) { Time.at(1425600000) } # Avoid time precision errors
 
before(:each) do
Loading
Loading
require 'spec_helper'
 
describe Gitlab::PushDataBuilder, lib: true do
describe Gitlab::DataBuilder::PushDataBuilder, lib: true do
let(:project) { create(:project) }
let(:user) { create(:user) }
 
Loading
Loading
Loading
Loading
@@ -39,7 +39,8 @@ describe AssemblaService, models: true do
token: 'verySecret',
subdomain: 'project_name'
)
@sample_data = Gitlab::PushDataBuilder.build_sample(project, user)
@sample_data = Gitlab::DataBuilder::PushDataBuilder.
build_sample(project, user)
@api_url = 'https://atlas.assembla.com/spaces/project_name/github_tool?secret_key=verySecret'
WebMock.stub_request(:post, @api_url)
end
Loading
Loading
require 'spec_helper'
 
describe BuildsEmailService do
let(:data) { Gitlab::BuildDataBuilder.build(create(:ci_build)) }
let(:data) do
Gitlab::DataBuilder::BuildDataBuilder.build(create(:ci_build))
end
 
describe 'Validations' do
context 'when service is active' do
Loading
Loading
@@ -39,7 +41,7 @@ describe BuildsEmailService do
 
describe '#test' do
it 'sends email' do
data = Gitlab::BuildDataBuilder.build(create(:ci_build))
data = Gitlab::DataBuilder::BuildDataBuilder.build(create(:ci_build))
subject.recipients = 'test@gitlab.com'
 
expect(BuildEmailWorker).to receive(:perform_async)
Loading
Loading
@@ -49,7 +51,7 @@ describe BuildsEmailService do
 
context 'notify only failed builds is true' do
it 'sends email' do
data = Gitlab::BuildDataBuilder.build(create(:ci_build))
data = Gitlab::DataBuilder::BuildDataBuilder.build(create(:ci_build))
data[:build_status] = "success"
subject.recipients = 'test@gitlab.com'
 
Loading
Loading
Loading
Loading
@@ -84,7 +84,9 @@ describe DroneCiService, models: true do
include_context :drone_ci_service
 
let(:user) { create(:user, username: 'username') }
let(:push_sample_data) { Gitlab::PushDataBuilder.build_sample(project, user) }
let(:push_sample_data) do
Gitlab::DataBuilder::PushDataBuilder.build_sample(project, user)
end
 
it do
service_hook = double
Loading
Loading
Loading
Loading
@@ -52,7 +52,8 @@ describe FlowdockService, models: true do
service_hook: true,
token: 'verySecret'
)
@sample_data = Gitlab::PushDataBuilder.build_sample(project, user)
@sample_data = Gitlab::DataBuilder::PushDataBuilder.
build_sample(project, user)
@api_url = 'https://api.flowdock.com/v1/messages'
WebMock.stub_request(:post, @api_url)
end
Loading
Loading
Loading
Loading
@@ -55,7 +55,8 @@ describe GemnasiumService, models: true do
token: 'verySecret',
api_key: 'GemnasiumUserApiKey'
)
@sample_data = Gitlab::PushDataBuilder.build_sample(project, user)
@sample_data = Gitlab::DataBuilder::PushDataBuilder.
build_sample(project, user)
end
it "should call Gemnasium service" do
expect(Gemnasium::GitlabService).to receive(:execute).with(an_instance_of(Hash)).once
Loading
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment