blob: e1b88a9d848f3eb52ab6421dae05012b0a37a6f9 (
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("Something went wrong. Your changes were not committed")
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.id,
@commit.revert_branch_name, @target_branch,
@commit.revert_message, @create_merge_request)
unless @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
|