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
e9570fcc
Commit
e9570fcc
authored
Oct 16, 2020
by
Igor Drozdov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Refactor Repository#merge_to_ref number of args
Propagate kwargs instead of args to a method
parent
f043ace9
Changes
8
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
42 additions
and
27 deletions
+42
-27
app/models/repository.rb
app/models/repository.rb
+0
-6
app/services/merge_requests/merge_to_ref_service.rb
app/services/merge_requests/merge_to_ref_service.rb
+7
-1
lib/gitlab/git/repository.rb
lib/gitlab/git/repository.rb
+2
-2
lib/gitlab/gitaly_client/operation_service.rb
lib/gitlab/gitaly_client/operation_service.rb
+1
-1
spec/lib/gitlab/git/repository_spec.rb
spec/lib/gitlab/git/repository_spec.rb
+3
-2
spec/lib/gitlab/gitaly_client/operation_service_spec.rb
spec/lib/gitlab/gitaly_client/operation_service_spec.rb
+19
-7
spec/models/repository_spec.rb
spec/models/repository_spec.rb
+7
-6
spec/services/merge_requests/merge_to_ref_service_spec.rb
spec/services/merge_requests/merge_to_ref_service_spec.rb
+3
-2
No files found.
app/models/repository.rb
View file @
e9570fcc
...
...
@@ -829,12 +829,6 @@ class Repository
end
end
def
merge_to_ref
(
user
,
source_sha
,
merge_request
,
target_ref
,
message
,
first_parent_ref
,
allow_conflicts
=
false
)
branch
=
merge_request
.
target_branch
raw
.
merge_to_ref
(
user
,
source_sha
,
branch
,
target_ref
,
message
,
first_parent_ref
,
allow_conflicts
)
end
def
delete_refs
(
*
ref_names
)
raw
.
delete_refs
(
*
ref_names
)
end
...
...
app/services/merge_requests/merge_to_ref_service.rb
View file @
e9570fcc
...
...
@@ -66,7 +66,13 @@ module MergeRequests
end
def
commit
repository
.
merge_to_ref
(
current_user
,
source
,
merge_request
,
target_ref
,
commit_message
,
first_parent_ref
,
allow_conflicts
)
repository
.
merge_to_ref
(
current_user
,
source_sha:
source
,
branch:
merge_request
.
target_branch
,
target_ref:
target_ref
,
message:
commit_message
,
first_parent_ref:
first_parent_ref
,
allow_conflicts:
allow_conflicts
)
rescue
Gitlab
::
Git
::
PreReceiveError
,
Gitlab
::
Git
::
CommandError
=>
error
raise
MergeError
,
error
.
message
end
...
...
lib/gitlab/git/repository.rb
View file @
e9570fcc
...
...
@@ -599,9 +599,9 @@ module Gitlab
tags
.
find
{
|
tag
|
tag
.
name
==
name
}
end
def
merge_to_ref
(
user
,
source_sha
,
branch
,
target_ref
,
message
,
first_parent_ref
,
allow_conflict
s
)
def
merge_to_ref
(
user
,
**
kwarg
s
)
wrapped_gitaly_errors
do
gitaly_operation_client
.
user_merge_to_ref
(
user
,
source_sha
,
branch
,
target_ref
,
message
,
first_parent_ref
,
allow_conflict
s
)
gitaly_operation_client
.
user_merge_to_ref
(
user
,
**
kwarg
s
)
end
end
...
...
lib/gitlab/gitaly_client/operation_service.rb
View file @
e9570fcc
...
...
@@ -103,7 +103,7 @@ module Gitlab
end
end
def
user_merge_to_ref
(
user
,
source_sha
,
branch
,
target_ref
,
message
,
first_parent_ref
,
allow_conflicts
)
def
user_merge_to_ref
(
user
,
source_sha
:,
branch
:,
target_ref
:,
message
:,
first_parent_ref
:,
allow_conflicts:
false
)
request
=
Gitaly
::
UserMergeToRefRequest
.
new
(
repository:
@gitaly_repo
,
source_sha:
source_sha
,
...
...
spec/lib/gitlab/git/repository_spec.rb
View file @
e9570fcc
...
...
@@ -1746,14 +1746,15 @@ RSpec.describe Gitlab::Git::Repository, :seed_helper do
let
(
:right_branch
)
{
'test-master'
}
let
(
:first_parent_ref
)
{
'refs/heads/test-master'
}
let
(
:target_ref
)
{
'refs/merge-requests/999/merge'
}
let
(
:allow_conflicts
)
{
false
}
before
do
repository
.
create_branch
(
right_branch
,
branch_head
)
unless
repository
.
ref_exists?
(
first_parent_ref
)
end
def
merge_to_ref
repository
.
merge_to_ref
(
user
,
left_sha
,
right_branch
,
target_ref
,
'Merge message'
,
first_parent_ref
,
allow_conflicts
)
repository
.
merge_to_ref
(
user
,
source_sha:
left_sha
,
branch:
right_branch
,
target_ref:
target_ref
,
message:
'Merge message'
,
first_parent_ref:
first_parent_ref
)
end
it
'generates a commit in the target_ref'
do
...
...
spec/lib/gitlab/gitaly_client/operation_service_spec.rb
View file @
e9570fcc
...
...
@@ -88,17 +88,29 @@ RSpec.describe Gitlab::GitalyClient::OperationService do
let
(
:source_sha
)
{
'cfe32cf61b73a0d5e9f13e774abde7ff789b1660'
}
let
(
:ref
)
{
'refs/merge-requests/x/merge'
}
let
(
:message
)
{
'validación'
}
let
(
:allow_conflicts
)
{
false
}
let
(
:response
)
{
Gitaly
::
UserMergeToRefResponse
.
new
(
commit_id:
'new-commit-id'
)
}
subject
{
client
.
user_merge_to_ref
(
user
,
source_sha
,
nil
,
ref
,
message
,
first_parent_ref
,
allow_conflicts
)
}
let
(
:payload
)
do
{
source_sha:
source_sha
,
branch:
'branch'
,
target_ref:
ref
,
message:
message
,
first_parent_ref:
first_parent_ref
,
allow_conflicts:
true
}
end
it
'sends a user_merge_to_ref message'
do
expect_any_instance_of
(
Gitaly
::
OperationService
::
Stub
)
.
to
receive
(
:user_merge_to_ref
).
with
(
kind_of
(
Gitaly
::
UserMergeToRefRequest
),
kind_of
(
Hash
))
.
and_return
(
response
)
subject
freeze_time
do
expect_any_instance_of
(
Gitaly
::
OperationService
::
Stub
).
to
receive
(
:user_merge_to_ref
)
do
|
_
,
request
,
options
|
expect
(
options
).
to
be_kind_of
(
Hash
)
expect
(
request
.
to_h
).
to
eq
(
payload
.
merge
({
repository:
repository
.
gitaly_repository
.
to_h
,
message:
message
.
dup
.
force_encoding
(
Encoding
::
ASCII_8BIT
),
user:
Gitlab
::
Git
::
User
.
from_gitlab
(
user
).
to_gitaly
.
to_h
,
timestamp:
{
nanos:
0
,
seconds:
Time
.
current
.
to_i
}
})
)
end
.
and_return
(
response
)
client
.
user_merge_to_ref
(
user
,
**
payload
)
end
end
end
...
...
spec/models/repository_spec.rb
View file @
e9570fcc
...
...
@@ -1698,12 +1698,13 @@ RSpec.describe Repository do
end
it
'writes merge of source SHA and first parent ref to MR merge_ref_path'
do
merge_commit_id
=
repository
.
merge_to_ref
(
user
,
merge_request
.
diff_head_sha
,
merge_request
,
merge_request
.
merge_ref_path
,
'Custom message'
,
merge_request
.
target_branch_ref
)
merge_commit_id
=
repository
.
merge_to_ref
(
user
,
source_sha:
merge_request
.
diff_head_sha
,
branch:
merge_request
.
target_branch
,
target_ref:
merge_request
.
merge_ref_path
,
message:
'Custom message'
,
first_parent_ref:
merge_request
.
target_branch_ref
)
merge_commit
=
repository
.
commit
(
merge_commit_id
)
...
...
spec/services/merge_requests/merge_to_ref_service_spec.rb
View file @
e9570fcc
...
...
@@ -257,8 +257,9 @@ RSpec.describe MergeRequests::MergeToRefService do
let
(
:params
)
{
{
allow_conflicts:
true
}
}
it
'calls merge_to_ref with allow_conflicts param'
do
expect
(
project
.
repository
).
to
receive
(
:merge_to_ref
)
.
with
(
anything
,
anything
,
anything
,
anything
,
anything
,
anything
,
true
)
expect
(
project
.
repository
).
to
receive
(
:merge_to_ref
)
do
|
user
,
**
kwargs
|
expect
(
kwargs
[
:allow_conflicts
]).
to
eq
(
true
)
end
.
and_call_original
service
.
execute
(
merge_request
)
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