summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKamil Trzcinski <ayufan@ayufan.eu>2015-10-05 10:14:33 +0200
committerKamil Trzcinski <ayufan@ayufan.eu>2015-10-05 10:15:40 +0200
commite3d870d7fc282a1f0a1028996c8b44e5d32b9cbf (patch)
tree578278b2435415d6684073bafea9d08d24fcf17f
parent546a3c6561fbe967cc37ccc3229b71893cd20c34 (diff)
downloadgitlab-ce-e3d870d7fc282a1f0a1028996c8b44e5d32b9cbf.tar.gz
Add user to Ci::Build to have pusher email address
-rw-r--r--app/models/ci/build.rb6
-rw-r--r--app/models/ci/commit.rb4
-rw-r--r--app/models/project_services/gitlab_ci_service.rb2
-rw-r--r--app/models/user.rb1
-rw-r--r--app/services/ci/create_builds_service.rb4
-rw-r--r--app/services/ci/create_commit_service.rb16
-rw-r--r--db/migrate/20151002121400_add_index_for_builds.rb (renamed from db/migrate/20151002121400_add_index_for_build_name.rb)2
-rw-r--r--db/migrate/20151002122929_add_ref_and_tag_to_builds.rb (renamed from db/migrate/20151002122929_add_sha_and_ref_to_builds.rb)3
-rw-r--r--db/migrate/20151002122943_migrate_ref_and_tag_to_build.rb (renamed from db/migrate/20151002122943_migrate_sha_and_ref_to_build.rb)3
-rw-r--r--db/migrate/20151005075649_add_user_id_to_build.rb5
-rw-r--r--lib/ci/api/commits.rb2
-rw-r--r--spec/factories/ci/builds.rb7
-rw-r--r--spec/factories/ci/commits.rb40
13 files changed, 29 insertions, 66 deletions
diff --git a/app/models/ci/build.rb b/app/models/ci/build.rb
index bf3e8915205..bfdc1c7486e 100644
--- a/app/models/ci/build.rb
+++ b/app/models/ci/build.rb
@@ -32,9 +32,9 @@ module Ci
belongs_to :commit, class_name: 'Ci::Commit'
belongs_to :runner, class_name: 'Ci::Runner'
belongs_to :trigger_request, class_name: 'Ci::TriggerRequest'
+ belongs_to :user
serialize :options
- serialize :push_data
validates :commit, presence: true
validates :status, presence: true
@@ -196,8 +196,8 @@ module Ci
def project_recipients
recipients = project.email_recipients.split(' ')
- if project.email_add_pusher? && push_data[:user_email].present?
- recipients << push_data[:user_email]
+ if project.email_add_pusher? && user.present? && user.notification_email.present?
+ recipients << user.notification_email
end
recipients.uniq
diff --git a/app/models/ci/commit.rb b/app/models/ci/commit.rb
index 35134b6628e..3c577e3f081 100644
--- a/app/models/ci/commit.rb
+++ b/app/models/ci/commit.rb
@@ -96,10 +96,10 @@ module Ci
builds_without_retry.group(:stage_idx).select(:stage).last
end
- def create_builds(ref, tag, push_data, trigger_request = nil)
+ def create_builds(ref, tag, user, trigger_request = nil)
return if skip_ci? && trigger_request.blank?
return unless config_processor
- CreateBuildsService.new.execute(self, config_processor, ref, tag, push_data, trigger_request)
+ CreateBuildsService.new.execute(self, config_processor, ref, tag, user, trigger_request)
end
def refs
diff --git a/app/models/project_services/gitlab_ci_service.rb b/app/models/project_services/gitlab_ci_service.rb
index fd108516530..8e2b395494e 100644
--- a/app/models/project_services/gitlab_ci_service.rb
+++ b/app/models/project_services/gitlab_ci_service.rb
@@ -52,7 +52,7 @@ class GitlabCiService < CiService
ci_project = Ci::Project.find_by(gitlab_id: project.id)
if ci_project
- Ci::CreateCommitService.new.execute(ci_project, data)
+ Ci::CreateCommitService.new.execute(ci_project, data, current_user)
end
end
diff --git a/app/models/user.rb b/app/models/user.rb
index 1069f8e3664..c7e3992b6a1 100644
--- a/app/models/user.rb
+++ b/app/models/user.rb
@@ -130,6 +130,7 @@ class User < ActiveRecord::Base
has_many :assigned_merge_requests, dependent: :destroy, foreign_key: :assignee_id, class_name: "MergeRequest"
has_many :oauth_applications, class_name: 'Doorkeeper::Application', as: :owner, dependent: :destroy
has_one :abuse_report, dependent: :destroy
+ has_many :ci_builds, dependent: :nullify, class_name: 'Ci::Build'
#
diff --git a/app/services/ci/create_builds_service.rb b/app/services/ci/create_builds_service.rb
index e9c85410e5c..77a4305071c 100644
--- a/app/services/ci/create_builds_service.rb
+++ b/app/services/ci/create_builds_service.rb
@@ -1,6 +1,6 @@
module Ci
class CreateBuildsService
- def execute(commit, ref, tag, push_data, config_processor, trigger_request)
+ def execute(commit, ref, tag, user, config_processor, trigger_request)
config_processor.stages.any? do |stage|
builds_attrs = config_processor.builds_for_stage_and_ref(stage, ref, tag)
builds_attrs.map do |build_attrs|
@@ -17,7 +17,7 @@ module Ci
trigger_request: trigger_request,
ref: ref,
tag: tag,
- push_data: push_data,
+ user: user,
})
end
end
diff --git a/app/services/ci/create_commit_service.rb b/app/services/ci/create_commit_service.rb
index 9120a82edcd..edbb07580c9 100644
--- a/app/services/ci/create_commit_service.rb
+++ b/app/services/ci/create_commit_service.rb
@@ -1,6 +1,6 @@
module Ci
class CreateCommitService
- def execute(project, params)
+ def execute(project, params, user)
before_sha = params[:before]
sha = params[:checkout_sha] || params[:after]
origin_ref = params[:ref]
@@ -17,21 +17,9 @@ module Ci
end
tag = origin_ref.start_with?('refs/tags/')
- push_data = {
- before: before_sha,
- after: sha,
- ref: ref,
- user_name: params[:user_name],
- user_email: params[:user_email],
- repository: params[:repository],
- commits: params[:commits],
- total_commits_count: params[:total_commits_count],
- ci_yaml_file: params[:ci_yaml_file]
- }
-
commit = project.gl_project.ensure_ci_commit(sha)
commit.update_committed!
- commit.create_builds(ref, tag, push_data)
+ commit.create_builds(ref, tag, user)
commit
end
diff --git a/db/migrate/20151002121400_add_index_for_build_name.rb b/db/migrate/20151002121400_add_index_for_builds.rb
index c6a81d74661..4ffc1363910 100644
--- a/db/migrate/20151002121400_add_index_for_build_name.rb
+++ b/db/migrate/20151002121400_add_index_for_builds.rb
@@ -1,4 +1,4 @@
-class AddIndexForBuildName < ActiveRecord::Migration
+class AddIndexForBuilds < ActiveRecord::Migration
def up
add_index :ci_builds, [:commit_id, :stage_idx, :created_at]
end
diff --git a/db/migrate/20151002122929_add_sha_and_ref_to_builds.rb b/db/migrate/20151002122929_add_ref_and_tag_to_builds.rb
index fc367341f1d..e3d2ac1cea5 100644
--- a/db/migrate/20151002122929_add_sha_and_ref_to_builds.rb
+++ b/db/migrate/20151002122929_add_ref_and_tag_to_builds.rb
@@ -1,7 +1,6 @@
-class AddShaAndRefToBuilds < ActiveRecord::Migration
+class AddRefAndTagToBuilds < ActiveRecord::Migration
def change
add_column :ci_builds, :tag, :boolean
add_column :ci_builds, :ref, :string
- add_column :ci_builds, :push_data, :text
end
end
diff --git a/db/migrate/20151002122943_migrate_sha_and_ref_to_build.rb b/db/migrate/20151002122943_migrate_ref_and_tag_to_build.rb
index b80808946d8..01d7b3f6773 100644
--- a/db/migrate/20151002122943_migrate_sha_and_ref_to_build.rb
+++ b/db/migrate/20151002122943_migrate_ref_and_tag_to_build.rb
@@ -1,7 +1,6 @@
-class MigrateShaAndRefToBuild < ActiveRecord::Migration
+class MigrateRefAndTagToBuild < ActiveRecord::Migration
def change
execute('UPDATE ci_builds SET ref=(SELECT ref FROM ci_commits WHERE ci_commits.id = ci_builds.commit_id) WHERE ref IS NULL')
- execute('UPDATE ci_builds SET push_data=(SELECT push_data FROM ci_commits WHERE ci_commits.id = ci_builds.commit_id) WHERE push_data IS NULL')
execute('UPDATE ci_builds SET tag=(SELECT tag FROM ci_commits WHERE ci_commits.id = ci_builds.commit_id) WHERE tag IS NULL')
end
end
diff --git a/db/migrate/20151005075649_add_user_id_to_build.rb b/db/migrate/20151005075649_add_user_id_to_build.rb
new file mode 100644
index 00000000000..0f4b92b8b79
--- /dev/null
+++ b/db/migrate/20151005075649_add_user_id_to_build.rb
@@ -0,0 +1,5 @@
+class AddUserIdToBuild < ActiveRecord::Migration
+ def change
+ add_column :ci_builds, :user_id, :integer
+ end
+end
diff --git a/lib/ci/api/commits.rb b/lib/ci/api/commits.rb
index bac463a5909..6a5b52b17de 100644
--- a/lib/ci/api/commits.rb
+++ b/lib/ci/api/commits.rb
@@ -51,7 +51,7 @@ module Ci
required_attributes! [:project_id, :data, :project_token]
project = Ci::Project.find(params[:project_id])
authenticate_project_token!(project)
- commit = Ci::CreateCommitService.new.execute(project, params[:data])
+ commit = Ci::CreateCommitService.new.execute(project, params[:data], current_user)
if commit.persisted?
present commit, with: Entities::CommitWithBuilds
diff --git a/spec/factories/ci/builds.rb b/spec/factories/ci/builds.rb
index 99da5a18776..8e2496398a6 100644
--- a/spec/factories/ci/builds.rb
+++ b/spec/factories/ci/builds.rb
@@ -27,9 +27,10 @@
FactoryGirl.define do
factory :ci_build, class: Ci::Build do
+ ref 'master'
+ tag false
started_at 'Di 29. Okt 09:51:28 CET 2013'
finished_at 'Di 29. Okt 09:53:28 CET 2013'
- commands 'ls -a'
options do
{
image: "ruby:2.1",
@@ -43,5 +44,9 @@ FactoryGirl.define do
started_at nil
finished_at nil
end
+
+ factory :ci_build_tag do
+ tag true
+ end
end
end
diff --git a/spec/factories/ci/commits.rb b/spec/factories/ci/commits.rb
index 9c7a0e9cbe0..b74aae795aa 100644
--- a/spec/factories/ci/commits.rb
+++ b/spec/factories/ci/commits.rb
@@ -18,59 +18,25 @@
# Read about factories at https://github.com/thoughtbot/factory_girl
FactoryGirl.define do
factory :ci_commit, class: Ci::Commit do
- ref 'master'
- before_sha '76de212e80737a608d939f648d959671fb0a0142'
sha '97de212e80737a608d939f648d959671fb0a0142'
- push_data do
- {
- ref: 'refs/heads/master',
- before: '76de212e80737a608d939f648d959671fb0a0142',
- after: '97de212e80737a608d939f648d959671fb0a0142',
- user_name: 'Git User',
- user_email: 'git@example.com',
- repository: {
- name: 'test-data',
- url: 'ssh://git@gitlab.com/test/test-data.git',
- description: '',
- homepage: 'http://gitlab.com/test/test-data'
- },
- commits: [
- {
- id: '97de212e80737a608d939f648d959671fb0a0142',
- message: 'Test commit message',
- timestamp: '2014-09-23T13:12:25+02:00',
- url: 'https://gitlab.com/test/test-data/commit/97de212e80737a608d939f648d959671fb0a0142',
- author: {
- name: 'Git User',
- email: 'git@user.com'
- }
- }
- ],
- total_commits_count: 1,
- ci_yaml_file: File.read(Rails.root.join('spec/support/gitlab_stubs/gitlab_ci.yml'))
- }
- end
gl_project factory: :empty_project
factory :ci_commit_without_jobs do
after(:create) do |commit, evaluator|
- commit.push_data[:ci_yaml_file] = YAML.dump({})
- commit.save
+ allow(commit).to receive(:ci_yaml_file) { YAML.dump({}) }
end
end
factory :ci_commit_with_one_job do
after(:create) do |commit, evaluator|
- commit.push_data[:ci_yaml_file] = YAML.dump({ rspec: { script: "ls" } })
- commit.save
+ allow(commit).to receive(:ci_yaml_file) { YAML.dump({ rspec: { script: "ls" } }) }
end
end
factory :ci_commit_with_two_jobs do
after(:create) do |commit, evaluator|
- commit.push_data[:ci_yaml_file] = YAML.dump({ rspec: { script: "ls" }, spinach: { script: "ls" } })
- commit.save
+ allow(commit).to receive(:ci_yaml_file) { YAML.dump({ rspec: { script: "ls" }, spinach: { script: "ls" } }) }
end
end
end