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
Boxiang Sun
gitlab-ce
Commits
a6c52c4e
Commit
a6c52c4e
authored
Oct 27, 2017
by
Oswaldo Ferreira
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Make merge_jid handling less stateful in MergeService
parent
dfd6c3f8
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
18 additions
and
61 deletions
+18
-61
app/models/merge_request.rb
app/models/merge_request.rb
+3
-1
app/services/merge_requests/merge_service.rb
app/services/merge_requests/merge_service.rb
+1
-8
app/workers/stuck_merge_jobs_worker.rb
app/workers/stuck_merge_jobs_worker.rb
+1
-1
spec/models/merge_request_spec.rb
spec/models/merge_request_spec.rb
+6
-0
spec/services/merge_requests/merge_service_spec.rb
spec/services/merge_requests/merge_service_spec.rb
+0
-49
spec/workers/stuck_merge_jobs_worker_spec.rb
spec/workers/stuck_merge_jobs_worker_spec.rb
+7
-2
No files found.
app/models/merge_request.rb
View file @
a6c52c4e
...
...
@@ -396,7 +396,9 @@ class MergeRequest < ActiveRecord::Base
end
def
merge_ongoing?
!!
merge_jid
&&
!
merged?
&&
Gitlab
::
SidekiqStatus
.
running?
(
merge_jid
)
# While the MergeRequest is locked, it should present itself as 'merge ongoing'.
# The unlocking process is handled by StuckMergeJobsWorker scheduled in Cron.
locked?
||
!!
merge_jid
&&
!
merged?
&&
Gitlab
::
SidekiqStatus
.
running?
(
merge_jid
)
end
def
closed_without_fork?
...
...
app/services/merge_requests/merge_service.rb
View file @
a6c52c4e
...
...
@@ -82,16 +82,9 @@ module MergeRequests
@merge_request
.
can_remove_source_branch?
(
branch_deletion_user
)
end
# Logs merge error message and cleans `MergeRequest#merge_jid`.
#
def
handle_merge_error
(
log_message
:,
save_message_on_model:
false
)
Rails
.
logger
.
error
(
"MergeService ERROR:
#{
merge_request_info
}
-
#{
log_message
}
"
)
if
save_message_on_model
@merge_request
.
update
(
merge_error:
log_message
,
merge_jid:
nil
)
else
clean_merge_jid
end
@merge_request
.
update
(
merge_error:
log_message
)
if
save_message_on_model
end
def
merge_request_info
...
...
app/workers/stuck_merge_jobs_worker.rb
View file @
a6c52c4e
...
...
@@ -23,7 +23,7 @@ class StuckMergeJobsWorker
merge_requests
=
MergeRequest
.
where
(
id:
completed_ids
)
merge_requests
.
where
.
not
(
merge_commit_sha:
nil
).
update_all
(
state: :merged
)
merge_requests
.
where
(
merge_commit_sha:
nil
).
update_all
(
state: :opened
)
merge_requests
.
where
(
merge_commit_sha:
nil
).
update_all
(
state: :opened
,
merge_jid:
nil
)
Rails
.
logger
.
info
(
"Updated state of locked merge jobs. JIDs:
#{
completed_jids
.
join
(
', '
)
}
"
)
end
...
...
spec/models/merge_request_spec.rb
View file @
a6c52c4e
...
...
@@ -1460,6 +1460,12 @@ describe MergeRequest do
end
describe
'#merge_ongoing?'
do
it
'returns true when the merge request is locked'
do
merge_request
=
build_stubbed
(
:merge_request
,
state: :locked
)
expect
(
merge_request
.
merge_ongoing?
).
to
be
(
true
)
end
it
'returns true when merge_id, MR is not merged and it has no running job'
do
merge_request
=
build_stubbed
(
:merge_request
,
state: :open
,
merge_jid:
'foo'
)
allow
(
Gitlab
::
SidekiqStatus
).
to
receive
(
:running?
).
with
(
'foo'
)
{
true
}
...
...
spec/services/merge_requests/merge_service_spec.rb
View file @
a6c52c4e
...
...
@@ -12,55 +12,6 @@ describe MergeRequests::MergeService do
end
describe
'#execute'
do
context
'MergeRequest#merge_jid'
do
let
(
:service
)
do
described_class
.
new
(
project
,
user
,
commit_message:
'Awesome message'
)
end
before
do
merge_request
.
update_column
(
:merge_jid
,
'hash-123'
)
end
it
'is cleaned when no error is raised'
do
service
.
execute
(
merge_request
)
expect
(
merge_request
.
reload
.
merge_jid
).
to
be_nil
end
it
'is cleaned when expected error is raised'
do
allow
(
service
).
to
receive
(
:commit
).
and_raise
(
described_class
::
MergeError
)
service
.
execute
(
merge_request
)
expect
(
merge_request
.
reload
.
merge_jid
).
to
be_nil
end
it
'is cleaned when merge request is not mergeable'
do
allow
(
merge_request
).
to
receive
(
:mergeable?
).
and_return
(
false
)
service
.
execute
(
merge_request
)
expect
(
merge_request
.
reload
.
merge_jid
).
to
be_nil
end
it
'is cleaned when no source is found'
do
allow
(
merge_request
).
to
receive
(
:diff_head_sha
).
and_return
(
nil
)
service
.
execute
(
merge_request
)
expect
(
merge_request
.
reload
.
merge_jid
).
to
be_nil
end
it
'is not cleaned when unexpected error is raised'
do
service
=
described_class
.
new
(
project
,
user
,
commit_message:
'Awesome message'
)
allow
(
service
).
to
receive
(
:commit
).
and_raise
(
StandardError
)
expect
{
service
.
execute
(
merge_request
)
}.
to
raise_error
(
StandardError
)
expect
(
merge_request
.
reload
.
merge_jid
).
to
be_present
end
end
context
'valid params'
do
let
(
:service
)
{
described_class
.
new
(
project
,
user
,
commit_message:
'Awesome message'
)
}
...
...
spec/workers/stuck_merge_jobs_worker_spec.rb
View file @
a6c52c4e
...
...
@@ -12,8 +12,13 @@ describe StuckMergeJobsWorker do
worker
.
perform
expect
(
mr_with_sha
.
reload
).
to
be_merged
expect
(
mr_without_sha
.
reload
).
to
be_opened
mr_with_sha
.
reload
mr_without_sha
.
reload
expect
(
mr_with_sha
).
to
be_merged
expect
(
mr_without_sha
).
to
be_opened
expect
(
mr_with_sha
.
merge_jid
).
to
be_present
expect
(
mr_without_sha
.
merge_jid
).
to
be_nil
end
it
'updates merge request to opened when locked but has not been merged'
do
...
...
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