mirror of
https://github.com/wahyd4/gitlabhq.git
synced 2026-08-11 21:56:19 +10:00
Implement 2 git hooks: tagf removal and commit message
Signed-off-by: Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>
This commit is contained in:
@@ -17,13 +17,13 @@
|
||||
= f.check_box :deny_delete_tag
|
||||
%span.descr Dont allow users to remove git tags
|
||||
|
||||
.form-group
|
||||
-#.form-group
|
||||
= f.label :force_push_regex, "Force push", class: 'control-label'
|
||||
.col-sm-10
|
||||
= 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
|
||||
|
||||
.form-group
|
||||
-#.form-group
|
||||
= f.label :delete_branch_regex, "Branch removal", class: 'control-label'
|
||||
.col-sm-10
|
||||
= f.text_field :delete_branch_regex, class: "form-control"
|
||||
@@ -32,7 +32,7 @@
|
||||
.form-group
|
||||
= f.label :commit_message_regex, "Commit message", class: 'control-label'
|
||||
.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
|
||||
|
||||
.form-actions
|
||||
|
||||
@@ -48,12 +48,39 @@ module Gitlab
|
||||
else
|
||||
:push_code
|
||||
end
|
||||
user.can?(action, project)
|
||||
|
||||
user.can?(action, project) &&
|
||||
pass_git_hooks?(user, project, ref, oldrev, newrev)
|
||||
else
|
||||
false
|
||||
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
|
||||
|
||||
def user_allowed?(user)
|
||||
|
||||
Reference in New Issue
Block a user