Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
gitlab-ce
Commits
e3d870d7
Commit
e3d870d7
authored
Oct 05, 2015
by
Kamil Trzcinski
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add user to Ci::Build to have pusher email address
parent
546a3c65
Changes
13
Hide whitespace changes
Inline
Side-by-side
Showing
13 changed files
with
29 additions
and
66 deletions
+29
-66
app/models/ci/build.rb
app/models/ci/build.rb
+3
-3
app/models/ci/commit.rb
app/models/ci/commit.rb
+2
-2
app/models/project_services/gitlab_ci_service.rb
app/models/project_services/gitlab_ci_service.rb
+1
-1
app/models/user.rb
app/models/user.rb
+1
-0
app/services/ci/create_builds_service.rb
app/services/ci/create_builds_service.rb
+2
-2
app/services/ci/create_commit_service.rb
app/services/ci/create_commit_service.rb
+2
-14
db/migrate/20151002121400_add_index_for_builds.rb
db/migrate/20151002121400_add_index_for_builds.rb
+1
-1
db/migrate/20151002122929_add_ref_and_tag_to_builds.rb
db/migrate/20151002122929_add_ref_and_tag_to_builds.rb
+1
-2
db/migrate/20151002122943_migrate_ref_and_tag_to_build.rb
db/migrate/20151002122943_migrate_ref_and_tag_to_build.rb
+1
-2
db/migrate/20151005075649_add_user_id_to_build.rb
db/migrate/20151005075649_add_user_id_to_build.rb
+5
-0
lib/ci/api/commits.rb
lib/ci/api/commits.rb
+1
-1
spec/factories/ci/builds.rb
spec/factories/ci/builds.rb
+6
-1
spec/factories/ci/commits.rb
spec/factories/ci/commits.rb
+3
-37
No files found.
app/models/ci/build.rb
View file @
e3d870d7
...
...
@@ -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
...
...
app/models/ci/commit.rb
View file @
e3d870d7
...
...
@@ -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
...
...
app/models/project_services/gitlab_ci_service.rb
View file @
e3d870d7
...
...
@@ -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
...
...
app/models/user.rb
View file @
e3d870d7
...
...
@@ -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'
#
...
...
app/services/ci/create_builds_service.rb
View file @
e3d870d7
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
...
...
app/services/ci/create_commit_service.rb
View file @
e3d870d7
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
...
...
db/migrate/20151002121400_add_index_for_build
_name
.rb
→
db/migrate/20151002121400_add_index_for_build
s
.rb
View file @
e3d870d7
class
AddIndexForBuild
Name
<
ActiveRecord
::
Migration
class
AddIndexForBuild
s
<
ActiveRecord
::
Migration
def
up
add_index
:ci_builds
,
[
:commit_id
,
:stage_idx
,
:created_at
]
end
...
...
db/migrate/20151002122929_add_
sha_and_ref
_to_builds.rb
→
db/migrate/20151002122929_add_
ref_and_tag
_to_builds.rb
View file @
e3d870d7
class
Add
ShaAndRef
ToBuilds
<
ActiveRecord
::
Migration
class
Add
RefAndTag
ToBuilds
<
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
db/migrate/20151002122943_migrate_
sha_and_ref
_to_build.rb
→
db/migrate/20151002122943_migrate_
ref_and_tag
_to_build.rb
View file @
e3d870d7
class
Migrate
ShaAndRef
ToBuild
<
ActiveRecord
::
Migration
class
Migrate
RefAndTag
ToBuild
<
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
db/migrate/20151005075649_add_user_id_to_build.rb
0 → 100644
View file @
e3d870d7
class
AddUserIdToBuild
<
ActiveRecord
::
Migration
def
change
add_column
:ci_builds
,
:user_id
,
:integer
end
end
lib/ci/api/commits.rb
View file @
e3d870d7
...
...
@@ -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
...
...
spec/factories/ci/builds.rb
View file @
e3d870d7
...
...
@@ -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
spec/factories/ci/commits.rb
View file @
e3d870d7
...
...
@@ -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
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment