Commit b8dc5d2c authored by Dmitriy Zaporozhets's avatar Dmitriy Zaporozhets

Implement 2 git hooks: tagf removal and commit message

Signed-off-by: default avatarDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>
parent f034e6f3
...@@ -17,13 +17,13 @@ ...@@ -17,13 +17,13 @@
= f.check_box :deny_delete_tag = f.check_box :deny_delete_tag
%span.descr Dont allow users to remove git tags %span.descr Dont allow users to remove git tags
.form-group -#.form-group
= f.label :force_push_regex, "Force push", class: 'control-label' = f.label :force_push_regex, "Force push", class: 'control-label'
.col-sm-10 .col-sm-10
= f.text_field :force_push_regex, class: "form-control" = f.text_field :force_push_regex, class: "form-control"
%p.hint Regular expression for branches to allow force push. Empty - allow force push to any branch %p.hint Regular expression for branches to allow force push. Empty - allow force push to any branch
.form-group -#.form-group
= f.label :delete_branch_regex, "Branch removal", class: 'control-label' = f.label :delete_branch_regex, "Branch removal", class: 'control-label'
.col-sm-10 .col-sm-10
= f.text_field :delete_branch_regex, class: "form-control" = f.text_field :delete_branch_regex, class: "form-control"
...@@ -32,7 +32,7 @@ ...@@ -32,7 +32,7 @@
.form-group .form-group
= f.label :commit_message_regex, "Commit message", class: 'control-label' = f.label :commit_message_regex, "Commit message", class: 'control-label'
.col-sm-10 .col-sm-10
= f.text_field :commit_message_regex, class: "form-control" = f.text_field :commit_message_regex, class: "form-control", placeholder: 'Ex. Fix \d+\..*'
%p.hint Commit message must match this regular expression to be pushed. Empty - allow remove of any commit message %p.hint Commit message must match this regular expression to be pushed. Empty - allow remove of any commit message
.form-actions .form-actions
......
...@@ -48,12 +48,39 @@ module Gitlab ...@@ -48,12 +48,39 @@ module Gitlab
else else
:push_code :push_code
end end
user.can?(action, project)
user.can?(action, project) &&
pass_git_hooks?(user, project, ref, oldrev, newrev)
else else
false false
end end
end end
def pass_git_hooks?(user, project, ref, oldrev, newrev)
return true unless project.git_hook
git_hook = project.git_hook
# Prevent tag removal
if git_hook.deny_delete_tag
if project.repository.tag_names.include?(ref) && newrev =~ /0000000/
return false
end
end
# Check commit messages unless its branch removal
if git_hook.commit_message_regex.present? && newrev !~ /00000000/
commits = project.repository.commits_between(oldrev, newrev)
commits.each do |commit|
unless commit.safe_message =~ Regexp.new(git_hook.commit_message_regex)
return false
end
end
end
true
end
private private
def user_allowed?(user) def user_allowed?(user)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment