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
1
Merge Requests
1
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
nexedi
gitlab-ce
Commits
9423547f
Commit
9423547f
authored
Jun 03, 2016
by
Kamil Trzcinski
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix other places where we still use commit attribute of Build
parent
4d5f7aa0
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
27 additions
and
27 deletions
+27
-27
app/controllers/projects/commit_controller.rb
app/controllers/projects/commit_controller.rb
+3
-3
app/models/ci/pipeline.rb
app/models/ci/pipeline.rb
+1
-1
lib/api/commit_statuses.rb
lib/api/commit_statuses.rb
+3
-3
spec/services/merge_requests/add_todo_when_build_fails_service_spec.rb
.../merge_requests/add_todo_when_build_fails_service_spec.rb
+4
-4
spec/services/merge_requests/merge_when_build_succeeds_service_spec.rb
.../merge_requests/merge_when_build_succeeds_service_spec.rb
+16
-16
No files found.
app/controllers/projects/commit_controller.rb
View file @
9423547f
...
...
@@ -104,7 +104,7 @@ class Projects::CommitController < Projects::ApplicationController
end
def
ci_builds
@ci_builds
||=
Ci
::
Build
.
where
(
commit
:
ci_commits
)
@ci_builds
||=
Ci
::
Build
.
where
(
pipeline
:
ci_commits
)
end
def
define_show_vars
...
...
@@ -117,8 +117,8 @@ class Projects::CommitController < Projects::ApplicationController
@diff_refs
=
[
commit
.
parent
||
commit
,
commit
]
@notes_count
=
commit
.
notes
.
count
@statuses
=
CommitStatus
.
where
(
commit
:
ci_commits
)
@builds
=
Ci
::
Build
.
where
(
commit
:
ci_commits
)
@statuses
=
CommitStatus
.
where
(
pipeline
:
ci_commits
)
@builds
=
Ci
::
Build
.
where
(
pipeline
:
ci_commits
)
end
def
assign_change_commit_vars
(
mr_source_branch
)
...
...
app/models/ci/pipeline.rb
View file @
9423547f
...
...
@@ -23,7 +23,7 @@ module Ci
def
self
.
stages
# We use pluck here due to problems with MySQL which doesn't allow LIMIT/OFFSET in queries
CommitStatus
.
where
(
commit
:
pluck
(
:id
)).
stages
CommitStatus
.
where
(
pipeline
:
pluck
(
:id
)).
stages
end
def
project_id
...
...
lib/api/commit_statuses.rb
View file @
9423547f
...
...
@@ -23,7 +23,7 @@ module API
not_found!
(
'Commit'
)
unless
user_project
.
commit
(
params
[
:sha
])
ci_commits
=
user_project
.
pipelines
.
where
(
sha:
params
[
:sha
])
statuses
=
::
CommitStatus
.
where
(
commit
:
ci_commits
)
statuses
=
::
CommitStatus
.
where
(
pipeline
:
ci_commits
)
statuses
=
statuses
.
latest
unless
parse_boolean
(
params
[
:all
])
statuses
=
statuses
.
where
(
ref:
params
[
:ref
])
if
params
[
:ref
].
present?
statuses
=
statuses
.
where
(
stage:
params
[
:stage
])
if
params
[
:stage
].
present?
...
...
@@ -67,8 +67,8 @@ module API
ci_commit
=
@project
.
ensure_pipeline
(
commit
.
sha
,
ref
)
name
=
params
[
:name
]
||
params
[
:context
]
status
=
GenericCommitStatus
.
running_or_pending
.
find_by
(
commit
:
ci_commit
,
name:
name
,
ref:
params
[
:ref
])
status
||=
GenericCommitStatus
.
new
(
project:
@project
,
commit
:
ci_commit
,
user:
current_user
)
status
=
GenericCommitStatus
.
running_or_pending
.
find_by
(
pipeline
:
ci_commit
,
name:
name
,
ref:
params
[
:ref
])
status
||=
GenericCommitStatus
.
new
(
project:
@project
,
pipeline
:
ci_commit
,
user:
current_user
)
status
.
update
(
attrs
)
case
params
[
:state
].
to_s
...
...
spec/services/merge_requests/add_todo_when_build_fails_service_spec.rb
View file @
9423547f
...
...
@@ -6,7 +6,7 @@ describe MergeRequests::AddTodoWhenBuildFailsService do
let
(
:merge_request
)
{
create
(
:merge_request
)
}
let
(
:project
)
{
create
(
:project
)
}
let
(
:sha
)
{
'1234567890abcdef1234567890abcdef12345678'
}
let
(
:
ci_commit
)
{
create
(
:ci_commit_with_one_job
,
ref:
merge_request
.
source_branch
,
project:
project
,
sha:
sha
)
}
let
(
:
pipeline
)
{
create
(
:ci_commit_with_one_job
,
ref:
merge_request
.
source_branch
,
project:
project
,
sha:
sha
)
}
let
(
:service
)
{
MergeRequests
::
AddTodoWhenBuildFailsService
.
new
(
project
,
user
,
commit_message:
'Awesome message'
)
}
let
(
:todo_service
)
{
TodoService
.
new
}
...
...
@@ -17,13 +17,13 @@ describe MergeRequests::AddTodoWhenBuildFailsService do
end
before
do
allow_any_instance_of
(
MergeRequest
).
to
receive
(
:
ci_commit
).
and_return
(
ci_commit
)
allow_any_instance_of
(
MergeRequest
).
to
receive
(
:
pipeline
).
and_return
(
pipeline
)
allow
(
service
).
to
receive
(
:todo_service
).
and_return
(
todo_service
)
end
describe
'#execute'
do
context
'commit status with ref'
do
let
(
:commit_status
)
{
create
(
:generic_commit_status
,
ref:
merge_request
.
source_branch
,
pipeline:
ci_commit
)
}
let
(
:commit_status
)
{
create
(
:generic_commit_status
,
ref:
merge_request
.
source_branch
,
pipeline:
pipeline
)
}
it
'notifies the todo service'
do
expect
(
todo_service
).
to
receive
(
:merge_request_build_failed
).
with
(
merge_request
)
...
...
@@ -52,7 +52,7 @@ describe MergeRequests::AddTodoWhenBuildFailsService do
describe
'#close'
do
context
'commit status with ref'
do
let
(
:commit_status
)
{
create
(
:generic_commit_status
,
ref:
merge_request
.
source_branch
,
pipeline:
ci_commit
)
}
let
(
:commit_status
)
{
create
(
:generic_commit_status
,
ref:
merge_request
.
source_branch
,
pipeline:
pipeline
)
}
it
'notifies the todo service'
do
expect
(
todo_service
).
to
receive
(
:merge_request_build_retried
).
with
(
merge_request
)
...
...
spec/services/merge_requests/merge_when_build_succeeds_service_spec.rb
View file @
9423547f
...
...
@@ -10,7 +10,7 @@ describe MergeRequests::MergeWhenBuildSucceedsService do
source_project:
project
,
target_project:
project
,
state:
"opened"
)
end
let
(
:
ci_commit
)
{
create
(
:ci_commit_with_one_job
,
ref:
mr_merge_if_green_enabled
.
source_branch
,
project:
project
)
}
let
(
:
pipeline
)
{
create
(
:ci_commit_with_one_job
,
ref:
mr_merge_if_green_enabled
.
source_branch
,
project:
project
)
}
let
(
:service
)
{
MergeRequests
::
MergeWhenBuildSucceedsService
.
new
(
project
,
user
,
commit_message:
'Awesome message'
)
}
describe
"#execute"
do
...
...
@@ -21,7 +21,7 @@ describe MergeRequests::MergeWhenBuildSucceedsService do
context
'first time enabling'
do
before
do
allow
(
merge_request
).
to
receive
(
:
ci_commit
).
and_return
(
ci_commit
)
allow
(
merge_request
).
to
receive
(
:
pipeline
).
and_return
(
pipeline
)
service
.
execute
(
merge_request
)
end
...
...
@@ -43,9 +43,9 @@ describe MergeRequests::MergeWhenBuildSucceedsService do
let
(
:build
)
{
create
(
:ci_build
,
ref:
mr_merge_if_green_enabled
.
source_branch
)
}
before
do
allow
(
mr_merge_if_green_enabled
).
to
receive
(
:
ci_commit
).
and_return
(
ci_commit
)
allow
(
mr_merge_if_green_enabled
).
to
receive
(
:
pipeline
).
and_return
(
pipeline
)
allow
(
mr_merge_if_green_enabled
).
to
receive
(
:mergeable?
).
and_return
(
true
)
allow
(
ci_commit
).
to
receive
(
:success?
).
and_return
(
true
)
allow
(
pipeline
).
to
receive
(
:success?
).
and_return
(
true
)
end
it
'updates the merge params'
do
...
...
@@ -62,8 +62,8 @@ describe MergeRequests::MergeWhenBuildSucceedsService do
let
(
:build
)
{
create
(
:ci_build
,
ref:
mr_merge_if_green_enabled
.
source_branch
,
status:
"success"
)
}
it
"merges all merge requests with merge when build succeeds enabled"
do
allow_any_instance_of
(
MergeRequest
).
to
receive
(
:
ci_commit
).
and_return
(
ci_commit
)
allow
(
ci_commit
).
to
receive
(
:success?
).
and_return
(
true
)
allow_any_instance_of
(
MergeRequest
).
to
receive
(
:
pipeline
).
and_return
(
pipeline
)
allow
(
pipeline
).
to
receive
(
:success?
).
and_return
(
true
)
expect
(
MergeWorker
).
to
receive
(
:perform_async
)
service
.
trigger
(
build
)
...
...
@@ -75,8 +75,8 @@ describe MergeRequests::MergeWhenBuildSucceedsService do
let
(
:build
)
{
create
(
:ci_build
,
ref:
mr_merge_if_green_enabled
.
source_branch
,
status:
"success"
)
}
it
"merges all merge requests with merge when build succeeds enabled"
do
allow_any_instance_of
(
MergeRequest
).
to
receive
(
:
ci_commit
).
and_return
(
ci_commit
)
allow
(
ci_commit
).
to
receive
(
:success?
).
and_return
(
true
)
allow_any_instance_of
(
MergeRequest
).
to
receive
(
:
pipeline
).
and_return
(
pipeline
)
allow
(
pipeline
).
to
receive
(
:success?
).
and_return
(
true
)
allow
(
old_build
).
to
receive
(
:sha
).
and_return
(
'1234abcdef'
)
expect
(
MergeWorker
).
not_to
receive
(
:perform_async
)
...
...
@@ -99,9 +99,9 @@ describe MergeRequests::MergeWhenBuildSucceedsService do
it
'discovers branches and merges all merge requests when status is success'
do
allow
(
project
.
repository
).
to
receive
(
:branch_names_contains
).
with
(
commit_status
.
sha
).
and_return
([
mr_merge_if_green_enabled
.
source_branch
])
allow
(
ci_commit
).
to
receive
(
:success?
).
and_return
(
true
)
allow_any_instance_of
(
MergeRequest
).
to
receive
(
:
ci_commit
).
and_return
(
ci_commit
)
allow
(
ci_commit
).
to
receive
(
:success?
).
and_return
(
true
)
allow
(
pipeline
).
to
receive
(
:success?
).
and_return
(
true
)
allow_any_instance_of
(
MergeRequest
).
to
receive
(
:
pipeline
).
and_return
(
pipeline
)
allow
(
pipeline
).
to
receive
(
:success?
).
and_return
(
true
)
expect
(
MergeWorker
).
to
receive
(
:perform_async
)
service
.
trigger
(
commit_status
)
...
...
@@ -110,17 +110,17 @@ describe MergeRequests::MergeWhenBuildSucceedsService do
context
'properly handles multiple stages'
do
let
(
:ref
)
{
mr_merge_if_green_enabled
.
source_branch
}
let
(
:build
)
{
create
(
:ci_build
,
pipeline:
ci_commit
,
ref:
ref
,
name:
'build'
,
stage:
'build'
)
}
let
(
:test
)
{
create
(
:ci_build
,
pipeline:
ci_commit
,
ref:
ref
,
name:
'test'
,
stage:
'test'
)
}
let
(
:build
)
{
create
(
:ci_build
,
pipeline:
pipeline
,
ref:
ref
,
name:
'build'
,
stage:
'build'
)
}
let
(
:test
)
{
create
(
:ci_build
,
pipeline:
pipeline
,
ref:
ref
,
name:
'test'
,
stage:
'test'
)
}
before
do
# This behavior of MergeRequest: we instantiate a new object
allow_any_instance_of
(
MergeRequest
).
to
receive
(
:
ci_commit
).
and_wrap_original
do
Ci
::
Pipeline
.
find
(
ci_commit
.
id
)
allow_any_instance_of
(
MergeRequest
).
to
receive
(
:
pipeline
).
and_wrap_original
do
Ci
::
Pipeline
.
find
(
pipeline
.
id
)
end
# We create test after the build
allow
(
ci_commit
).
to
receive
(
:create_next_builds
).
and_wrap_original
do
allow
(
pipeline
).
to
receive
(
:create_next_builds
).
and_wrap_original
do
test
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