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
Tatuya Kamada
gitlab-ce
Commits
0950d92d
Commit
0950d92d
authored
Sep 15, 2016
by
Rémy Coutable
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Reduce duplication in Commits::{CherryPickService,RevertService}
Signed-off-by:
Rémy Coutable
<
remy@rymai.me
>
parent
00f002ed
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
21 additions
and
27 deletions
+21
-27
app/services/commits/change_service.rb
app/services/commits/change_service.rb
+19
-1
app/services/commits/cherry_pick_service.rb
app/services/commits/cherry_pick_service.rb
+1
-13
app/services/commits/revert_service.rb
app/services/commits/revert_service.rb
+1
-13
No files found.
app/services/commits/change_service.rb
View file @
0950d92d
...
...
@@ -16,11 +16,29 @@ module Commits
error
(
ex
.
message
)
end
private
def
commit
raise
NotImplementedError
end
private
def
commit_change
(
action
)
raise
NotImplementedError
unless
repository
.
respond_to?
(
action
)
into
=
@create_merge_request
?
@commit
.
public_send
(
"
#{
action
}
_branch_name"
)
:
@target_branch
tree_id
=
repository
.
public_send
(
"check_
#{
action
}
_content"
,
@commit
,
@target_branch
)
if
tree_id
create_target_branch
(
into
)
if
@create_merge_request
repository
.
public_send
(
action
,
current_user
,
@commit
,
into
,
tree_id
)
success
else
error_msg
=
"Sorry, we cannot
#{
action
.
to_s
.
dasherize
}
this
#{
@commit
.
change_type_title
}
automatically.
It may have already been
#{
action
.
to_s
.
dasherize
}
, or a more recent commit may have updated some of its content."
raise
ChangeError
,
error_msg
end
end
def
check_push_permissions
allowed
=
::
Gitlab
::
UserAccess
.
new
(
current_user
,
project:
project
).
can_push_to_branch?
(
@target_branch
)
...
...
app/services/commits/cherry_pick_service.rb
View file @
0950d92d
module
Commits
class
CherryPickService
<
ChangeService
def
commit
cherry_pick_into
=
@create_merge_request
?
@commit
.
cherry_pick_branch_name
:
@target_branch
cherry_pick_tree_id
=
repository
.
check_cherry_pick_content
(
@commit
,
@target_branch
)
if
cherry_pick_tree_id
create_target_branch
(
cherry_pick_into
)
if
@create_merge_request
repository
.
cherry_pick
(
current_user
,
@commit
,
cherry_pick_into
,
cherry_pick_tree_id
)
success
else
error_msg
=
"Sorry, we cannot cherry-pick this
#{
@commit
.
change_type_title
}
automatically.
It may have already been cherry-picked, or a more recent commit may have updated some of its content."
raise
ChangeError
,
error_msg
end
commit_change
(
:cherry_pick
)
end
end
end
app/services/commits/revert_service.rb
View file @
0950d92d
module
Commits
class
RevertService
<
ChangeService
def
commit
revert_into
=
@create_merge_request
?
@commit
.
revert_branch_name
:
@target_branch
revert_tree_id
=
repository
.
check_revert_content
(
@commit
,
@target_branch
)
if
revert_tree_id
create_target_branch
(
revert_into
)
if
@create_merge_request
repository
.
revert
(
current_user
,
@commit
,
revert_into
,
revert_tree_id
)
success
else
error_msg
=
"Sorry, we cannot revert this
#{
@commit
.
change_type_title
}
automatically.
It may have already been reverted, or a more recent commit may have updated some of its content."
raise
ChangeError
,
error_msg
end
commit_change
(
:revert
)
end
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