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
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Léo-Paul Géneau
gitlab-ce
Commits
546a3c65
Commit
546a3c65
authored
Oct 02, 2015
by
Kamil Trzcinski
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Refactor commit and build
parent
0de7c83a
Changes
32
Show whitespace changes
Inline
Side-by-side
Showing
32 changed files
with
193 additions
and
193 deletions
+193
-193
app/controllers/ci/builds_controller.rb
app/controllers/ci/builds_controller.rb
+1
-1
app/controllers/ci/commits_controller.rb
app/controllers/ci/commits_controller.rb
+3
-3
app/controllers/ci/projects_controller.rb
app/controllers/ci/projects_controller.rb
+2
-1
app/helpers/ci/commits_helper.rb
app/helpers/ci/commits_helper.rb
+1
-1
app/helpers/ci/gitlab_helper.rb
app/helpers/ci/gitlab_helper.rb
+1
-1
app/helpers/ci_status_helper.rb
app/helpers/ci_status_helper.rb
+1
-1
app/models/ci/build.rb
app/models/ci/build.rb
+16
-0
app/models/ci/commit.rb
app/models/ci/commit.rb
+43
-94
app/models/ci/project_status.rb
app/models/ci/project_status.rb
+0
-12
app/models/project.rb
app/models/project.rb
+5
-1
app/models/project_services/ci/hip_chat_message.rb
app/models/project_services/ci/hip_chat_message.rb
+1
-1
app/models/project_services/ci/mail_service.rb
app/models/project_services/ci/mail_service.rb
+1
-1
app/models/project_services/ci/slack_message.rb
app/models/project_services/ci/slack_message.rb
+1
-1
app/models/project_services/gitlab_ci_service.rb
app/models/project_services/gitlab_ci_service.rb
+2
-2
app/services/ci/create_builds_service.rb
app/services/ci/create_builds_service.rb
+27
-0
app/services/ci/create_commit_service.rb
app/services/ci/create_commit_service.rb
+14
-25
app/services/ci/create_trigger_request_service.rb
app/services/ci/create_trigger_request_service.rb
+3
-3
app/views/ci/builds/_build.html.haml
app/views/ci/builds/_build.html.haml
+4
-0
app/views/ci/builds/show.html.haml
app/views/ci/builds/show.html.haml
+3
-3
app/views/ci/commits/_commit.html.haml
app/views/ci/commits/_commit.html.haml
+2
-2
app/views/ci/commits/show.html.haml
app/views/ci/commits/show.html.haml
+28
-29
app/views/ci/notify/build_fail_email.html.haml
app/views/ci/notify/build_fail_email.html.haml
+1
-1
app/views/ci/notify/build_fail_email.text.erb
app/views/ci/notify/build_fail_email.text.erb
+1
-1
app/views/ci/notify/build_success_email.html.haml
app/views/ci/notify/build_success_email.html.haml
+1
-1
app/views/ci/notify/build_success_email.text.erb
app/views/ci/notify/build_success_email.text.erb
+1
-1
config/routes.rb
config/routes.rb
+4
-6
db/migrate/20151002112914_add_stage_idx_to_builds.rb
db/migrate/20151002112914_add_stage_idx_to_builds.rb
+5
-0
db/migrate/20151002121400_add_index_for_build_name.rb
db/migrate/20151002121400_add_index_for_build_name.rb
+5
-0
db/migrate/20151002122929_add_sha_and_ref_to_builds.rb
db/migrate/20151002122929_add_sha_and_ref_to_builds.rb
+7
-0
db/migrate/20151002122943_migrate_sha_and_ref_to_build.rb
db/migrate/20151002122943_migrate_sha_and_ref_to_build.rb
+7
-0
lib/ci/gitlab_ci_yaml_processor.rb
lib/ci/gitlab_ci_yaml_processor.rb
+1
-0
spec/requests/ci/commits_spec.rb
spec/requests/ci/commits_spec.rb
+1
-1
No files found.
app/controllers/ci/builds_controller.rb
View file @
546a3c65
...
@@ -18,7 +18,7 @@ module Ci
...
@@ -18,7 +18,7 @@ module Ci
if
commit
if
commit
# Redirect to commit page
# Redirect to commit page
redirect_to
ci_project_
ref_commit_path
(
@project
,
@build
.
commit
.
ref
,
@build
.
commit
.
sha
)
redirect_to
ci_project_
commit_path
(
@project
,
@build
.
commit
)
return
return
end
end
end
end
...
...
app/controllers/ci/commits_controller.rb
View file @
546a3c65
...
@@ -13,7 +13,7 @@ module Ci
...
@@ -13,7 +13,7 @@ module Ci
end
end
def
status
def
status
commit
=
Ci
::
Project
.
find
(
params
[
:project_id
]).
commits
.
find_by_sha
_and_ref
!
(
params
[
:id
],
params
[
:ref_id
])
commit
=
Ci
::
Project
.
find
(
params
[
:project_id
]).
commits
.
find_by_sha!
(
params
[
:id
],
params
[
:ref_id
])
render
json:
commit
.
to_json
(
only:
[
:id
,
:sha
],
methods:
[
:status
,
:coverage
])
render
json:
commit
.
to_json
(
only:
[
:id
,
:sha
],
methods:
[
:status
,
:coverage
])
rescue
ActiveRecord
::
RecordNotFound
rescue
ActiveRecord
::
RecordNotFound
render
json:
{
status:
"not_found"
}
render
json:
{
status:
"not_found"
}
...
@@ -22,7 +22,7 @@ module Ci
...
@@ -22,7 +22,7 @@ module Ci
def
cancel
def
cancel
commit
.
builds
.
running_or_pending
.
each
(
&
:cancel
)
commit
.
builds
.
running_or_pending
.
each
(
&
:cancel
)
redirect_to
ci_project_
ref_commits_path
(
project
,
commit
.
ref
,
commit
.
sha
)
redirect_to
ci_project_
commits_path
(
project
,
commit
.
sha
)
end
end
private
private
...
@@ -32,7 +32,7 @@ module Ci
...
@@ -32,7 +32,7 @@ module Ci
end
end
def
commit
def
commit
@commit
||=
Ci
::
Project
.
find
(
params
[
:project_id
]).
commits
.
find_by_sha
_and_ref!
(
params
[
:id
],
params
[
:ref_
id
])
@commit
||=
Ci
::
Project
.
find
(
params
[
:project_id
]).
commits
.
find_by_sha
!
(
params
[
:
id
])
end
end
end
end
end
end
app/controllers/ci/projects_controller.rb
View file @
546a3c65
...
@@ -19,7 +19,8 @@ module Ci
...
@@ -19,7 +19,8 @@ module Ci
@ref
=
params
[
:ref
]
@ref
=
params
[
:ref
]
@commits
=
@project
.
commits
.
reverse_order
@commits
=
@project
.
commits
.
reverse_order
@commits
=
@commits
.
where
(
ref:
@ref
)
if
@ref
# TODO: this is broken
# @commits = @commits.where(ref: @ref) if @ref
@commits
=
@commits
.
page
(
params
[
:page
]).
per
(
20
)
@commits
=
@commits
.
page
(
params
[
:page
]).
per
(
20
)
end
end
...
...
app/helpers/ci/commits_helper.rb
View file @
546a3c65
module
Ci
module
Ci
module
CommitsHelper
module
CommitsHelper
def
ci_commit_path
(
commit
)
def
ci_commit_path
(
commit
)
ci_project_
ref_commits_path
(
commit
.
project
,
commit
.
ref
,
commit
.
sha
)
ci_project_
commits_path
(
commit
.
project
,
commit
)
end
end
def
commit_link
(
commit
)
def
commit_link
(
commit
)
...
...
app/helpers/ci/gitlab_helper.rb
View file @
546a3c65
...
@@ -26,7 +26,7 @@ module Ci
...
@@ -26,7 +26,7 @@ module Ci
def
yaml_web_editor_link
(
project
)
def
yaml_web_editor_link
(
project
)
commits
=
project
.
commits
commits
=
project
.
commits
if
commits
.
any?
&&
commits
.
last
.
push_data
[
:ci_yaml_file
]
if
commits
.
any?
&&
commits
.
last
.
ci_yaml_file
"
#{
project
.
gitlab_url
}
/edit/master/.gitlab-ci.yml"
"
#{
project
.
gitlab_url
}
/edit/master/.gitlab-ci.yml"
else
else
"
#{
project
.
gitlab_url
}
/new/master"
"
#{
project
.
gitlab_url
}
/new/master"
...
...
app/helpers/ci_status_helper.rb
View file @
546a3c65
module
CiStatusHelper
module
CiStatusHelper
def
ci_status_path
(
ci_commit
)
def
ci_status_path
(
ci_commit
)
ci_project_
ref_commits_path
(
ci_commit
.
project
,
ci_commit
.
ref
,
ci_commit
)
ci_project_
commits_path
(
ci_commit
.
project
,
ci_commit
)
end
end
def
ci_status_icon
(
ci_commit
)
def
ci_status_icon
(
ci_commit
)
...
...
app/models/ci/build.rb
View file @
546a3c65
...
@@ -34,10 +34,12 @@ module Ci
...
@@ -34,10 +34,12 @@ module Ci
belongs_to
:trigger_request
,
class_name:
'Ci::TriggerRequest'
belongs_to
:trigger_request
,
class_name:
'Ci::TriggerRequest'
serialize
:options
serialize
:options
serialize
:push_data
validates
:commit
,
presence:
true
validates
:commit
,
presence:
true
validates
:status
,
presence:
true
validates
:status
,
presence:
true
validates
:coverage
,
numericality:
true
,
allow_blank:
true
validates
:coverage
,
numericality:
true
,
allow_blank:
true
validates_presence_of
:ref
scope
:running
,
->
()
{
where
(
status:
"running"
)
}
scope
:running
,
->
()
{
where
(
status:
"running"
)
}
scope
:pending
,
->
()
{
where
(
status:
"pending"
)
}
scope
:pending
,
->
()
{
where
(
status:
"pending"
)
}
...
@@ -45,6 +47,9 @@ module Ci
...
@@ -45,6 +47,9 @@ module Ci
scope
:failed
,
->
()
{
where
(
status:
"failed"
)
}
scope
:failed
,
->
()
{
where
(
status:
"failed"
)
}
scope
:unstarted
,
->
()
{
where
(
runner_id:
nil
)
}
scope
:unstarted
,
->
()
{
where
(
runner_id:
nil
)
}
scope
:running_or_pending
,
->
()
{
where
(
status
:[
:running
,
:pending
])
}
scope
:running_or_pending
,
->
()
{
where
(
status
:[
:running
,
:pending
])
}
scope
:latest
,
->
()
{
group
(
:name
).
order
(
stage_idx: :asc
,
created_at: :desc
)
}
scope
:ignore_failures
,
->
()
{
where
(
allow_failure:
false
)
}
scope
:for_ref
,
->
(
ref
)
{
where
(
ref:
ref
)
}
acts_as_taggable
acts_as_taggable
...
@@ -82,6 +87,7 @@ module Ci
...
@@ -82,6 +87,7 @@ module Ci
new_build
.
name
=
build
.
name
new_build
.
name
=
build
.
name
new_build
.
allow_failure
=
build
.
allow_failure
new_build
.
allow_failure
=
build
.
allow_failure
new_build
.
stage
=
build
.
stage
new_build
.
stage
=
build
.
stage
new_build
.
stage_idx
=
build
.
stage_idx
new_build
.
trigger_request
=
build
.
trigger_request
new_build
.
trigger_request
=
build
.
trigger_request
new_build
.
save
new_build
.
save
new_build
new_build
...
@@ -187,6 +193,16 @@ module Ci
...
@@ -187,6 +193,16 @@ module Ci
project
.
name
project
.
name
end
end
def
project_recipients
recipients
=
project
.
email_recipients
.
split
(
' '
)
if
project
.
email_add_pusher?
&&
push_data
[
:user_email
].
present?
recipients
<<
push_data
[
:user_email
]
end
recipients
.
uniq
end
def
repo_url
def
repo_url
project
.
repo_url_with_auth
project
.
repo_url_with_auth
end
end
...
...
app/models/ci/commit.rb
View file @
546a3c65
...
@@ -23,9 +23,7 @@ module Ci
...
@@ -23,9 +23,7 @@ module Ci
has_many
:builds
,
dependent: :destroy
,
class_name:
'Ci::Build'
has_many
:builds
,
dependent: :destroy
,
class_name:
'Ci::Build'
has_many
:trigger_requests
,
dependent: :destroy
,
class_name:
'Ci::TriggerRequest'
has_many
:trigger_requests
,
dependent: :destroy
,
class_name:
'Ci::TriggerRequest'
serialize
:push_data
validates_presence_of
:sha
validates_presence_of
:ref
,
:sha
,
:before_sha
,
:push_data
validate
:valid_commit_sha
validate
:valid_commit_sha
def
self
.
truncate_sha
(
sha
)
def
self
.
truncate_sha
(
sha
)
...
@@ -69,15 +67,15 @@ module Ci
...
@@ -69,15 +67,15 @@ module Ci
end
end
def
git_author_name
def
git_author_name
commit_data
[
:author
][
:name
]
if
commit_data
&&
commit_data
[
:author
]
commit_data
.
author_name
if
commit_data
end
end
def
git_author_email
def
git_author_email
commit_data
[
:author
][
:email
]
if
commit_data
&&
commit_data
[
:author
]
commit_data
.
author_email
if
commit_data
end
end
def
git_commit_message
def
git_commit_message
commit_data
[
:message
]
if
commit_data
&&
commit_data
[
:message
]
commit_data
.
message
if
commit_data
end
end
def
short_before_sha
def
short_before_sha
...
@@ -89,84 +87,31 @@ module Ci
...
@@ -89,84 +87,31 @@ module Ci
end
end
def
commit_data
def
commit_data
push_data
[
:commits
].
find
do
|
commit
|
@commit
||=
gl_project
.
commit
(
sha
)
commit
[
:id
]
==
sha
end
rescue
rescue
nil
nil
end
end
def
project_recipients
recipients
=
project
.
email_recipients
.
split
(
' '
)
if
project
.
email_add_pusher?
&&
push_data
[
:user_email
].
present?
recipients
<<
push_data
[
:user_email
]
end
recipients
.
uniq
end
def
stage
def
stage
return
unless
config_processor
builds_without_retry
.
group
(
:stage_idx
).
select
(
:stage
).
last
stages
=
builds_without_retry
.
select
(
&
:active?
).
map
(
&
:stage
)
config_processor
.
stages
.
find
{
|
stage
|
stages
.
include?
stage
}
end
end
def
create_builds
_for_stage
(
stage
,
trigger_request
)
def
create_builds
(
ref
,
tag
,
push_data
,
trigger_request
=
nil
)
return
if
skip_ci?
&&
trigger_request
.
blank?
return
if
skip_ci?
&&
trigger_request
.
blank?
return
unless
config_processor
return
unless
config_processor
CreateBuildsService
.
new
.
execute
(
self
,
config_processor
,
ref
,
tag
,
push_data
,
trigger_request
)
builds_attrs
=
config_processor
.
builds_for_stage_and_ref
(
stage
,
ref
,
tag
)
builds_attrs
.
map
do
|
build_attrs
|
builds
.
create!
({
name:
build_attrs
[
:name
],
commands:
build_attrs
[
:script
],
tag_list:
build_attrs
[
:tags
],
options:
build_attrs
[
:options
],
allow_failure:
build_attrs
[
:allow_failure
],
stage:
build_attrs
[
:stage
],
trigger_request:
trigger_request
,
})
end
end
end
def
create_next_builds
(
trigger_request
)
def
refs
return
if
skip_ci?
&&
trigger_request
.
blank?
builds
.
group
(
:ref
).
pluck
(
:ref
)
return
unless
config_processor
stages
=
builds
.
where
(
trigger_request:
trigger_request
).
group_by
(
&
:stage
)
config_processor
.
stages
.
any?
do
|
stage
|
!
stages
.
include?
(
stage
)
&&
create_builds_for_stage
(
stage
,
trigger_request
).
present?
end
end
end
def
create_builds
(
trigger_request
=
nil
)
def
last_ref
return
if
skip_ci?
&&
trigger_request
.
blank?
builds
.
latest
.
first
.
try
(
:ref
)
return
unless
config_processor
config_processor
.
stages
.
any?
do
|
stage
|
create_builds_for_stage
(
stage
,
trigger_request
).
present?
end
end
end
def
builds_without_retry
def
builds_without_retry
@builds_without_retry
||=
builds
.
latest
begin
grouped_builds
=
builds
.
group_by
(
&
:name
)
grouped_builds
.
map
do
|
name
,
builds
|
builds
.
sort_by
(
&
:id
).
last
end
end
end
def
builds_without_retry_sorted
return
builds_without_retry
unless
config_processor
stages
=
config_processor
.
stages
builds_without_retry
.
sort_by
do
|
build
|
[
stages
.
index
(
build
.
stage
)
||
-
1
,
build
.
name
||
""
]
end
end
end
def
retried_builds
def
retried_builds
...
@@ -180,35 +125,32 @@ module Ci
...
@@ -180,35 +125,32 @@ module Ci
return
'failed'
return
'failed'
elsif
builds
.
none?
elsif
builds
.
none?
return
'skipped'
return
'skipped'
elsif
success?
end
'success'
elsif
pending?
statuses
=
builds_without_retry
.
ignore_failures
.
pluck
(
:status
)
'pending'
if
statuses
.
all?
{
|
status
|
status
==
'success'
}
elsif
running?
return
'success'
'running'
elsif
statuses
.
all?
{
|
status
|
status
==
'pending'
}
elsif
canceled?
return
'pending'
'canceled'
elsif
statuses
.
include?
(
'running'
)
||
statuses
.
include?
(
'pending'
)
return
'running'
elsif
statuses
.
all?
{
|
status
|
status
==
'canceled'
}
return
'canceled'
else
else
'failed'
return
'failed'
end
end
end
end
def
pending?
def
pending?
builds_without_retry
.
all?
do
|
build
|
status
==
'pending'
build
.
pending?
end
end
end
def
running?
def
running?
builds_without_retry
.
any?
do
|
build
|
status
==
'running'
build
.
running?
||
build
.
pending?
end
end
end
def
success?
def
success?
builds_without_retry
.
all?
do
|
build
|
status
==
'success'
build
.
success?
||
build
.
ignored?
end
end
end
def
failed?
def
failed?
...
@@ -216,15 +158,17 @@ module Ci
...
@@ -216,15 +158,17 @@ module Ci
end
end
def
canceled?
def
canceled?
builds_without_retry
.
all?
do
|
build
|
status
==
'canceled'
build
.
canceled?
end
end
end
def
duration
def
duration
@duration
||=
builds_without_retry
.
select
(
&
:duration
).
sum
(
&
:duration
).
to_i
@duration
||=
builds_without_retry
.
select
(
&
:duration
).
sum
(
&
:duration
).
to_i
end
end
def
duration_for_ref
(
ref
)
builds_without_retry
.
for_ref
(
ref
).
select
(
&
:duration
).
sum
(
&
:duration
).
to_i
end
def
finished_at
def
finished_at
@finished_at
||=
builds
.
order
(
'finished_at DESC'
).
first
.
try
(
:finished_at
)
@finished_at
||=
builds
.
order
(
'finished_at DESC'
).
first
.
try
(
:finished_at
)
end
end
...
@@ -238,12 +182,12 @@ module Ci
...
@@ -238,12 +182,12 @@ module Ci
end
end
end
end
def
matrix
?
def
matrix
_for_ref?
(
ref
)
builds_without_retry
.
size
>
1
builds_without_retry
.
for_ref
(
ref
).
pluck
(
:id
).
size
>
1
end
end
def
config_processor
def
config_processor
@config_processor
||=
Ci
::
GitlabCiYamlProcessor
.
new
(
push_data
[
:ci_yaml_file
]
)
@config_processor
||=
Ci
::
GitlabCiYamlProcessor
.
new
(
ci_yaml_file
)
rescue
Ci
::
GitlabCiYamlProcessor
::
ValidationError
=>
e
rescue
Ci
::
GitlabCiYamlProcessor
::
ValidationError
=>
e
save_yaml_error
(
e
.
message
)
save_yaml_error
(
e
.
message
)
nil
nil
...
@@ -253,10 +197,15 @@ module Ci
...
@@ -253,10 +197,15 @@ module Ci
nil
nil
end
end
def
ci_yaml_file
gl_project
.
repository
.
blob_at
(
sha
,
'.gitlab-ci.yml'
)
rescue
nil
end
def
skip_ci?
def
skip_ci?
return
false
if
builds
.
any?
return
false
if
builds
.
any?
commits
=
push_data
[
:commits
]
git_commit_message
=~
/(\[ci skip\])/
if
git_commit_message
commits
.
present?
&&
commits
.
last
[
:message
]
=~
/(\[ci skip\])/
end
end
def
update_committed!
def
update_committed!
...
...
app/models/ci/project_status.rb
View file @
546a3c65
...
@@ -28,18 +28,6 @@ module Ci
...
@@ -28,18 +28,6 @@ module Ci
status
status
end
end
# only check for toggling build status within same ref.
def
last_commit_changed_status?
ref
=
last_commit
.
ref
last_commits
=
commits
.
where
(
ref:
ref
).
last
(
2
)
if
last_commits
.
size
<
2
false
else
last_commits
[
0
].
status
!=
last_commits
[
1
].
status
end
end
def
last_commit_for_ref
(
ref
)
def
last_commit_for_ref
(
ref
)
commits
.
where
(
ref:
ref
).
last
commits
.
where
(
ref:
ref
).
last
end
end
...
...
app/models/project.rb
View file @
546a3c65
...
@@ -744,7 +744,11 @@ class Project < ActiveRecord::Base
...
@@ -744,7 +744,11 @@ class Project < ActiveRecord::Base
end
end
def
ci_commit
(
sha
)
def
ci_commit
(
sha
)
gitlab_ci_project
.
commits
.
find_by
(
sha:
sha
)
if
gitlab_ci?
ci_commits
.
find_by
(
sha:
sha
)
end
def
ensure_ci_commit
(
sha
)
ci_commit
(
sha
)
||
ci_commits
.
create
(
sha:
sha
)
end
end
def
ensure_gitlab_ci_project
def
ensure_gitlab_ci_project
...
...
app/models/project_services/ci/hip_chat_message.rb
View file @
546a3c65
...
@@ -13,7 +13,7 @@ module Ci
...
@@ -13,7 +13,7 @@ module Ci
lines
.
push
(
"<a href=
\"
#{
ci_project_url
(
project
)
}
\"
>
#{
project
.
name
}
</a> - "
)
lines
.
push
(
"<a href=
\"
#{
ci_project_url
(
project
)
}
\"
>
#{
project
.
name
}
</a> - "
)
if
commit
.
matrix?
if
commit
.
matrix?
lines
.
push
(
"<a href=
\"
#{
ci_project_
ref_commits_url
(
project
,
commit
.
ref
,
commit
.
sha
)
}
\"
>Commit #
#{
commit
.
id
}
</a></br>"
)
lines
.
push
(
"<a href=
\"
#{
ci_project_
commits_url
(
project
,
commit
.
sha
)
}
\"
>Commit #
#{
commit
.
id
}
</a></br>"
)
else
else
first_build
=
commit
.
builds_without_retry
.
first
first_build
=
commit
.
builds_without_retry
.
first
lines
.
push
(
"<a href=
\"
#{
ci_project_build_url
(
project
,
first_build
)
}
\"
>Build '
#{
first_build
.
name
}
' #
#{
first_build
.
id
}
</a></br>"
)
lines
.
push
(
"<a href=
\"
#{
ci_project_build_url
(
project
,
first_build
)
}
\"
>Build '
#{
first_build
.
name
}
' #
#{
first_build
.
id
}
</a></br>"
)
...
...
app/models/project_services/ci/mail_service.rb
View file @
546a3c65
...
@@ -61,7 +61,7 @@ module Ci
...
@@ -61,7 +61,7 @@ module Ci
end
end
def
execute
(
build
)
def
execute
(
build
)
build
.
commit
.
project_recipients
.
each
do
|
recipient
|
build
.
project_recipients
.
each
do
|
recipient
|
case
build
.
status
.
to_sym
case
build
.
status
.
to_sym
when
:success
when
:success
mailer
.
build_success_email
(
build
.
id
,
recipient
)
mailer
.
build_success_email
(
build
.
id
,
recipient
)
...
...
app/models/project_services/ci/slack_message.rb
View file @
546a3c65
...
@@ -48,7 +48,7 @@ module Ci
...
@@ -48,7 +48,7 @@ module Ci
def
attachment_message
def
attachment_message
out
=
"<
#{
ci_project_url
(
project
)
}
|
#{
project_name
}
>: "
out
=
"<
#{
ci_project_url
(
project
)
}
|
#{
project_name
}
>: "
if
commit
.
matrix?
if
commit
.
matrix?
out
<<
"Commit <
#{
ci_project_
ref_commits_url
(
project
,
commit
.
ref
,
commit
.
sha
)
}
|
\#
#{
commit
.
id
}
> "
out
<<
"Commit <
#{
ci_project_
commits_url
(
project
,
commit
.
sha
)
}
|
\#
#{
commit
.
id
}
> "
else
else
build
=
commit
.
builds_without_retry
.
first
build
=
commit
.
builds_without_retry
.
first
out
<<
"Build <
#{
ci_project_build_url
(
project
,
build
)
}
|
\#
#{
build
.
id
}
> "
out
<<
"Build <
#{
ci_project_build_url
(
project
,
build
)
}
|
\#
#{
build
.
id
}
> "
...
...
app/models/project_services/gitlab_ci_service.rb
View file @
546a3c65
...
@@ -63,7 +63,7 @@ class GitlabCiService < CiService
...
@@ -63,7 +63,7 @@ class GitlabCiService < CiService
end
end
def
get_ci_commit
(
sha
,
ref
)
def
get_ci_commit
(
sha
,
ref
)
Ci
::
Project
.
find
(
project
.
gitlab_ci_project
).
commits
.
find_by_sha
_and_ref!
(
sha
,
ref
)
Ci
::
Project
.
find
(
project
.
gitlab_ci_project
).
commits
.
find_by_sha
!
(
sha
)
end
end
def
commit_status
(
sha
,
ref
)
def
commit_status
(
sha
,
ref
)
...
@@ -80,7 +80,7 @@ class GitlabCiService < CiService
...
@@ -80,7 +80,7 @@ class GitlabCiService < CiService
def
build_page
(
sha
,
ref
)
def
build_page
(
sha
,
ref
)
if
project
.
gitlab_ci_project
.
present?
if
project
.
gitlab_ci_project
.
present?
ci_project_
ref_commits_url
(
project
.
gitlab_ci_project
,
ref
,
sha
)
ci_project_
commits_url
(
project
.
gitlab_ci_project
,
sha
)
end
end
end
end
...
...
app/services/ci/create_builds_service.rb
0 → 100644
View file @
546a3c65
module
Ci
class
CreateBuildsService
def
execute
(
commit
,
ref
,
tag
,
push_data
,
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
|
# don't create the same build twice
unless
commit
.
builds
.
find_by_name_and_trigger_request
(
name:
build_attrs
[
:name
],
ref:
ref
,
tag:
tag
,
trigger_request:
trigger_request
)
commit
.
builds
.
create!
({
name:
build_attrs
[
:name
],
commands:
build_attrs
[
:script
],
tag_list:
build_attrs
[
:tags
],
options:
build_attrs
[
:options
],
allow_failure:
build_attrs
[
:allow_failure
],
stage:
build_attrs
[
:stage
],
stage_idx:
build_attrs
[
:stage_idx
],
trigger_request:
trigger_request
,
ref:
ref
,
tag:
tag
,
push_data:
push_data
,
})
end
end
end
end
end
end
app/services/ci/create_commit_service.rb
View file @
546a3c65
...
@@ -16,16 +16,8 @@ module Ci
...
@@ -16,16 +16,8 @@ module Ci
return
false
return
false
end
end
commit
=
project
.
commits
.
find_by_sha_and_ref
(
sha
,
ref
)
tag
=
origin_ref
.
start_with?
(
'refs/tags/'
)
push_data
=
{
# Create commit if not exists yet
unless
commit
data
=
{
ref:
ref
,
sha:
sha
,
tag:
origin_ref
.
start_with?
(
'refs/tags/'
),
before_sha:
before_sha
,
push_data:
{
before:
before_sha
,
before:
before_sha
,
after:
sha
,
after:
sha
,
ref:
ref
,
ref:
ref
,
...
@@ -36,13 +28,10 @@ module Ci
...
@@ -36,13 +28,10 @@ module Ci
total_commits_count:
params
[
:total_commits_count
],
total_commits_count:
params
[
:total_commits_count
],
ci_yaml_file:
params
[
:ci_yaml_file
]
ci_yaml_file:
params
[
:ci_yaml_file
]
}
}
}
commit
=
project
.
commits
.
create
(
data
)
end
commit
=
project
.
gl_project
.
ensure_ci_commit
(
sha
)
commit
.
update_committed!
commit
.
update_committed!
commit
.
create_builds
unless
commit
.
builds
.
any?
commit
.
create_builds
(
ref
,
tag
,
push_data
)
commit
commit
end
end
...
...
app/services/ci/create_trigger_request_service.rb
View file @
546a3c65
module
Ci
module
Ci
class
CreateTriggerRequestService
class
CreateTriggerRequestService
def
execute
(
project
,
trigger
,
ref
,
variables
=
nil
)
def
execute
(
project
,
trigger
,
ref
,
variables
=
nil
)
commit
=
project
.
commits
.
where
(
ref:
ref
).
last
commit
=
project
.
gl_project
.
commit
(
ref
)
return
unless
commit
return
unless
commit
ci_commit
=
project
.
gl_project
.
ensure_ci_commit
(
commit
.
sha
)
trigger_request
=
trigger
.
trigger_requests
.
create!
(
trigger_request
=
trigger
.
trigger_requests
.
create!
(
commit:
commit
,
variables:
variables
variables:
variables
)
)
if
c
ommit
.
create_builds
(
trigger_request
)
if
c
i_commit
.
create_builds
(
ref
,
tag
,
nil
,
trigger_request
)
trigger_request
trigger_request
end
end
end
end
...
...
app/views/ci/builds/_build.html.haml
View file @
546a3c65
...
@@ -6,6 +6,10 @@
...
@@ -6,6 +6,10 @@
=
link_to
ci_project_build_path
(
build
.
project
,
build
)
do
=
link_to
ci_project_build_path
(
build
.
project
,
build
)
do
%strong
Build ##{build.id}
%strong
Build ##{build.id}
-
if
defined?
(
ref
)
%td
=
build
.
ref
%td
%td
=
build
.
stage
=
build
.
stage
...
...
app/views/ci/builds/show.html.haml
View file @
546a3c65
#up-build-trace
#up-build-trace
-
if
@commit
.
matrix
?
-
if
@commit
.
matrix
_for_ref?
(
@build
.
ref
)
%ul
.center-top-menu
%ul
.center-top-menu
-
@commit
.
builds_without_retry
_sorted
.
each
do
|
build
|
-
@commit
.
builds_without_retry
.
for_ref
(
build
.
ref
)
.
each
do
|
build
|
%li
{
class:
(
'active'
if
build
==
@build
)
}
%li
{
class:
(
'active'
if
build
==
@build
)
}
=
link_to
ci_project_build_url
(
@project
,
build
)
do
=
link_to
ci_project_build_url
(
@project
,
build
)
do
=
ci_icon_for_status
(
build
.
status
)
=
ci_icon_for_status
(
build
.
status
)
...
@@ -12,7 +12,7 @@
...
@@ -12,7 +12,7 @@
=
build
.
id
=
build
.
id
-
unless
@commit
.
builds_without_retry
.
include?
(
@build
)
-
unless
@commit
.
builds_without_retry
.
for_ref
(
@build
.
ref
).
include?
(
@build
)
%li
.active
%li
.active
%a
%a
Build ##{@build.id}
Build ##{@build.id}
...
...
app/views/ci/commits/_commit.html.haml
View file @
546a3c65
...
@@ -7,7 +7,7 @@
...
@@ -7,7 +7,7 @@
%td
.build-link
%td
.build-link
=
link_to
ci_project_
ref_commits_path
(
commit
.
project
,
commit
.
ref
,
commit
.
sha
)
do
=
link_to
ci_project_
commits_path
(
commit
.
project
,
commit
.
sha
)
do
%strong
#{
commit
.
short_sha
}
%strong
#{
commit
.
short_sha
}
%td
.build-message
%td
.build-message
...
@@ -16,7 +16,7 @@
...
@@ -16,7 +16,7 @@
%td
.build-branch
%td
.build-branch
-
unless
@ref
-
unless
@ref
%span
%span
=
link_to
truncate
(
commit
.
ref
,
length:
25
),
ci_project_path
(
@project
,
ref:
commit
.
ref
)
=
link_to
truncate
(
commit
.
last_ref
,
length:
25
),
ci_project_path
(
@project
,
ref:
commit
.
last_
ref
)
%td
.duration
%td
.duration
-
if
commit
.
duration
>
0
-
if
commit
.
duration
>
0
...
...
app/views/ci/commits/show.html.haml
View file @
546a3c65
...
@@ -17,11 +17,8 @@
...
@@ -17,11 +17,8 @@
%p
%p
%span
.attr-name
Commit:
%span
.attr-name
Commit:
#{
gitlab_commit_link
(
@project
,
@commit
.
sha
)
}
#{
gitlab_commit_link
(
@project
,
@commit
.
sha
)
}
%p
%span
.attr-name
Branch:
#{
gitlab_ref_link
(
@project
,
@commit
.
ref
)
}
.col-sm-6
.col-sm-6
-
if
@commit
.
git_author_name
||
@commit
.
git_author_email
%p
%p
%span
.attr-name
Author:
%span
.attr-name
Author:
#{
@commit
.
git_author_name
}
(
#{
@commit
.
git_author_email
}
)
#{
@commit
.
git_author_name
}
(
#{
@commit
.
git_author_email
}
)
...
@@ -33,7 +30,7 @@
...
@@ -33,7 +30,7 @@
-
if
current_user
&&
can?
(
current_user
,
:manage_builds
,
gl_project
)
-
if
current_user
&&
can?
(
current_user
,
:manage_builds
,
gl_project
)
.pull-right
.pull-right
-
if
@commit
.
builds
.
running_or_pending
.
any?
-
if
@commit
.
builds
.
running_or_pending
.
any?
=
link_to
"Cancel"
,
cancel_ci_project_
ref_commits_path
(
@project
,
@commit
.
ref
,
@commit
.
sha
),
class:
'btn btn-sm btn-danger'
=
link_to
"Cancel"
,
cancel_ci_project_
commits_path
(
@project
,
@commit
),
class:
'btn btn-sm btn-danger'
-
if
@commit
.
yaml_errors
.
present?
-
if
@commit
.
yaml_errors
.
present?
...
@@ -43,18 +40,19 @@
...
@@ -43,18 +40,19 @@
-
@commit
.
yaml_errors
.
split
(
","
).
each
do
|
error
|
-
@commit
.
yaml_errors
.
split
(
","
).
each
do
|
error
|
%li
=
error
%li
=
error
-
unless
@commit
.
push_data
[
:ci_yaml_file
]
-
unless
@commit
.
ci_yaml_file
.bs-callout.bs-callout-warning
.bs-callout.bs-callout-warning
\.gitlab-ci.yml not found in this commit
\.gitlab-ci.yml not found in this commit
%h3
-
@commit
.
refs
.
each
do
|
ref
|
Builds
%h3
-
if
@commit
.
duration
>
0
Builds for
#{
ref
}
-
if
@commit
.
duration_for_ref
(
ref
)
>
0
%small
.pull-right
%small
.pull-right
%i
.fa.fa-time
%i
.fa.fa-time
#{
time_interval_in_words
@commit
.
duration
}
#{
time_interval_in_words
@commit
.
duration_for_ref
(
ref
)
}
%table
.table.builds
%table
.table.builds
%thead
%thead
%tr
%tr
%th
Status
%th
Status
...
@@ -66,7 +64,7 @@
...
@@ -66,7 +64,7 @@
-
if
@project
.
coverage_enabled?
-
if
@project
.
coverage_enabled?
%th
Coverage
%th
Coverage
%th
%th
=
render
@commit
.
builds_without_retry_sorted
,
controls:
true
=
render
@commit
.
builds_without_retry
.
for_ref
(
ref
)
,
controls:
true
-
if
@commit
.
retried_builds
.
any?
-
if
@commit
.
retried_builds
.
any?
%h3
%h3
...
@@ -77,6 +75,7 @@
...
@@ -77,6 +75,7 @@
%tr
%tr
%th
Status
%th
Status
%th
Build ID
%th
Build ID
%th
Ref
%th
Stage
%th
Stage
%th
Name
%th
Name
%th
Duration
%th
Duration
...
@@ -84,4 +83,4 @@
...
@@ -84,4 +83,4 @@
-
if
@project
.
coverage_enabled?
-
if
@project
.
coverage_enabled?
%th
Coverage
%th
Coverage
%th
%th
=
render
@commit
.
retried_builds
=
render
@commit
.
retried_builds
,
ref:
true
app/views/ci/notify/build_fail_email.html.haml
View file @
546a3c65
...
@@ -11,7 +11,7 @@
...
@@ -11,7 +11,7 @@
%p
%p
Author:
#{
@build
.
commit
.
git_author_name
}
Author:
#{
@build
.
commit
.
git_author_name
}
%p
%p
Branch:
#{
@build
.
commit
.
ref
}
Branch:
#{
@build
.
ref
}
%p
%p
Message:
#{
@build
.
commit
.
git_commit_message
}
Message:
#{
@build
.
commit
.
git_commit_message
}
...
...
app/views/ci/notify/build_fail_email.text.erb
View file @
546a3c65
...
@@ -3,7 +3,7 @@ Build failed for <%= @project.name %>
...
@@ -3,7 +3,7 @@ Build failed for <%= @project.name %>
Status:
<%=
@build
.
status
%>
Status:
<%=
@build
.
status
%>
Commit:
<%=
@build
.
commit
.
short_sha
%>
Commit:
<%=
@build
.
commit
.
short_sha
%>
Author:
<%=
@build
.
commit
.
git_author_name
%>
Author:
<%=
@build
.
commit
.
git_author_name
%>
Branch:
<%=
@build
.
commit
.
ref
%>
Branch:
<%=
@build
.
ref
%>
Message:
<%=
@build
.
commit
.
git_commit_message
%>
Message:
<%=
@build
.
commit
.
git_commit_message
%>
Url:
<%=
ci_project_build_url
(
@build
.
project
,
@build
)
%>
Url:
<%=
ci_project_build_url
(
@build
.
project
,
@build
)
%>
app/views/ci/notify/build_success_email.html.haml
View file @
546a3c65
...
@@ -12,7 +12,7 @@
...
@@ -12,7 +12,7 @@
%p
%p
Author:
#{
@build
.
commit
.
git_author_name
}
Author:
#{
@build
.
commit
.
git_author_name
}
%p
%p
Branch:
#{
@build
.
commit
.
ref
}
Branch:
#{
@build
.
ref
}
%p
%p
Message:
#{
@build
.
commit
.
git_commit_message
}
Message:
#{
@build
.
commit
.
git_commit_message
}
...
...
app/views/ci/notify/build_success_email.text.erb
View file @
546a3c65
...
@@ -3,7 +3,7 @@ Build successful for <%= @project.name %>
...
@@ -3,7 +3,7 @@ Build successful for <%= @project.name %>
Status:
<%=
@build
.
status
%>
Status:
<%=
@build
.
status
%>
Commit:
<%=
@build
.
commit
.
short_sha
%>
Commit:
<%=
@build
.
commit
.
short_sha
%>
Author:
<%=
@build
.
commit
.
git_author_name
%>
Author:
<%=
@build
.
commit
.
git_author_name
%>
Branch:
<%=
@build
.
commit
.
ref
%>
Branch:
<%=
@build
.
ref
%>
Message:
<%=
@build
.
commit
.
git_commit_message
%>
Message:
<%=
@build
.
commit
.
git_commit_message
%>
Url:
<%=
ci_project_build_url
(
@build
.
project
,
@build
)
%>
Url:
<%=
ci_project_build_url
(
@build
.
project
,
@build
)
%>
config/routes.rb
View file @
546a3c65
...
@@ -30,14 +30,12 @@ Gitlab::Application.routes.draw do
...
@@ -30,14 +30,12 @@ Gitlab::Application.routes.draw do
resource
:charts
,
only:
[
:show
]
resource
:charts
,
only:
[
:show
]
resources
:refs
,
constraints:
{
ref_id:
/.*/
},
only:
[]
do
resources
:commits
,
only:
[
:show
]
do
resources
:commits
,
only:
[
:show
]
do
member
do
member
do
get
:status
get
:status
get
:cancel
get
:cancel
end
end
end
end
end
resources
:builds
,
only:
[
:show
]
do
resources
:builds
,
only:
[
:show
]
do
member
do
member
do
...
...
db/migrate/20151002112914_add_stage_idx_to_builds.rb
0 → 100644
View file @
546a3c65
class
AddStageIdxToBuilds
<
ActiveRecord
::
Migration
def
change
add_column
:ci_builds
,
:stage_idx
,
:integer
end
end
db/migrate/20151002121400_add_index_for_build_name.rb
0 → 100644
View file @
546a3c65
class
AddIndexForBuildName
<
ActiveRecord
::
Migration
def
up
add_index
:ci_builds
,
[
:commit_id
,
:stage_idx
,
:created_at
]
end
end
db/migrate/20151002122929_add_sha_and_ref_to_builds.rb
0 → 100644
View file @
546a3c65
class
AddShaAndRefToBuilds
<
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
0 → 100644
View file @
546a3c65
class
MigrateShaAndRefToBuild
<
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
lib/ci/gitlab_ci_yaml_processor.rb
View file @
546a3c65
...
@@ -85,6 +85,7 @@ module Ci
...
@@ -85,6 +85,7 @@ module Ci
def
build_job
(
name
,
job
)
def
build_job
(
name
,
job
)
{
{
stage_idx:
stages
.
index
(
job
[
:stage
]),
stage:
job
[
:stage
],
stage:
job
[
:stage
],
script:
"
#{
@before_script
.
join
(
"
\n
"
)
}
\n
#{
normalize_script
(
job
[
:script
])
}
"
,
script:
"
#{
@before_script
.
join
(
"
\n
"
)
}
\n
#{
normalize_script
(
job
[
:script
])
}
"
,
tags:
job
[
:tags
]
||
[],
tags:
job
[
:tags
]
||
[],
...
...
spec/requests/ci/commits_spec.rb
View file @
546a3c65
...
@@ -7,7 +7,7 @@ describe "Commits" do
...
@@ -7,7 +7,7 @@ describe "Commits" do
describe
"GET /:project/refs/:ref_name/commits/:id/status.json"
do
describe
"GET /:project/refs/:ref_name/commits/:id/status.json"
do
before
do
before
do
get
status_ci_project_
ref_commits_path
(
@commit
.
project
,
@commit
.
ref
,
@commit
.
sha
),
format: :json
get
status_ci_project_
commits_path
(
@commit
.
project
,
@commit
.
sha
),
format: :json
end
end
it
{
expect
(
response
.
status
).
to
eq
(
200
)
}
it
{
expect
(
response
.
status
).
to
eq
(
200
)
}
...
...
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