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
Kazuhiko Shiozaki
gitlab-ce
Commits
317a7469
Commit
317a7469
authored
Oct 05, 2015
by
Kamil Trzcinski
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Make commit_spec run
parent
e3d870d7
Changes
13
Hide whitespace changes
Inline
Side-by-side
Showing
13 changed files
with
226 additions
and
208 deletions
+226
-208
app/models/ci/build.rb
app/models/ci/build.rb
+3
-1
app/models/ci/commit.rb
app/models/ci/commit.rb
+45
-30
app/services/ci/create_builds_service.rb
app/services/ci/create_builds_service.rb
+18
-21
app/services/ci/web_hook_service.rb
app/services/ci/web_hook_service.rb
+0
-2
app/views/ci/builds/show.html.haml
app/views/ci/builds/show.html.haml
+0
-5
app/views/ci/commits/show.html.haml
app/views/ci/commits/show.html.haml
+3
-8
db/schema.rb
db/schema.rb
+64
-37
lib/ci/gitlab_ci_yaml_processor.rb
lib/ci/gitlab_ci_yaml_processor.rb
+2
-2
spec/factories/ci/commits.rb
spec/factories/ci/commits.rb
+11
-5
spec/models/ci/build_spec.rb
spec/models/ci/build_spec.rb
+38
-13
spec/models/ci/commit_spec.rb
spec/models/ci/commit_spec.rb
+38
-84
spec/models/ci/project_services/mail_service_spec.rb
spec/models/ci/project_services/mail_service_spec.rb
+0
-0
spec/spec_helper.rb
spec/spec_helper.rb
+4
-0
No files found.
app/models/ci/build.rb
View file @
317a7469
...
@@ -80,6 +80,8 @@ module Ci
...
@@ -80,6 +80,8 @@ module Ci
def
retry
(
build
)
def
retry
(
build
)
new_build
=
Ci
::
Build
.
new
(
status: :pending
)
new_build
=
Ci
::
Build
.
new
(
status: :pending
)
new_build
.
ref
=
build
.
ref
new_build
.
tag
=
build
.
tag
new_build
.
options
=
build
.
options
new_build
.
options
=
build
.
options
new_build
.
commands
=
build
.
commands
new_build
.
commands
=
build
.
commands
new_build
.
tag_list
=
build
.
tag_list
new_build
.
tag_list
=
build
.
tag_list
...
@@ -141,7 +143,7 @@ module Ci
...
@@ -141,7 +143,7 @@ module Ci
state
:canceled
,
value:
'canceled'
state
:canceled
,
value:
'canceled'
end
end
delegate
:sha
,
:short_sha
,
:
before_sha
,
:ref
,
:
project
,
delegate
:sha
,
:short_sha
,
:project
,
to: :commit
,
prefix:
false
to: :commit
,
prefix:
false
def
trace_html
def
trace_html
...
...
app/models/ci/commit.rb
View file @
317a7469
...
@@ -58,14 +58,6 @@ module Ci
...
@@ -58,14 +58,6 @@ module Ci
end
end
end
end
def
new_branch?
before_sha
==
Ci
::
Git
::
BLANK_SHA
end
def
compare?
!
new_branch?
end
def
git_author_name
def
git_author_name
commit_data
.
author_name
if
commit_data
commit_data
.
author_name
if
commit_data
end
end
...
@@ -78,10 +70,6 @@ module Ci
...
@@ -78,10 +70,6 @@ module Ci
commit_data
.
message
if
commit_data
commit_data
.
message
if
commit_data
end
end
def
short_before_sha
Ci
::
Commit
.
truncate_sha
(
before_sha
)
end
def
short_sha
def
short_sha
Ci
::
Commit
.
truncate_sha
(
sha
)
Ci
::
Commit
.
truncate_sha
(
sha
)
end
end
...
@@ -99,7 +87,22 @@ module Ci
...
@@ -99,7 +87,22 @@ module Ci
def
create_builds
(
ref
,
tag
,
user
,
trigger_request
=
nil
)
def
create_builds
(
ref
,
tag
,
user
,
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
,
user
,
trigger_request
)
config_processor
.
stages
.
any?
do
|
stage
|
CreateBuildsService
.
new
.
execute
(
self
,
stage
,
ref
,
tag
,
user
,
trigger_request
).
present?
end
end
def
create_next_builds
(
ref
,
tag
,
user
,
trigger_request
)
return
if
skip_ci?
&&
trigger_request
.
blank?
return
unless
config_processor
stages
=
builds
.
where
(
ref:
ref
,
tag:
tag
,
trigger_request:
trigger_request
).
group_by
(
&
:stage
)
config_processor
.
stages
.
any?
do
|
stage
|
unless
stages
.
include?
(
stage
)
CreateBuildsService
.
new
.
execute
(
self
,
stage
,
ref
,
tag
,
user
,
trigger_request
).
present?
end
end
end
end
def
refs
def
refs
...
@@ -111,7 +114,14 @@ module Ci
...
@@ -111,7 +114,14 @@ module Ci
end
end
def
builds_without_retry
def
builds_without_retry
builds
.
latest
@builds_without_retry
||=
begin
grouped_builds
=
builds
.
group_by
(
&
:name
)
latest_builds
=
grouped_builds
.
map
do
|
name
,
builds
|
builds
.
sort_by
(
&
:id
).
last
end
latest_builds
.
sort_by
(
&
:stage_idx
)
end
end
end
def
retried_builds
def
retried_builds
...
@@ -125,32 +135,35 @@ module Ci
...
@@ -125,32 +135,35 @@ module Ci
return
'failed'
return
'failed'
elsif
builds
.
none?
elsif
builds
.
none?
return
'skipped'
return
'skipped'
end
elsif
success?
'success'
statuses
=
builds_without_retry
.
ignore_failures
.
pluck
(
:status
)
elsif
pending?
if
statuses
.
all?
{
|
status
|
status
==
'success'
}
'pending'
return
'success'
elsif
running?
elsif
statuses
.
all?
{
|
status
|
status
==
'pending'
}
'running'
return
'pending'
elsif
canceled?
elsif
statuses
.
include?
(
'running'
)
||
statuses
.
include?
(
'pending'
)
'canceled'
return
'running'
elsif
statuses
.
all?
{
|
status
|
status
==
'canceled'
}
return
'canceled'
else
else
return
'failed'
'failed'
end
end
end
end
def
pending?
def
pending?
status
==
'pending'
builds_without_retry
.
all?
do
|
build
|
build
.
pending?
end
end
end
def
running?
def
running?
status
==
'running'
builds_without_retry
.
any?
do
|
build
|
build
.
running?
||
build
.
pending?
end
end
end
def
success?
def
success?
status
==
'success'
builds_without_retry
.
all?
do
|
build
|
build
.
success?
||
build
.
ignored?
end
end
end
def
failed?
def
failed?
...
@@ -158,7 +171,9 @@ module Ci
...
@@ -158,7 +171,9 @@ module Ci
end
end
def
canceled?
def
canceled?
status
==
'canceled'
builds_without_retry
.
all?
do
|
build
|
build
.
canceled?
end
end
end
def
duration
def
duration
...
...
app/services/ci/create_builds_service.rb
View file @
317a7469
module
Ci
module
Ci
class
CreateBuildsService
class
CreateBuildsService
def
execute
(
commit
,
ref
,
tag
,
user
,
config_processor
,
trigger_request
)
def
execute
(
commit
,
stage
,
ref
,
tag
,
user
,
trigger_request
)
config_processor
.
stages
.
any?
do
|
stage
|
builds_attrs
=
commit
.
config_processor
.
builds_for_stage_and_ref
(
stage
,
ref
,
tag
)
builds_attrs
=
config_processor
.
builds_for_stage_and_ref
(
stage
,
ref
,
tag
)
builds_attrs
.
map
do
|
build_attrs
|
builds_attrs
.
map
do
|
build_attrs
|
# don't create the same build twice
build_attrs
.
slice!
(
:name
,
unless
commit
.
builds
.
find_by_name_and_trigger_request
(
name:
build_attrs
[
:name
],
ref:
ref
,
tag:
tag
,
trigger_request:
trigger_request
)
:commands
,
commit
.
builds
.
create!
({
:tag_list
,
name:
build_attrs
[
:name
],
:options
,
commands:
build_attrs
[
:script
],
:allow_failure
,
tag_list:
build_attrs
[
:tags
],
:stage
,
options:
build_attrs
[
:options
],
:stage_idx
)
allow_failure:
build_attrs
[
:allow_failure
],
stage:
build_attrs
[
:stage
],
build_attrs
.
merge!
(
ref:
ref
,
stage_idx:
build_attrs
[
:stage_idx
],
tag:
tag
,
trigger_request:
trigger_request
,
trigger_request:
trigger_request
,
ref:
ref
,
user:
user
)
tag:
tag
,
user:
user
,
commit
.
builds
.
create!
(
build_attrs
)
})
end
end
end
end
end
end
end
end
...
...
app/services/ci/web_hook_service.rb
View file @
317a7469
...
@@ -28,8 +28,6 @@ module Ci
...
@@ -28,8 +28,6 @@ module Ci
gitlab_url:
project
.
gitlab_url
,
gitlab_url:
project
.
gitlab_url
,
ref:
build
.
ref
,
ref:
build
.
ref
,
sha:
build
.
sha
,
sha:
build
.
sha
,
before_sha:
build
.
before_sha
,
push_data:
build
.
commit
.
push_data
})
})
end
end
end
end
...
...
app/views/ci/builds/show.html.haml
View file @
317a7469
...
@@ -122,11 +122,6 @@
...
@@ -122,11 +122,6 @@
Commit
Commit
.pull-right
.pull-right
%small
#{
build_commit_link
@build
}
%small
#{
build_commit_link
@build
}
-
if
@build
.
commit
.
compare?
%p
%span
.attr-name
Compare:
#{
build_compare_link
@build
}
%p
%p
%span
.attr-name
Branch:
%span
.attr-name
Branch:
#{
build_ref_link
@build
}
#{
build_ref_link
@build
}
...
...
app/views/ci/commits/show.html.haml
View file @
317a7469
...
@@ -9,14 +9,9 @@
...
@@ -9,14 +9,9 @@
.gray-content-block.second-block
.gray-content-block.second-block
.row
.row
.col-sm-6
.col-sm-6
-
if
@commit
.
compare?
%p
%p
%span
.attr-name
Commit:
%span
.attr-name
Compare:
#{
gitlab_commit_link
(
@project
,
@commit
.
sha
)
}
#{
gitlab_compare_link
(
@project
,
@commit
.
short_before_sha
,
@commit
.
short_sha
)
}
-
else
%p
%span
.attr-name
Commit:
#{
gitlab_commit_link
(
@project
,
@commit
.
sha
)
}
.col-sm-6
.col-sm-6
-
if
@commit
.
git_author_name
||
@commit
.
git_author_email
-
if
@commit
.
git_author_name
||
@commit
.
git_author_email
%p
%p
...
...
db/schema.rb
View file @
317a7469
...
@@ -11,10 +11,7 @@
...
@@ -11,10 +11,7 @@
#
#
# It's strongly recommended that you check this file into your version control system.
# It's strongly recommended that you check this file into your version control system.
ActiveRecord
::
Schema
.
define
(
version:
20150930095736
)
do
ActiveRecord
::
Schema
.
define
(
version:
20151005075649
)
do
# These are extensions that must be enabled in order to support this database
enable_extension
"plpgsql"
create_table
"abuse_reports"
,
force:
true
do
|
t
|
create_table
"abuse_reports"
,
force:
true
do
|
t
|
t
.
integer
"reporter_id"
t
.
integer
"reporter_id"
...
@@ -45,8 +42,8 @@ ActiveRecord::Schema.define(version: 20150930095736) do
...
@@ -45,8 +42,8 @@ ActiveRecord::Schema.define(version: 20150930095736) do
t
.
string
"after_sign_out_path"
t
.
string
"after_sign_out_path"
t
.
integer
"session_expire_delay"
,
default:
10080
,
null:
false
t
.
integer
"session_expire_delay"
,
default:
10080
,
null:
false
t
.
text
"import_sources"
t
.
text
"import_sources"
t
.
text
"help_page_text"
t
.
boolean
"ci_enabled"
,
default:
true
,
null:
false
t
.
boolean
"ci_enabled"
,
default:
true
,
null:
false
t
.
text
"help_page_text"
end
end
create_table
"audit_events"
,
force:
true
do
|
t
|
create_table
"audit_events"
,
force:
true
do
|
t
|
...
@@ -85,37 +82,60 @@ ActiveRecord::Schema.define(version: 20150930095736) do
...
@@ -85,37 +82,60 @@ ActiveRecord::Schema.define(version: 20150930095736) do
t
.
integer
"project_id"
t
.
integer
"project_id"
t
.
string
"status"
t
.
string
"status"
t
.
datetime
"finished_at"
t
.
datetime
"finished_at"
t
.
text
"trace"
t
.
text
"trace"
,
limit:
2147483647
t
.
datetime
"created_at"
t
.
datetime
"created_at"
t
.
datetime
"updated_at"
t
.
datetime
"updated_at"
t
.
datetime
"started_at"
t
.
datetime
"started_at"
t
.
integer
"runner_id"
t
.
integer
"runner_id"
t
.
float
"coverage"
t
.
float
"coverage"
,
limit:
24
t
.
integer
"commit_id"
t
.
integer
"commit_id"
t
.
text
"commands"
t
.
text
"commands"
t
.
integer
"job_id"
t
.
integer
"job_id"
t
.
string
"name"
t
.
string
"name"
t
.
boolean
"deploy"
,
default:
false
t
.
boolean
"deploy"
,
default:
false
t
.
text
"options"
t
.
text
"options"
t
.
boolean
"allow_failure"
,
default:
false
,
null:
false
t
.
boolean
"allow_failure"
,
default:
false
,
null:
false
t
.
string
"stage"
t
.
string
"stage"
t
.
integer
"trigger_request_id"
t
.
integer
"trigger_request_id"
t
.
integer
"gl_project_id"
t
.
integer
"stage_idx"
t
.
boolean
"tag"
t
.
string
"ref"
t
.
text
"push_data"
t
.
integer
"user_id"
end
end
add_index
"ci_builds"
,
[
"commit_id"
,
"name"
],
name:
"index_ci_builds_on_commit_id_and_name"
,
using: :btree
add_index
"ci_builds"
,
[
"commit_id"
,
"stage_idx"
,
"created_at"
],
name:
"index_ci_builds_on_commit_id_and_stage_idx_and_created_at"
,
using: :btree
add_index
"ci_builds"
,
[
"commit_id"
],
name:
"index_ci_builds_on_commit_id"
,
using: :btree
add_index
"ci_builds"
,
[
"commit_id"
],
name:
"index_ci_builds_on_commit_id"
,
using: :btree
add_index
"ci_builds"
,
[
"project_id"
,
"commit_id"
],
name:
"index_ci_builds_on_project_id_and_commit_id"
,
using: :btree
add_index
"ci_builds"
,
[
"project_id"
,
"commit_id"
],
name:
"index_ci_builds_on_project_id_and_commit_id"
,
using: :btree
add_index
"ci_builds"
,
[
"project_id"
],
name:
"index_ci_builds_on_project_id"
,
using: :btree
add_index
"ci_builds"
,
[
"project_id"
],
name:
"index_ci_builds_on_project_id"
,
using: :btree
add_index
"ci_builds"
,
[
"runner_id"
],
name:
"index_ci_builds_on_runner_id"
,
using: :btree
add_index
"ci_builds"
,
[
"runner_id"
],
name:
"index_ci_builds_on_runner_id"
,
using: :btree
create_table
"ci_commit_statuses"
,
force:
true
do
|
t
|
t
.
integer
"commit_id"
t
.
string
"sha"
t
.
string
"ref"
t
.
string
"state"
t
.
string
"target_url"
t
.
string
"description"
t
.
string
"context"
,
default:
"default"
t
.
datetime
"created_at"
t
.
datetime
"updated_at"
end
add_index
"ci_commit_statuses"
,
[
"commit_id"
,
"context"
,
"ref"
],
name:
"index_ci_commit_statuses_on_commit_id_and_context_and_ref"
,
using: :btree
add_index
"ci_commit_statuses"
,
[
"commit_id"
,
"ref"
],
name:
"index_ci_commit_statuses_on_commit_id_and_ref"
,
using: :btree
create_table
"ci_commits"
,
force:
true
do
|
t
|
create_table
"ci_commits"
,
force:
true
do
|
t
|
t
.
integer
"project_id"
t
.
integer
"project_id"
t
.
string
"ref"
t
.
string
"ref"
t
.
string
"sha"
t
.
string
"sha"
t
.
string
"before_sha"
t
.
string
"before_sha"
t
.
text
"push_data"
t
.
text
"push_data"
,
limit:
16777215
t
.
datetime
"created_at"
t
.
datetime
"created_at"
t
.
datetime
"updated_at"
t
.
datetime
"updated_at"
t
.
boolean
"tag"
,
default:
false
t
.
boolean
"tag"
,
default:
false
t
.
text
"yaml_errors"
t
.
text
"yaml_errors"
t
.
datetime
"committed_at"
t
.
datetime
"committed_at"
t
.
integer
"gl_project_id"
t
.
integer
"gl_project_id"
...
@@ -134,6 +154,7 @@ ActiveRecord::Schema.define(version: 20150930095736) do
...
@@ -134,6 +154,7 @@ ActiveRecord::Schema.define(version: 20150930095736) do
t
.
text
"description"
t
.
text
"description"
t
.
datetime
"created_at"
t
.
datetime
"created_at"
t
.
datetime
"updated_at"
t
.
datetime
"updated_at"
t
.
integer
"gl_project_id"
end
end
add_index
"ci_events"
,
[
"created_at"
],
name:
"index_ci_events_on_created_at"
,
using: :btree
add_index
"ci_events"
,
[
"created_at"
],
name:
"index_ci_events_on_created_at"
,
using: :btree
...
@@ -181,10 +202,11 @@ ActiveRecord::Schema.define(version: 20150930095736) do
...
@@ -181,10 +202,11 @@ ActiveRecord::Schema.define(version: 20150930095736) do
end
end
create_table
"ci_runner_projects"
,
force:
true
do
|
t
|
create_table
"ci_runner_projects"
,
force:
true
do
|
t
|
t
.
integer
"runner_id"
,
null:
false
t
.
integer
"runner_id"
,
null:
false
t
.
integer
"project_id"
,
null:
false
t
.
integer
"project_id"
,
null:
false
t
.
datetime
"created_at"
t
.
datetime
"created_at"
t
.
datetime
"updated_at"
t
.
datetime
"updated_at"
t
.
integer
"gl_project_id"
end
end
add_index
"ci_runner_projects"
,
[
"project_id"
],
name:
"index_ci_runner_projects_on_project_id"
,
using: :btree
add_index
"ci_runner_projects"
,
[
"project_id"
],
name:
"index_ci_runner_projects_on_project_id"
,
using: :btree
...
@@ -208,11 +230,12 @@ ActiveRecord::Schema.define(version: 20150930095736) do
...
@@ -208,11 +230,12 @@ ActiveRecord::Schema.define(version: 20150930095736) do
create_table
"ci_services"
,
force:
true
do
|
t
|
create_table
"ci_services"
,
force:
true
do
|
t
|
t
.
string
"type"
t
.
string
"type"
t
.
string
"title"
t
.
string
"title"
t
.
integer
"project_id"
,
null:
false
t
.
integer
"project_id"
,
null:
false
t
.
datetime
"created_at"
t
.
datetime
"created_at"
t
.
datetime
"updated_at"
t
.
datetime
"updated_at"
t
.
boolean
"active"
,
default:
false
,
null:
false
t
.
boolean
"active"
,
default:
false
,
null:
false
t
.
text
"properties"
t
.
text
"properties"
t
.
integer
"gl_project_id"
end
end
add_index
"ci_services"
,
[
"project_id"
],
name:
"index_ci_services_on_project_id"
,
using: :btree
add_index
"ci_services"
,
[
"project_id"
],
name:
"index_ci_services_on_project_id"
,
using: :btree
...
@@ -257,10 +280,11 @@ ActiveRecord::Schema.define(version: 20150930095736) do
...
@@ -257,10 +280,11 @@ ActiveRecord::Schema.define(version: 20150930095736) do
create_table
"ci_triggers"
,
force:
true
do
|
t
|
create_table
"ci_triggers"
,
force:
true
do
|
t
|
t
.
string
"token"
t
.
string
"token"
t
.
integer
"project_id"
,
null:
false
t
.
integer
"project_id"
,
null:
false
t
.
datetime
"deleted_at"
t
.
datetime
"deleted_at"
t
.
datetime
"created_at"
t
.
datetime
"created_at"
t
.
datetime
"updated_at"
t
.
datetime
"updated_at"
t
.
integer
"gl_project_id"
end
end
add_index
"ci_triggers"
,
[
"deleted_at"
],
name:
"index_ci_triggers_on_deleted_at"
,
using: :btree
add_index
"ci_triggers"
,
[
"deleted_at"
],
name:
"index_ci_triggers_on_deleted_at"
,
using: :btree
...
@@ -272,15 +296,17 @@ ActiveRecord::Schema.define(version: 20150930095736) do
...
@@ -272,15 +296,17 @@ ActiveRecord::Schema.define(version: 20150930095736) do
t
.
text
"encrypted_value"
t
.
text
"encrypted_value"
t
.
string
"encrypted_value_salt"
t
.
string
"encrypted_value_salt"
t
.
string
"encrypted_value_iv"
t
.
string
"encrypted_value_iv"
t
.
integer
"gl_project_id"
end
end
add_index
"ci_variables"
,
[
"project_id"
],
name:
"index_ci_variables_on_project_id"
,
using: :btree
add_index
"ci_variables"
,
[
"project_id"
],
name:
"index_ci_variables_on_project_id"
,
using: :btree
create_table
"ci_web_hooks"
,
force:
true
do
|
t
|
create_table
"ci_web_hooks"
,
force:
true
do
|
t
|
t
.
string
"url"
,
null:
false
t
.
string
"url"
,
null:
false
t
.
integer
"project_id"
,
null:
false
t
.
integer
"project_id"
,
null:
false
t
.
datetime
"created_at"
t
.
datetime
"created_at"
t
.
datetime
"updated_at"
t
.
datetime
"updated_at"
t
.
integer
"gl_project_id"
end
end
create_table
"deploy_keys_projects"
,
force:
true
do
|
t
|
create_table
"deploy_keys_projects"
,
force:
true
do
|
t
|
...
@@ -426,9 +452,9 @@ ActiveRecord::Schema.define(version: 20150930095736) do
...
@@ -426,9 +452,9 @@ ActiveRecord::Schema.define(version: 20150930095736) do
create_table
"merge_request_diffs"
,
force:
true
do
|
t
|
create_table
"merge_request_diffs"
,
force:
true
do
|
t
|
t
.
string
"state"
t
.
string
"state"
t
.
text
"st_commits"
t
.
text
"st_commits"
,
limit:
2147483647
t
.
text
"st_diffs"
t
.
text
"st_diffs"
,
limit:
2147483647
t
.
integer
"merge_request_id"
,
null:
false
t
.
integer
"merge_request_id"
,
null:
false
t
.
datetime
"created_at"
t
.
datetime
"created_at"
t
.
datetime
"updated_at"
t
.
datetime
"updated_at"
end
end
...
@@ -511,8 +537,8 @@ ActiveRecord::Schema.define(version: 20150930095736) do
...
@@ -511,8 +537,8 @@ ActiveRecord::Schema.define(version: 20150930095736) do
t
.
string
"line_code"
t
.
string
"line_code"
t
.
string
"commit_id"
t
.
string
"commit_id"
t
.
integer
"noteable_id"
t
.
integer
"noteable_id"
t
.
boolean
"system"
,
default:
false
,
null:
false
t
.
boolean
"system"
,
default:
false
,
null:
false
t
.
text
"st_diff"
t
.
text
"st_diff"
,
limit:
2147483647
t
.
integer
"updated_by_id"
t
.
integer
"updated_by_id"
end
end
...
@@ -581,25 +607,26 @@ ActiveRecord::Schema.define(version: 20150930095736) do
...
@@ -581,25 +607,26 @@ ActiveRecord::Schema.define(version: 20150930095736) do
t
.
datetime
"created_at"
t
.
datetime
"created_at"
t
.
datetime
"updated_at"
t
.
datetime
"updated_at"
t
.
integer
"creator_id"
t
.
integer
"creator_id"
t
.
boolean
"issues_enabled"
,
default:
true
,
null:
false
t
.
boolean
"issues_enabled"
,
default:
true
,
null:
false
t
.
boolean
"wall_enabled"
,
default:
true
,
null:
false
t
.
boolean
"wall_enabled"
,
default:
true
,
null:
false
t
.
boolean
"merge_requests_enabled"
,
default:
true
,
null:
false
t
.
boolean
"merge_requests_enabled"
,
default:
true
,
null:
false
t
.
boolean
"wiki_enabled"
,
default:
true
,
null:
false
t
.
boolean
"wiki_enabled"
,
default:
true
,
null:
false
t
.
integer
"namespace_id"
t
.
integer
"namespace_id"
t
.
string
"issues_tracker"
,
default:
"gitlab"
,
null:
false
t
.
string
"issues_tracker"
,
default:
"gitlab"
,
null:
false
t
.
string
"issues_tracker_id"
t
.
string
"issues_tracker_id"
t
.
boolean
"snippets_enabled"
,
default:
true
,
null:
false
t
.
boolean
"snippets_enabled"
,
default:
true
,
null:
false
t
.
datetime
"last_activity_at"
t
.
datetime
"last_activity_at"
t
.
string
"import_url"
t
.
string
"import_url"
t
.
integer
"visibility_level"
,
default:
0
,
null:
false
t
.
integer
"visibility_level"
,
default:
0
,
null:
false
t
.
boolean
"archived"
,
default:
false
,
null:
false
t
.
boolean
"archived"
,
default:
false
,
null:
false
t
.
string
"avatar"
t
.
string
"avatar"
t
.
string
"import_status"
t
.
string
"import_status"
t
.
float
"repository_size"
,
default:
0.0
t
.
float
"repository_size"
,
limit:
24
,
default:
0.0
t
.
integer
"star_count"
,
default:
0
,
null:
false
t
.
integer
"star_count"
,
default:
0
,
null:
false
t
.
string
"import_type"
t
.
string
"import_type"
t
.
string
"import_source"
t
.
string
"import_source"
t
.
integer
"commit_count"
,
default:
0
t
.
integer
"commit_count"
,
default:
0
t
.
boolean
"shared_runners_enabled"
,
default:
false
end
end
add_index
"projects"
,
[
"created_at"
,
"id"
],
name:
"index_projects_on_created_at_and_id"
,
using: :btree
add_index
"projects"
,
[
"created_at"
,
"id"
],
name:
"index_projects_on_created_at_and_id"
,
using: :btree
...
@@ -651,15 +678,15 @@ ActiveRecord::Schema.define(version: 20150930095736) do
...
@@ -651,15 +678,15 @@ ActiveRecord::Schema.define(version: 20150930095736) do
create_table
"snippets"
,
force:
true
do
|
t
|
create_table
"snippets"
,
force:
true
do
|
t
|
t
.
string
"title"
t
.
string
"title"
t
.
text
"content"
t
.
text
"content"
,
limit:
2147483647
t
.
integer
"author_id"
,
null:
false
t
.
integer
"author_id"
,
null:
false
t
.
integer
"project_id"
t
.
integer
"project_id"
t
.
datetime
"created_at"
t
.
datetime
"created_at"
t
.
datetime
"updated_at"
t
.
datetime
"updated_at"
t
.
string
"file_name"
t
.
string
"file_name"
t
.
datetime
"expires_at"
t
.
datetime
"expires_at"
t
.
string
"type"
t
.
string
"type"
t
.
integer
"visibility_level"
,
default:
0
,
null:
false
t
.
integer
"visibility_level"
,
default:
0
,
null:
false
end
end
add_index
"snippets"
,
[
"author_id"
],
name:
"index_snippets_on_author_id"
,
using: :btree
add_index
"snippets"
,
[
"author_id"
],
name:
"index_snippets_on_author_id"
,
using: :btree
...
...
lib/ci/gitlab_ci_yaml_processor.rb
View file @
317a7469
...
@@ -87,8 +87,8 @@ module Ci
...
@@ -87,8 +87,8 @@ module Ci
{
{
stage_idx:
stages
.
index
(
job
[
:stage
]),
stage_idx:
stages
.
index
(
job
[
:stage
]),
stage:
job
[
:stage
],
stage:
job
[
:stage
],
script
:
"
#{
@before_script
.
join
(
"
\n
"
)
}
\n
#{
normalize_script
(
job
[
:script
])
}
"
,
commands
:
"
#{
@before_script
.
join
(
"
\n
"
)
}
\n
#{
normalize_script
(
job
[
:script
])
}
"
,
tag
s
:
job
[
:tags
]
||
[],
tag
_list
:
job
[
:tags
]
||
[],
name:
name
,
name:
name
,
only:
job
[
:only
],
only:
job
[
:only
],
except:
job
[
:except
],
except:
job
[
:except
],
...
...
spec/factories/ci/commits.rb
View file @
317a7469
...
@@ -23,20 +23,26 @@ FactoryGirl.define do
...
@@ -23,20 +23,26 @@ FactoryGirl.define do
gl_project
factory: :empty_project
gl_project
factory: :empty_project
factory
:ci_commit_without_jobs
do
factory
:ci_commit_without_jobs
do
after
(
:
create
)
do
|
commit
,
evaluator
|
after
(
:
build
)
do
|
commit
|
allow
(
commit
).
to
receive
(
:ci_yaml_file
)
{
YAML
.
dump
({})
}
allow
(
commit
).
to
receive
(
:ci_yaml_file
)
{
YAML
.
dump
({})
}
end
end
end
end
factory
:ci_commit_with_one_job
do
factory
:ci_commit_with_one_job
do
after
(
:
create
)
do
|
commit
,
evaluator
|
after
(
:
build
)
do
|
commit
|
allow
(
commit
).
to
receive
(
:ci_yaml_file
)
{
YAML
.
dump
({
rspec:
{
script:
"ls"
}
})
}
allow
(
commit
).
to
receive
(
:ci_yaml_file
)
{
YAML
.
dump
({
rspec:
{
script:
"ls"
}
})
}
end
end
end
end
factory
:ci_commit_with_two_jobs
do
factory
:ci_commit_with_two_jobs
do
after
(
:create
)
do
|
commit
,
evaluator
|
after
(
:build
)
do
|
commit
|
allow
(
commit
).
to
receive
(
:ci_yaml_file
)
{
YAML
.
dump
({
rspec:
{
script:
"ls"
},
spinach:
{
script:
"ls"
}
})
}
allow
(
commit
).
to
receive
(
:ci_yaml_file
)
{
YAML
.
dump
({
rspec:
{
script:
"ls"
},
spinach:
{
script:
"ls"
}})
}
end
end
factory
:ci_commit_yaml_stub
do
after
(
:build
)
do
|
commit
|
allow
(
commit
).
to
receive
(
:ci_yaml_file
)
{
File
.
read
(
Rails
.
root
.
join
(
'spec/support/gitlab_stubs/gitlab_ci.yml'
))
}
end
end
end
end
end
end
...
...
spec/models/ci/build_spec.rb
View file @
317a7469
...
@@ -28,11 +28,14 @@ require 'spec_helper'
...
@@ -28,11 +28,14 @@ require 'spec_helper'
describe
Ci
::
Build
do
describe
Ci
::
Build
do
let
(
:project
)
{
FactoryGirl
.
create
:ci_project
}
let
(
:project
)
{
FactoryGirl
.
create
:ci_project
}
let
(
:gl_project
)
{
FactoryGirl
.
create
:empty_project
,
gitlab_ci_project:
project
}
let
(
:gl_project
)
{
FactoryGirl
.
create
:empty_project
,
gitlab_ci_project:
project
}
let
(
:commit
)
{
FactoryGirl
.
create
:ci_commit
,
gl_project:
gl_project
}
let
(
:commit
)
{
FactoryGirl
.
create
:ci_commit
_yaml_stub
,
gl_project:
gl_project
}
let
(
:build
)
{
FactoryGirl
.
create
:ci_build
,
commit:
commit
}
let
(
:build
)
{
FactoryGirl
.
create
:ci_build
,
commit:
commit
}
subject
{
build
}
it
{
is_expected
.
to
belong_to
(
:commit
)
}
it
{
is_expected
.
to
belong_to
(
:commit
)
}
it
{
is_expected
.
to
belong_to
(
:user
)
}
it
{
is_expected
.
to
validate_presence_of
:status
}
it
{
is_expected
.
to
validate_presence_of
:status
}
it
{
is_expected
.
to
validate_presence_of
:ref
}
it
{
is_expected
.
to
respond_to
:success?
}
it
{
is_expected
.
to
respond_to
:success?
}
it
{
is_expected
.
to
respond_to
:failed?
}
it
{
is_expected
.
to
respond_to
:failed?
}
...
@@ -236,12 +239,6 @@ describe Ci::Build do
...
@@ -236,12 +239,6 @@ describe Ci::Build do
it
{
is_expected
.
to
eq
(
options
)
}
it
{
is_expected
.
to
eq
(
options
)
}
end
end
describe
:ref
do
subject
{
build
.
ref
}
it
{
is_expected
.
to
eq
(
commit
.
ref
)
}
end
describe
:sha
do
describe
:sha
do
subject
{
build
.
sha
}
subject
{
build
.
sha
}
...
@@ -254,12 +251,6 @@ describe Ci::Build do
...
@@ -254,12 +251,6 @@ describe Ci::Build do
it
{
is_expected
.
to
eq
(
commit
.
short_sha
)
}
it
{
is_expected
.
to
eq
(
commit
.
short_sha
)
}
end
end
describe
:before_sha
do
subject
{
build
.
before_sha
}
it
{
is_expected
.
to
eq
(
commit
.
before_sha
)
}
end
describe
:allow_git_fetch
do
describe
:allow_git_fetch
do
subject
{
build
.
allow_git_fetch
}
subject
{
build
.
allow_git_fetch
}
...
@@ -359,4 +350,38 @@ describe Ci::Build do
...
@@ -359,4 +350,38 @@ describe Ci::Build do
end
end
end
end
end
end
describe
:project_recipients
do
let
(
:pusher_email
)
{
'pusher@gitlab.test'
}
let
(
:user
)
{
User
.
new
(
notification_email:
pusher_email
)
}
subject
{
build
.
project_recipients
}
before
do
build
.
update_attributes
(
user:
user
)
end
it
'should return pusher_email as only recipient when no additional recipients are given'
do
project
.
update_attributes
(
email_add_pusher:
true
,
email_recipients:
''
)
is_expected
.
to
eq
([
pusher_email
])
end
it
'should return pusher_email and additional recipients'
do
project
.
update_attributes
(
email_add_pusher:
true
,
email_recipients:
'rec1 rec2'
)
is_expected
.
to
eq
([
'rec1'
,
'rec2'
,
pusher_email
])
end
it
'should return recipients'
do
project
.
update_attributes
(
email_add_pusher:
false
,
email_recipients:
'rec1 rec2'
)
is_expected
.
to
eq
([
'rec1'
,
'rec2'
])
end
it
'should return unique recipients only'
do
project
.
update_attributes
(
email_add_pusher:
true
,
email_recipients:
"rec1 rec1
#{
pusher_email
}
"
)
is_expected
.
to
eq
([
'rec1'
,
pusher_email
])
end
end
end
end
spec/models/ci/commit_spec.rb
View file @
317a7469
...
@@ -21,15 +21,10 @@ describe Ci::Commit do
...
@@ -21,15 +21,10 @@ describe Ci::Commit do
let
(
:project
)
{
FactoryGirl
.
create
:ci_project
}
let
(
:project
)
{
FactoryGirl
.
create
:ci_project
}
let
(
:gl_project
)
{
FactoryGirl
.
create
:empty_project
,
gitlab_ci_project:
project
}
let
(
:gl_project
)
{
FactoryGirl
.
create
:empty_project
,
gitlab_ci_project:
project
}
let
(
:commit
)
{
FactoryGirl
.
create
:ci_commit
,
gl_project:
gl_project
}
let
(
:commit
)
{
FactoryGirl
.
create
:ci_commit
,
gl_project:
gl_project
}
let
(
:commit_with_project
)
{
FactoryGirl
.
create
:ci_commit
,
gl_project:
gl_project
}
let
(
:config_processor
)
{
Ci
::
GitlabCiYamlProcessor
.
new
(
gitlab_ci_yaml
)
}
it
{
is_expected
.
to
belong_to
(
:gl_project
)
}
it
{
is_expected
.
to
belong_to
(
:gl_project
)
}
it
{
is_expected
.
to
have_many
(
:builds
)
}
it
{
is_expected
.
to
have_many
(
:builds
)
}
it
{
is_expected
.
to
validate_presence_of
:before_sha
}
it
{
is_expected
.
to
validate_presence_of
:sha
}
it
{
is_expected
.
to
validate_presence_of
:sha
}
it
{
is_expected
.
to
validate_presence_of
:ref
}
it
{
is_expected
.
to
validate_presence_of
:push_data
}
it
{
is_expected
.
to
respond_to
:git_author_name
}
it
{
is_expected
.
to
respond_to
:git_author_name
}
it
{
is_expected
.
to
respond_to
:git_author_email
}
it
{
is_expected
.
to
respond_to
:git_author_email
}
...
@@ -59,53 +54,6 @@ describe Ci::Commit do
...
@@ -59,53 +54,6 @@ describe Ci::Commit do
end
end
end
end
describe
:project_recipients
do
context
'always sending notification'
do
it
'should return commit_pusher_email as only recipient when no additional recipients are given'
do
project
=
FactoryGirl
.
create
:ci_project
,
email_add_pusher:
true
,
email_recipients:
''
gl_project
=
FactoryGirl
.
create
:empty_project
,
gitlab_ci_project:
project
commit
=
FactoryGirl
.
create
:ci_commit
,
gl_project:
gl_project
expected
=
'commit_pusher_email'
allow
(
commit
).
to
receive
(
:push_data
)
{
{
user_email:
expected
}
}
expect
(
commit
.
project_recipients
).
to
eq
([
expected
])
end
it
'should return commit_pusher_email and additional recipients'
do
project
=
FactoryGirl
.
create
:ci_project
,
email_add_pusher:
true
,
email_recipients:
'rec1 rec2'
gl_project
=
FactoryGirl
.
create
:empty_project
,
gitlab_ci_project:
project
commit
=
FactoryGirl
.
create
:ci_commit
,
gl_project:
gl_project
expected
=
'commit_pusher_email'
allow
(
commit
).
to
receive
(
:push_data
)
{
{
user_email:
expected
}
}
expect
(
commit
.
project_recipients
).
to
eq
([
'rec1'
,
'rec2'
,
expected
])
end
it
'should return recipients'
do
project
=
FactoryGirl
.
create
:ci_project
,
email_add_pusher:
false
,
email_recipients:
'rec1 rec2'
gl_project
=
FactoryGirl
.
create
:empty_project
,
gitlab_ci_project:
project
commit
=
FactoryGirl
.
create
:ci_commit
,
gl_project:
gl_project
expect
(
commit
.
project_recipients
).
to
eq
([
'rec1'
,
'rec2'
])
end
it
'should return unique recipients only'
do
project
=
FactoryGirl
.
create
:ci_project
,
email_add_pusher:
true
,
email_recipients:
'rec1 rec1 rec2'
gl_project
=
FactoryGirl
.
create
:empty_project
,
gitlab_ci_project:
project
commit
=
FactoryGirl
.
create
:ci_commit
,
gl_project:
gl_project
expected
=
'rec2'
allow
(
commit
).
to
receive
(
:push_data
)
{
{
user_email:
expected
}
}
expect
(
commit
.
project_recipients
).
to
eq
([
'rec1'
,
'rec2'
])
end
end
end
describe
:valid_commit_sha
do
describe
:valid_commit_sha
do
context
'commit.sha can not start with 00000000'
do
context
'commit.sha can not start with 00000000'
do
before
do
before
do
...
@@ -117,14 +65,6 @@ describe Ci::Commit do
...
@@ -117,14 +65,6 @@ describe Ci::Commit do
end
end
end
end
describe
:compare?
do
subject
{
commit_with_project
.
compare?
}
context
'if commit.before_sha are not nil'
do
it
{
is_expected
.
to
be_truthy
}
end
end
describe
:short_sha
do
describe
:short_sha
do
subject
{
commit
.
short_before_sha
}
subject
{
commit
.
short_before_sha
}
...
@@ -144,36 +84,51 @@ describe Ci::Commit do
...
@@ -144,36 +84,51 @@ describe Ci::Commit do
end
end
describe
:create_next_builds
do
describe
:create_next_builds
do
before
do
end
allow
(
commit
).
to
receive
(
:config_processor
).
and_return
(
config_processor
)
describe
:create_builds
do
let
(
:commit
)
{
FactoryGirl
.
create
:ci_commit_yaml_stub
,
gl_project:
gl_project
}
def
create_builds
(
trigger_request
=
nil
)
commit
.
create_builds
(
'master'
,
false
,
nil
,
trigger_request
)
end
end
it
"creates builds for next type"
do
def
create_next_builds
(
trigger_request
=
nil
)
expect
(
commit
.
create_builds
).
to
be_truthy
commit
.
create_next_builds
(
'master'
,
false
,
nil
,
trigger_request
)
end
it
'creates builds'
do
expect
(
create_builds
).
to
be_truthy
commit
.
builds
.
reload
commit
.
builds
.
reload
expect
(
commit
.
builds
.
size
).
to
eq
(
2
)
expect
(
commit
.
builds
.
size
).
to
eq
(
2
)
expect
(
c
ommit
.
create_next_builds
(
nil
)
).
to
be_truthy
expect
(
c
reate_next_builds
).
to
be_truthy
commit
.
builds
.
reload
commit
.
builds
.
reload
expect
(
commit
.
builds
.
size
).
to
eq
(
4
)
expect
(
commit
.
builds
.
size
).
to
eq
(
4
)
expect
(
c
ommit
.
create_next_builds
(
nil
)
).
to
be_truthy
expect
(
c
reate_next_builds
).
to
be_truthy
commit
.
builds
.
reload
commit
.
builds
.
reload
expect
(
commit
.
builds
.
size
).
to
eq
(
5
)
expect
(
commit
.
builds
.
size
).
to
eq
(
5
)
expect
(
c
ommit
.
create_next_builds
(
nil
)
).
to
be_falsey
expect
(
c
reate_next_builds
).
to
be_falsey
end
end
end
describe
:create_builds
do
context
'for different ref'
do
before
do
def
create_develop_builds
allow
(
commit
).
to
receive
(
:config_processor
).
and_return
(
config_processor
)
commit
.
create_builds
(
'develop'
,
false
,
nil
,
nil
)
end
end
it
'creates builds'
do
it
'creates builds'
do
expect
(
commit
.
create_builds
).
to
be_truthy
expect
(
create_builds
).
to
be_truthy
commit
.
builds
.
reload
commit
.
builds
.
reload
expect
(
commit
.
builds
.
size
).
to
eq
(
2
)
expect
(
commit
.
builds
.
size
).
to
eq
(
2
)
expect
(
create_develop_builds
).
to
be_truthy
commit
.
builds
.
reload
expect
(
commit
.
builds
.
size
).
to
eq
(
4
)
expect
(
commit
.
refs
.
size
).
to
eq
(
2
)
expect
(
commit
.
builds
.
pluck
(
:name
).
uniq
.
size
).
to
eq
(
2
)
end
end
end
context
'for build triggers'
do
context
'for build triggers'
do
...
@@ -181,40 +136,39 @@ describe Ci::Commit do
...
@@ -181,40 +136,39 @@ describe Ci::Commit do
let
(
:trigger_request
)
{
FactoryGirl
.
create
:ci_trigger_request
,
commit:
commit
,
trigger:
trigger
}
let
(
:trigger_request
)
{
FactoryGirl
.
create
:ci_trigger_request
,
commit:
commit
,
trigger:
trigger
}
it
'creates builds'
do
it
'creates builds'
do
expect
(
c
ommit
.
c
reate_builds
(
trigger_request
)).
to
be_truthy
expect
(
create_builds
(
trigger_request
)).
to
be_truthy
commit
.
builds
.
reload
commit
.
builds
.
reload
expect
(
commit
.
builds
.
size
).
to
eq
(
2
)
expect
(
commit
.
builds
.
size
).
to
eq
(
2
)
end
end
it
'rebuilds commit'
do
it
'rebuilds commit'
do
expect
(
c
ommit
.
c
reate_builds
).
to
be_truthy
expect
(
create_builds
).
to
be_truthy
commit
.
builds
.
reload
commit
.
builds
.
reload
expect
(
commit
.
builds
.
size
).
to
eq
(
2
)
expect
(
commit
.
builds
.
size
).
to
eq
(
2
)
expect
(
c
ommit
.
c
reate_builds
(
trigger_request
)).
to
be_truthy
expect
(
create_builds
(
trigger_request
)).
to
be_truthy
commit
.
builds
.
reload
commit
.
builds
.
reload
expect
(
commit
.
builds
.
size
).
to
eq
(
4
)
expect
(
commit
.
builds
.
size
).
to
eq
(
4
)
end
end
it
'creates next builds'
do
it
'creates next builds'
do
expect
(
c
ommit
.
c
reate_builds
(
trigger_request
)).
to
be_truthy
expect
(
create_builds
(
trigger_request
)).
to
be_truthy
commit
.
builds
.
reload
commit
.
builds
.
reload
expect
(
commit
.
builds
.
size
).
to
eq
(
2
)
expect
(
commit
.
builds
.
size
).
to
eq
(
2
)
expect
(
c
ommit
.
c
reate_next_builds
(
trigger_request
)).
to
be_truthy
expect
(
create_next_builds
(
trigger_request
)).
to
be_truthy
commit
.
builds
.
reload
commit
.
builds
.
reload
expect
(
commit
.
builds
.
size
).
to
eq
(
4
)
expect
(
commit
.
builds
.
size
).
to
eq
(
4
)
end
end
context
'for [ci skip]'
do
context
'for [ci skip]'
do
before
do
before
do
commit
.
push_data
[
:commits
][
0
][
:message
]
=
'skip this commit [ci skip]'
allow
(
commit
).
to
receive
(
:git_commit_message
)
{
'message [ci skip]'
}
commit
.
save
end
end
it
'rebuilds commit'
do
it
'rebuilds commit'
do
expect
(
commit
.
status
).
to
eq
(
'skipped'
)
expect
(
commit
.
status
).
to
eq
(
'skipped'
)
expect
(
c
ommit
.
c
reate_builds
(
trigger_request
)).
to
be_truthy
expect
(
create_builds
(
trigger_request
)).
to
be_truthy
commit
.
builds
.
reload
commit
.
builds
.
reload
expect
(
commit
.
builds
.
size
).
to
eq
(
2
)
expect
(
commit
.
builds
.
size
).
to
eq
(
2
)
expect
(
commit
.
status
).
to
eq
(
'pending'
)
expect
(
commit
.
status
).
to
eq
(
'pending'
)
...
...
spec/models/ci/mail_service_spec.rb
→
spec/models/ci/
project_services/
mail_service_spec.rb
View file @
317a7469
File moved
spec/spec_helper.rb
View file @
317a7469
...
@@ -42,4 +42,8 @@ RSpec.configure do |config|
...
@@ -42,4 +42,8 @@ RSpec.configure do |config|
end
end
end
end
FactoryGirl
::
SyntaxRunner
.
class_eval
do
include
RSpec
::
Mocks
::
ExampleMethods
end
ActiveRecord
::
Migration
.
maintain_test_schema!
ActiveRecord
::
Migration
.
maintain_test_schema!
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