blob: 5ac2853019bd50c9865aaa61ae002a1d4e7339df (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
|
module Commits
class RevertService < ::BaseService
class ValidationError < StandardError; end
def execute
@source_project = params[:source_project] || @project
@target_branch = params[:target_branch]
@commit = params[:commit]
@create_merge_request = params[:create_merge_request]
# Check push permissions to branch
validate
if commit
success
else
error("Sorry, we cannot revert this commit automatically.
It may have already been reverted, or a more recent commit may
have updated some of its content.")
end
rescue Repository::CommitError, Gitlab::Git::Repository::InvalidBlobName, GitHooksService::PreReceiveError, ValidationError => ex
error(ex.message)
end
def commit
raw_repo = repository.rugged
# Create branch with revert commit
reverted = repository.revert(current_user, @commit, @target_branch, @create_merge_request)
if reverted && !@create_merge_request
repository.rm_branch(current_user, @commit.revert_branch_name)
end
reverted
end
private
def raise_error(message)
raise ValidationError.new(message)
end
def validate
allowed = ::Gitlab::GitAccess.new(current_user, project).can_push_to_branch?(@target_branch)
unless allowed
raise_error("You are not allowed to push into this branch")
end
end
end
end
|