Commit ca538143 authored by Valery Sizov's avatar Valery Sizov

git hook refactoring

parent b50b5e4e
class Admin::GitHooksController < Admin::ApplicationController
before_filter :ensure_hook_exist
before_filter :git_hook
respond_to :html
......@@ -7,7 +7,7 @@ class Admin::GitHooksController < Admin::ApplicationController
end
def update
@git_hook.update_attributes(git_hook_params)
@git_hook.update_attributes(git_hook_params.merge(is_sample: true))
if @git_hook.valid?
redirect_to admin_git_hooks_path
......@@ -18,13 +18,12 @@ class Admin::GitHooksController < Admin::ApplicationController
private
# Only allow a trusted parameter "white list" through.
def git_hook_params
params.require(:git_hook).permit(:deny_delete_tag, :delete_branch_regex,
:commit_message_regex, :force_push_regex, :author_email_regex, :member_check, :file_name_regex)
end
def ensure_hook_exist
@git_hook ||= (GitHook.find_by(project_id: nil) || GitHook.create!)
def git_hook
@git_hook ||= GitHook.find_or_create_by(is_sample: true)
end
end
......@@ -9,14 +9,14 @@ class Projects::GitHooksController < Projects::ApplicationController
def index
project.create_git_hook unless project.git_hook
@pre_receive_hook = project.git_hook
@git_hook = project.git_hook
end
def update
@pre_receive_hook = project.git_hook
@pre_receive_hook.update_attributes(git_hook_params)
@git_hook = project.git_hook
@git_hook.update_attributes(git_hook_params)
if @pre_receive_hook.valid?
if @git_hook.valid?
redirect_to namespace_project_git_hooks_path(@project.namespace, @project)
else
render :index
......
class GitHook < ActiveRecord::Base
belongs_to :project
validates :project, presence: true, unless: "is_sample?"
def commit_message_allowed?(message)
if commit_message_regex.present?
......
......@@ -92,10 +92,11 @@ module Projects
@project.import_start
end
predefined_git_hook = GitHook.find_by(project_id: nil)
predefined_git_hook = GitHook.find_by(is_sample: true)
if predefined_git_hook
project.git_hook = predefined_git_hook.clone
git_hook = predefined_git_hook.dup.tap{ |gh| gh.is_sample = false }
project.git_hook = git_hook
end
end
end
......
......@@ -10,55 +10,4 @@
.alert.alert-danger
- @git_hook.errors.full_messages.each do |msg|
%p= msg
.form-group
.col-sm-offset-2.col-sm-10
.checkbox
= f.label :deny_delete_tag do
= f.check_box :deny_delete_tag
%strong
Do not allow users to remove git tags with
%code git push
.help-block Tags can still be deleted through the web UI.
.form-group
.col-sm-offset-2.col-sm-10
.checkbox
= f.label :member_check do
= f.check_box :member_check
%strong
Check whether author is a GitLab user
.help-block Restrict commits by author(email) to existing GitLab users
.form-group
= f.label :commit_message_regex, "Commit message", class: 'control-label'
.col-sm-10
= f.text_field :commit_message_regex, class: "form-control", placeholder: 'Example: Fixes \d+\..*'
.help-block
All commit messages must match this
= link_to 'Ruby regular expression', 'http://www.ruby-doc.org/core-2.1.1/Regexp.html'
to be pushed.
If this field is empty it allows any commit message.
For example you can require that an issue number is always mentioned in the commit message.
.form-group
= f.label :author_email_regex, "Commit author's email", class: 'control-label'
.col-sm-10
= f.text_field :author_email_regex, class: "form-control", placeholder: 'Example: Fixes @my-company.com$'
.help-block
All commit author's email must match this
= link_to 'Ruby regular expression', 'http://www.ruby-doc.org/core-2.1.1/Regexp.html'
to be pushed.
If this field is empty it allows any email.
.form-group
= f.label :file_name_regex, "Prohibited file names", class: 'control-label'
.col-sm-10
= f.text_field :file_name_regex, class: "form-control", placeholder: 'Example: (jar|exe)$'
.help-block
All commited filenames must not match this
= link_to 'Ruby regular expression', 'http://www.ruby-doc.org/core-2.1.1/Regexp.html'
to be pushed.
If this field is empty it allows any filenames.
.form-actions
= f.submit "Save Git hooks", class: "btn btn-create"
= render "shared/git_hooks_form", f: f
\ No newline at end of file
......@@ -36,7 +36,7 @@
Hooks
= nav_link(controller: :git_hooks) do
= link_to admin_git_hooks_path, title: 'Git Hooks' do
%i.fa.fa-git
%i.fa.fa-git-square
%span
Git Hooks
= nav_link(controller: :background_jobs) do
......
......@@ -5,60 +5,9 @@
%hr.clearfix
= form_for [@project.namespace.becomes(Namespace), @project, @pre_receive_hook], html: { class: 'form-horizontal' } do |f|
-if @pre_receive_hook.errors.any?
= form_for [@project.namespace.becomes(Namespace), @project, @git_hook], html: { class: 'form-horizontal' } do |f|
-if @git_hook.errors.any?
.alert.alert-danger
- @pre_receive_hook.errors.full_messages.each do |msg|
- @git_hook.errors.full_messages.each do |msg|
%p= msg
.form-group
.col-sm-offset-2.col-sm-10
.checkbox
= f.label :deny_delete_tag do
= f.check_box :deny_delete_tag
%strong
Do not allow users to remove git tags with
%code git push
.help-block Tags can still be deleted through the web UI.
.form-group
.col-sm-offset-2.col-sm-10
.checkbox
= f.label :member_check do
= f.check_box :member_check
%strong
Check whether author is a GitLab user
.help-block Restrict commits by author(email) to existing GitLab users
.form-group
= f.label :commit_message_regex, "Commit message", class: 'control-label'
.col-sm-10
= f.text_field :commit_message_regex, class: "form-control", placeholder: 'Example: Fixes \d+\..*'
.help-block
All commit messages must match this
= link_to 'Ruby regular expression', 'http://www.ruby-doc.org/core-2.1.1/Regexp.html'
to be pushed.
If this field is empty it allows any commit message.
For example you can require that an issue number is always mentioned in the commit message.
.form-group
= f.label :author_email_regex, "Commit author's email", class: 'control-label'
.col-sm-10
= f.text_field :author_email_regex, class: "form-control", placeholder: 'Example: Fixes @my-company.com$'
.help-block
All commit author's email must match this
= link_to 'Ruby regular expression', 'http://www.ruby-doc.org/core-2.1.1/Regexp.html'
to be pushed.
If this field is empty it allows any email.
.form-group
= f.label :file_name_regex, "Prohibited file names", class: 'control-label'
.col-sm-10
= f.text_field :file_name_regex, class: "form-control", placeholder: 'Example: (jar|exe)$'
.help-block
All commited filenames must not match this
= link_to 'Ruby regular expression', 'http://www.ruby-doc.org/core-2.1.1/Regexp.html'
to be pushed.
If this field is empty it allows any filenames.
.form-actions
= f.submit "Save Git hooks", class: "btn btn-create"
= render "shared/git_hooks_form", f: f
.form-group
.col-sm-offset-2.col-sm-10
.checkbox
= f.label :deny_delete_tag do
= f.check_box :deny_delete_tag
%strong
Do not allow users to remove git tags with
%code git push
.help-block Tags can still be deleted through the web UI.
.form-group
.col-sm-offset-2.col-sm-10
.checkbox
= f.label :member_check do
= f.check_box :member_check
%strong
Check whether author is a GitLab user
.help-block Restrict commits by author(email) to existing GitLab users
.form-group
= f.label :commit_message_regex, "Commit message", class: 'control-label'
.col-sm-10
= f.text_field :commit_message_regex, class: "form-control", placeholder: 'Example: Fixes \d+\..*'
.help-block
All commit messages must match this
= link_to 'Ruby regular expression', 'http://www.ruby-doc.org/core-2.1.1/Regexp.html'
to be pushed.
If this field is empty it allows any commit message.
For example you can require that an issue number is always mentioned in the commit message.
.form-group
= f.label :author_email_regex, "Commit author's email", class: 'control-label'
.col-sm-10
= f.text_field :author_email_regex, class: "form-control", placeholder: 'Example: Fixes @my-company.com$'
.help-block
All commit author's email must match this
= link_to 'Ruby regular expression', 'http://www.ruby-doc.org/core-2.1.1/Regexp.html'
to be pushed.
If this field is empty it allows any email.
.form-group
= f.label :file_name_regex, "Prohibited file names", class: 'control-label'
.col-sm-10
= f.text_field :file_name_regex, class: "form-control", placeholder: 'Example: (jar|exe)$'
.help-block
All commited filenames must not match this
= link_to 'Ruby regular expression', 'http://www.ruby-doc.org/core-2.1.1/Regexp.html'
to be pushed.
If this field is empty it allows any filenames.
.form-actions
= f.submit "Save Git hooks", class: "btn btn-create"
\ No newline at end of file
class AddIsSampleToGitHooks < ActiveRecord::Migration
def change
add_column :git_hooks, :is_sample, :boolean, default: false
end
end
......@@ -11,7 +11,7 @@
#
# It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema.define(version: 20150324155957) do
ActiveRecord::Schema.define(version: 20150324223425) do
# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"
......@@ -125,6 +125,7 @@ ActiveRecord::Schema.define(version: 20150324155957) do
t.string "author_email_regex"
t.boolean "member_check", default: false, null: false
t.string "file_name_regex"
t.boolean "is_sample", default: false
end
create_table "identities", force: true do |t|
......
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