Commit d5264e88 authored by Lin Jen-Shin's avatar Lin Jen-Shin
parent 0a20897b
...@@ -343,7 +343,7 @@ module Ci ...@@ -343,7 +343,7 @@ module Ci
def execute_hooks def execute_hooks
return unless project return unless project
build_data = Gitlab::DataBuilder::BuildDataBuilder.build(self) build_data = Gitlab::DataBuilder::Build.build(self)
project.execute_hooks(build_data.dup, :build_hooks) project.execute_hooks(build_data.dup, :build_hooks)
project.execute_services(build_data.dup, :build_hooks) project.execute_services(build_data.dup, :build_hooks)
project.running_or_pending_build_count(force: true) project.running_or_pending_build_count(force: true)
......
...@@ -222,7 +222,7 @@ module Ci ...@@ -222,7 +222,7 @@ module Ci
end end
def pipeline_data def pipeline_data
Gitlab::DataBuilder::PipelineDataBuilder.build(self) Gitlab::DataBuilder::Pipeline.build(self)
end end
def keep_around_commits def keep_around_commits
......
...@@ -51,8 +51,7 @@ class BuildsEmailService < Service ...@@ -51,8 +51,7 @@ class BuildsEmailService < Service
end end
def test_data(project = nil, user = nil) def test_data(project = nil, user = nil)
build = project.builds.last Gitlab::DataBuilder::Build.build(project.builds.last)
Gitlab::DataBuilder::BuildDataBuilder.build(build)
end end
def fields def fields
......
...@@ -80,7 +80,7 @@ class Service < ActiveRecord::Base ...@@ -80,7 +80,7 @@ class Service < ActiveRecord::Base
end end
def test_data(project, user) def test_data(project, user)
Gitlab::DataBuilder::PushDataBuilder.build_sample(project, user) Gitlab::DataBuilder::Push.build_sample(project, user)
end end
def event_channel_names def event_channel_names
......
...@@ -39,7 +39,12 @@ class DeleteBranchService < BaseService ...@@ -39,7 +39,12 @@ class DeleteBranchService < BaseService
end end
def build_push_data(branch) def build_push_data(branch)
Gitlab::DataBuilder::PushDataBuilder Gitlab::DataBuilder::Push.build(
.build(project, current_user, branch.target.sha, Gitlab::Git::BLANK_SHA, "#{Gitlab::Git::BRANCH_REF_PREFIX}#{branch.name}", []) project,
current_user,
branch.target.sha,
Gitlab::Git::BLANK_SHA,
"#{Gitlab::Git::BRANCH_REF_PREFIX}#{branch.name}",
[])
end end
end end
...@@ -33,7 +33,12 @@ class DeleteTagService < BaseService ...@@ -33,7 +33,12 @@ class DeleteTagService < BaseService
end end
def build_push_data(tag) def build_push_data(tag)
Gitlab::DataBuilder::PushDataBuilder Gitlab::DataBuilder::Push.build(
.build(project, current_user, tag.target.sha, Gitlab::Git::BLANK_SHA, "#{Gitlab::Git::TAG_REF_PREFIX}#{tag.name}", []) project,
current_user,
tag.target.sha,
Gitlab::Git::BLANK_SHA,
"#{Gitlab::Git::TAG_REF_PREFIX}#{tag.name}",
[])
end end
end end
...@@ -138,13 +138,23 @@ class GitPushService < BaseService ...@@ -138,13 +138,23 @@ class GitPushService < BaseService
end end
def build_push_data def build_push_data
@push_data ||= Gitlab::DataBuilder::PushDataBuilder. @push_data ||= Gitlab::DataBuilder::Push.build(
build(@project, current_user, params[:oldrev], params[:newrev], params[:ref], push_commits) @project,
current_user,
params[:oldrev],
params[:newrev],
params[:ref],
push_commits)
end end
def build_push_data_system_hook def build_push_data_system_hook
@push_data_system ||= Gitlab::DataBuilder::PushDataBuilder. @push_data_system ||= Gitlab::DataBuilder::Push.build(
build(@project, current_user, params[:oldrev], params[:newrev], params[:ref], []) @project,
current_user,
params[:oldrev],
params[:newrev],
params[:ref],
[])
end end
def push_to_existing_branch? def push_to_existing_branch?
......
...@@ -34,12 +34,24 @@ class GitTagPushService < BaseService ...@@ -34,12 +34,24 @@ class GitTagPushService < BaseService
end end
end end
Gitlab::DataBuilder::PushDataBuilder. Gitlab::DataBuilder::Push.build(
build(project, current_user, params[:oldrev], params[:newrev], params[:ref], commits, message) project,
current_user,
params[:oldrev],
params[:newrev],
params[:ref],
commits,
message)
end end
def build_system_push_data def build_system_push_data
Gitlab::DataBuilder::PushDataBuilder. Gitlab::DataBuilder::Push.build(
build(project, current_user, params[:oldrev], params[:newrev], params[:ref], [], '') project,
current_user,
params[:oldrev],
params[:newrev],
params[:ref],
[],
'')
end end
end end
...@@ -16,7 +16,7 @@ module Notes ...@@ -16,7 +16,7 @@ module Notes
end end
def hook_data def hook_data
Gitlab::DataBuilder::NoteDataBuilder.build(@note, @note.author) Gitlab::DataBuilder::Note.build(@note, @note.author)
end end
def execute_note_hooks def execute_note_hooks
......
class TestHookService class TestHookService
def execute(hook, current_user) def execute(hook, current_user)
data = Gitlab::DataBuilder::PushDataBuilder. data = Gitlab::DataBuilder::Push.build_sample(hook.project, current_user)
build_sample(hook.project, current_user)
hook.execute(data, 'push_hooks') hook.execute(data, 'push_hooks')
end end
end end
module Gitlab module Gitlab
module DataBuilder module DataBuilder
module BuildDataBuilder module Build
extend self extend self
def build(build) def build(build)
......
module Gitlab module Gitlab
module DataBuilder module DataBuilder
module NoteDataBuilder module Note
extend self extend self
# Produce a hash of post-receive data # Produce a hash of post-receive data
......
module Gitlab module Gitlab
module DataBuilder module DataBuilder
module PipelineDataBuilder module Pipeline
extend self extend self
def build(pipeline) def build(pipeline)
......
module Gitlab module Gitlab
module DataBuilder module DataBuilder
module PushDataBuilder module Push
extend self extend self
# Produce a hash of post-receive data # Produce a hash of post-receive data
......
require 'spec_helper' require 'spec_helper'
describe Gitlab::DataBuilder::BuildDataBuilder do describe Gitlab::DataBuilder::Build do
let(:build) { create(:ci_build) } let(:build) { create(:ci_build) }
describe '.build' do describe '.build' do
......
require 'spec_helper' require 'spec_helper'
describe Gitlab::DataBuilder::NoteDataBuilder, lib: true do describe Gitlab::DataBuilder::Note, lib: true do
let(:project) { create(:project) } let(:project) { create(:project) }
let(:user) { create(:user) } let(:user) { create(:user) }
let(:data) { described_class.build(note, user) } let(:data) { described_class.build(note, user) }
......
require 'spec_helper' require 'spec_helper'
describe Gitlab::DataBuilder::PipelineDataBuilder do describe Gitlab::DataBuilder::Pipeline do
let(:user) { create(:user) } let(:user) { create(:user) }
let(:project) { create(:project) } let(:project) { create(:project) }
......
require 'spec_helper' require 'spec_helper'
describe Gitlab::DataBuilder::PushDataBuilder, lib: true do describe Gitlab::DataBuilder::Push, lib: true do
let(:project) { create(:project) } let(:project) { create(:project) }
let(:user) { create(:user) } let(:user) { create(:user) }
......
...@@ -39,8 +39,7 @@ describe AssemblaService, models: true do ...@@ -39,8 +39,7 @@ describe AssemblaService, models: true do
token: 'verySecret', token: 'verySecret',
subdomain: 'project_name' subdomain: 'project_name'
) )
@sample_data = Gitlab::DataBuilder::PushDataBuilder. @sample_data = Gitlab::DataBuilder::Push.build_sample(project, user)
build_sample(project, user)
@api_url = 'https://atlas.assembla.com/spaces/project_name/github_tool?secret_key=verySecret' @api_url = 'https://atlas.assembla.com/spaces/project_name/github_tool?secret_key=verySecret'
WebMock.stub_request(:post, @api_url) WebMock.stub_request(:post, @api_url)
end end
......
...@@ -2,7 +2,7 @@ require 'spec_helper' ...@@ -2,7 +2,7 @@ require 'spec_helper'
describe BuildsEmailService do describe BuildsEmailService do
let(:data) do let(:data) do
Gitlab::DataBuilder::BuildDataBuilder.build(create(:ci_build)) Gitlab::DataBuilder::Build.build(create(:ci_build))
end end
describe 'Validations' do describe 'Validations' do
...@@ -41,7 +41,7 @@ describe BuildsEmailService do ...@@ -41,7 +41,7 @@ describe BuildsEmailService do
describe '#test' do describe '#test' do
it 'sends email' do it 'sends email' do
data = Gitlab::DataBuilder::BuildDataBuilder.build(create(:ci_build)) data = Gitlab::DataBuilder::Build.build(create(:ci_build))
subject.recipients = 'test@gitlab.com' subject.recipients = 'test@gitlab.com'
expect(BuildEmailWorker).to receive(:perform_async) expect(BuildEmailWorker).to receive(:perform_async)
...@@ -51,7 +51,7 @@ describe BuildsEmailService do ...@@ -51,7 +51,7 @@ describe BuildsEmailService do
context 'notify only failed builds is true' do context 'notify only failed builds is true' do
it 'sends email' do it 'sends email' do
data = Gitlab::DataBuilder::BuildDataBuilder.build(create(:ci_build)) data = Gitlab::DataBuilder::Build.build(create(:ci_build))
data[:build_status] = "success" data[:build_status] = "success"
subject.recipients = 'test@gitlab.com' subject.recipients = 'test@gitlab.com'
......
...@@ -54,7 +54,7 @@ describe CampfireService, models: true do ...@@ -54,7 +54,7 @@ describe CampfireService, models: true do
subdomain: 'project-name', subdomain: 'project-name',
room: 'test-room' room: 'test-room'
) )
@sample_data = Gitlab::PushDataBuilder.build_sample(project, user) @sample_data = Gitlab::DataBuilder::Push.build_sample(project, user)
@rooms_url = 'https://verySecret:X@project-name.campfirenow.com/rooms.json' @rooms_url = 'https://verySecret:X@project-name.campfirenow.com/rooms.json'
@headers = { 'Content-Type' => 'application/json; charset=utf-8' } @headers = { 'Content-Type' => 'application/json; charset=utf-8' }
end end
......
...@@ -85,7 +85,7 @@ describe DroneCiService, models: true do ...@@ -85,7 +85,7 @@ describe DroneCiService, models: true do
let(:user) { create(:user, username: 'username') } let(:user) { create(:user, username: 'username') }
let(:push_sample_data) do let(:push_sample_data) do
Gitlab::DataBuilder::PushDataBuilder.build_sample(project, user) Gitlab::DataBuilder::Push.build_sample(project, user)
end end
it do it do
......
...@@ -52,8 +52,7 @@ describe FlowdockService, models: true do ...@@ -52,8 +52,7 @@ describe FlowdockService, models: true do
service_hook: true, service_hook: true,
token: 'verySecret' token: 'verySecret'
) )
@sample_data = Gitlab::DataBuilder::PushDataBuilder. @sample_data = Gitlab::DataBuilder::Push.build_sample(project, user)
build_sample(project, user)
@api_url = 'https://api.flowdock.com/v1/messages' @api_url = 'https://api.flowdock.com/v1/messages'
WebMock.stub_request(:post, @api_url) WebMock.stub_request(:post, @api_url)
end end
......
...@@ -55,8 +55,7 @@ describe GemnasiumService, models: true do ...@@ -55,8 +55,7 @@ describe GemnasiumService, models: true do
token: 'verySecret', token: 'verySecret',
api_key: 'GemnasiumUserApiKey' api_key: 'GemnasiumUserApiKey'
) )
@sample_data = Gitlab::DataBuilder::PushDataBuilder. @sample_data = Gitlab::DataBuilder::Push.build_sample(project, user)
build_sample(project, user)
end end
it "calls Gemnasium service" do it "calls Gemnasium service" do
expect(Gemnasium::GitlabService).to receive(:execute).with(an_instance_of(Hash)).once expect(Gemnasium::GitlabService).to receive(:execute).with(an_instance_of(Hash)).once
......
...@@ -49,7 +49,7 @@ describe HipchatService, models: true do ...@@ -49,7 +49,7 @@ describe HipchatService, models: true do
let(:token) { 'verySecret' } let(:token) { 'verySecret' }
let(:server_url) { 'https://hipchat.example.com'} let(:server_url) { 'https://hipchat.example.com'}
let(:push_sample_data) do let(:push_sample_data) do
Gitlab::DataBuilder::PushDataBuilder.build_sample(project, user) Gitlab::DataBuilder::Push.build_sample(project, user)
end end
before(:each) do before(:each) do
...@@ -111,7 +111,7 @@ describe HipchatService, models: true do ...@@ -111,7 +111,7 @@ describe HipchatService, models: true do
context 'tag_push events' do context 'tag_push events' do
let(:push_sample_data) do let(:push_sample_data) do
Gitlab::DataBuilder::PushDataBuilder.build( Gitlab::DataBuilder::Push.build(
project, project,
user, user,
Gitlab::Git::BLANK_SHA, Gitlab::Git::BLANK_SHA,
...@@ -195,7 +195,7 @@ describe HipchatService, models: true do ...@@ -195,7 +195,7 @@ describe HipchatService, models: true do
end end
it "calls Hipchat API for commit comment events" do it "calls Hipchat API for commit comment events" do
data = Gitlab::DataBuilder::NoteDataBuilder.build(commit_note, user) data = Gitlab::DataBuilder::Note.build(commit_note, user)
hipchat.execute(data) hipchat.execute(data)
expect(WebMock).to have_requested(:post, api_url).once expect(WebMock).to have_requested(:post, api_url).once
...@@ -227,7 +227,7 @@ describe HipchatService, models: true do ...@@ -227,7 +227,7 @@ describe HipchatService, models: true do
end end
it "calls Hipchat API for merge request comment events" do it "calls Hipchat API for merge request comment events" do
data = Gitlab::DataBuilder::NoteDataBuilder.build(merge_request_note, user) data = Gitlab::DataBuilder::Note.build(merge_request_note, user)
hipchat.execute(data) hipchat.execute(data)
expect(WebMock).to have_requested(:post, api_url).once expect(WebMock).to have_requested(:post, api_url).once
...@@ -254,7 +254,7 @@ describe HipchatService, models: true do ...@@ -254,7 +254,7 @@ describe HipchatService, models: true do
end end
it "calls Hipchat API for issue comment events" do it "calls Hipchat API for issue comment events" do
data = Gitlab::DataBuilder::NoteDataBuilder.build(issue_note, user) data = Gitlab::DataBuilder::Note.build(issue_note, user)
hipchat.execute(data) hipchat.execute(data)
message = hipchat.send(:create_message, data) message = hipchat.send(:create_message, data)
...@@ -280,7 +280,7 @@ describe HipchatService, models: true do ...@@ -280,7 +280,7 @@ describe HipchatService, models: true do
end end
it "calls Hipchat API for snippet comment events" do it "calls Hipchat API for snippet comment events" do
data = Gitlab::DataBuilder::NoteDataBuilder.build(snippet_note, user) data = Gitlab::DataBuilder::Note.build(snippet_note, user)
hipchat.execute(data) hipchat.execute(data)
expect(WebMock).to have_requested(:post, api_url).once expect(WebMock).to have_requested(:post, api_url).once
...@@ -303,7 +303,7 @@ describe HipchatService, models: true do ...@@ -303,7 +303,7 @@ describe HipchatService, models: true do
context 'build events' do context 'build events' do
let(:pipeline) { create(:ci_empty_pipeline) } let(:pipeline) { create(:ci_empty_pipeline) }
let(:build) { create(:ci_build, pipeline: pipeline) } let(:build) { create(:ci_build, pipeline: pipeline) }
let(:data) { Gitlab::DataBuilder::BuildDataBuilder.build(build) } let(:data) { Gitlab::DataBuilder::Build.build(build) }
context 'for failed' do context 'for failed' do
before { build.drop } before { build.drop }
......
...@@ -47,7 +47,7 @@ describe IrkerService, models: true do ...@@ -47,7 +47,7 @@ describe IrkerService, models: true do
let(:user) { create(:user) } let(:user) { create(:user) }
let(:project) { create(:project) } let(:project) { create(:project) }
let(:sample_data) do let(:sample_data) do
Gitlab::DataBuilder::PushDataBuilder.build_sample(project, user) Gitlab::DataBuilder::Push.build_sample(project, user)
end end
let(:recipients) { '#commits irc://test.net/#test ftp://bad' } let(:recipients) { '#commits irc://test.net/#test ftp://bad' }
......
...@@ -66,8 +66,7 @@ describe JiraService, models: true do ...@@ -66,8 +66,7 @@ describe JiraService, models: true do
password: 'gitlab_jira_password' password: 'gitlab_jira_password'
) )
@jira_service.save # will build API URL, as api_url was not specified above @jira_service.save # will build API URL, as api_url was not specified above
@sample_data = Gitlab::DataBuilder::PushDataBuilder. @sample_data = Gitlab::DataBuilder::Push.build_sample(project, user)
build_sample(project, user)
# https://github.com/bblimke/webmock#request-with-basic-authentication # https://github.com/bblimke/webmock#request-with-basic-authentication
@api_url = 'http://gitlab_jira_username:gitlab_jira_password@jira.example.com/rest/api/2/issue/JIRA-123/transitions' @api_url = 'http://gitlab_jira_username:gitlab_jira_password@jira.example.com/rest/api/2/issue/JIRA-123/transitions'
@comment_url = 'http://gitlab_jira_username:gitlab_jira_password@jira.example.com/rest/api/2/issue/JIRA-123/comment' @comment_url = 'http://gitlab_jira_username:gitlab_jira_password@jira.example.com/rest/api/2/issue/JIRA-123/comment'
......
...@@ -49,7 +49,7 @@ describe PushoverService, models: true do ...@@ -49,7 +49,7 @@ describe PushoverService, models: true do
let(:user) { create(:user) } let(:user) { create(:user) }
let(:project) { create(:project) } let(:project) { create(:project) }
let(:sample_data) do let(:sample_data) do
Gitlab::DataBuilder::PushDataBuilder.build_sample(project, user) Gitlab::DataBuilder::Push.build_sample(project, user)
end end
let(:api_key) { 'verySecret' } let(:api_key) { 'verySecret' }
......
...@@ -46,7 +46,7 @@ describe SlackService, models: true do ...@@ -46,7 +46,7 @@ describe SlackService, models: true do
let(:user) { create(:user) } let(:user) { create(:user) }
let(:project) { create(:project) } let(:project) { create(:project) }
let(:push_sample_data) do let(:push_sample_data) do
Gitlab::DataBuilder::PushDataBuilder.build_sample(project, user) Gitlab::DataBuilder::Push.build_sample(project, user)
end end
let(:webhook_url) { 'https://hooks.slack.com/services/SVRWFV0VVAR97N/B02R25XN3/ZBqu7xMupaEEICInN685' } let(:webhook_url) { 'https://hooks.slack.com/services/SVRWFV0VVAR97N/B02R25XN3/ZBqu7xMupaEEICInN685' }
let(:username) { 'slack_username' } let(:username) { 'slack_username' }
...@@ -197,8 +197,7 @@ describe SlackService, models: true do ...@@ -197,8 +197,7 @@ describe SlackService, models: true do
it "uses the right channel" do it "uses the right channel" do
slack.update_attributes(note_channel: "random") slack.update_attributes(note_channel: "random")
note_data = Gitlab::DataBuilder::NoteDataBuilder. note_data = Gitlab::DataBuilder::Note.build(issue_note, user)
build(issue_note, user)
expect(Slack::Notifier).to receive(:new). expect(Slack::Notifier).to receive(:new).
with(webhook_url, channel: "random"). with(webhook_url, channel: "random").
...@@ -238,7 +237,7 @@ describe SlackService, models: true do ...@@ -238,7 +237,7 @@ describe SlackService, models: true do
end end
it "calls Slack API for commit comment events" do it "calls Slack API for commit comment events" do
data = Gitlab::DataBuilder::NoteDataBuilder.build(commit_note, user) data = Gitlab::DataBuilder::Note.build(commit_note, user)
slack.execute(data) slack.execute(data)
expect(WebMock).to have_requested(:post, webhook_url).once expect(WebMock).to have_requested(:post, webhook_url).once
...@@ -252,8 +251,7 @@ describe SlackService, models: true do ...@@ -252,8 +251,7 @@ describe SlackService, models: true do
end end
it "calls Slack API for merge request comment events" do it "calls Slack API for merge request comment events" do
data = Gitlab::DataBuilder::NoteDataBuilder. data = Gitlab::DataBuilder::Note.build(merge_request_note, user)
build(merge_request_note, user)
slack.execute(data) slack.execute(data)
expect(WebMock).to have_requested(:post, webhook_url).once expect(WebMock).to have_requested(:post, webhook_url).once
...@@ -266,7 +264,7 @@ describe SlackService, models: true do ...@@ -266,7 +264,7 @@ describe SlackService, models: true do
end end
it "calls Slack API for issue comment events" do it "calls Slack API for issue comment events" do
data = Gitlab::DataBuilder::NoteDataBuilder.build(issue_note, user) data = Gitlab::DataBuilder::Note.build(issue_note, user)
slack.execute(data) slack.execute(data)
expect(WebMock).to have_requested(:post, webhook_url).once expect(WebMock).to have_requested(:post, webhook_url).once
...@@ -280,7 +278,7 @@ describe SlackService, models: true do ...@@ -280,7 +278,7 @@ describe SlackService, models: true do
end end
it "calls Slack API for snippet comment events" do it "calls Slack API for snippet comment events" do
data = Gitlab::DataBuilder::NoteDataBuilder.build(snippet_note, user) data = Gitlab::DataBuilder::Note.build(snippet_note, user)
slack.execute(data) slack.execute(data)
expect(WebMock).to have_requested(:post, webhook_url).once expect(WebMock).to have_requested(:post, webhook_url).once
......
...@@ -896,7 +896,7 @@ describe User, models: true do ...@@ -896,7 +896,7 @@ describe User, models: true do
let!(:project1) { create(:project) } let!(:project1) { create(:project) }
let!(:project2) { create(:project, forked_from_project: project1) } let!(:project2) { create(:project, forked_from_project: project1) }
let!(:push_data) do let!(:push_data) do
Gitlab::DataBuilder::PushDataBuilder.build_sample(project2, subject) Gitlab::DataBuilder::Push.build_sample(project2, subject)
end end
let!(:push_event) { create(:event, action: Event::PUSHED, project: project2, target: project1, author: subject, data: push_data) } let!(:push_event) { create(:event, action: Event::PUSHED, project: project2, target: project1, author: subject, data: push_data) }
......
...@@ -5,7 +5,7 @@ describe BuildEmailWorker do ...@@ -5,7 +5,7 @@ describe BuildEmailWorker do
let(:build) { create(:ci_build) } let(:build) { create(:ci_build) }
let(:user) { create(:user) } let(:user) { create(:user) }
let(:data) { Gitlab::DataBuilder::BuildDataBuilder.build(build) } let(:data) { Gitlab::DataBuilder::Build.build(build) }
subject { BuildEmailWorker.new } subject { BuildEmailWorker.new }
......
...@@ -5,9 +5,7 @@ describe EmailsOnPushWorker do ...@@ -5,9 +5,7 @@ describe EmailsOnPushWorker do
let(:project) { create(:project) } let(:project) { create(:project) }
let(:user) { create(:user) } let(:user) { create(:user) }
let(:data) do let(:data) { Gitlab::DataBuilder::Push.build_sample(project, user) }
Gitlab::DataBuilder::PushDataBuilder.build_sample(project, user)
end
let(:recipients) { user.email } let(:recipients) { user.email }
let(:perform) { subject.perform(project.id, recipients, data.stringify_keys) } let(:perform) { subject.perform(project.id, recipients, data.stringify_keys) }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment