Commit b58f3235 authored by Dmitriy Zaporozhets's avatar Dmitriy Zaporozhets

Merge branch 'default_git_hook' into 'master'

Default git hook

Implements #235

![joxi_screenshot_1427289765356](https://dev.gitlab.org/gitlab/gitlab-ee/uploads/74dc8aa49cdfdfd6044f9a8f1d0c137f/joxi_screenshot_1427289765356.png)

See merge request !361
parents 66d507a2 8b3f3e15
v 7.10.0 (unreleased)
- Improve UI for next pages: Group LDAP sync, Project git hooks, Project share with groups, Admin -> Appearance settigns
- Default git hooks for new projects
v 7.9.0 (unreleased)
- Strip prefixes and suffixes from synced SSH keys:
......
class Admin::GitHooksController < Admin::ApplicationController
before_filter :git_hook
respond_to :html
def index
end
def update
@git_hook.update_attributes(git_hook_params.merge(is_sample: true))
if @git_hook.valid?
redirect_to admin_git_hooks_path
else
render :index
end
end
private
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 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
validates :project, presence: true, unless: "is_sample?"
def commit_message_allowed?(message)
if commit_message_regex.present?
......
......@@ -91,6 +91,13 @@ module Projects
if @project.import?
@project.import_start
end
predefined_git_hook = GitHook.find_by(is_sample: true)
if predefined_git_hook
git_hook = predefined_git_hook.dup.tap{ |gh| gh.is_sample = false }
project.git_hook = git_hook
end
end
end
end
%h3.page-title
Pre-defined git hooks.
%p.light
Rules that define what git pushes are accepted for this project. All newly created projects will use this settings.
%hr.clearfix
= form_for [:admin, @git_hook], html: { class: 'form-horizontal' } do |f|
-if @git_hook.errors.any?
.alert.alert-danger
- @git_hook.errors.full_messages.each do |msg|
%p= msg
= render "shared/git_hooks_form", f: f
\ No newline at end of file
......@@ -34,6 +34,11 @@
%i.fa.fa-external-link
%span
Hooks
= nav_link(controller: :git_hooks) do
= link_to admin_git_hooks_path, title: 'Git Hooks' do
%i.fa.fa-git-square
%span
Git Hooks
= nav_link(controller: :background_jobs) do
= link_to admin_background_jobs_path, title: 'Background Jobs' do
%i.fa.fa-cog
......
......@@ -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
......@@ -138,6 +138,8 @@ Gitlab::Application.routes.draw do
end
end
resources :git_hooks, only: [:index, :update]
resources :applications
resources :groups, constraints: { id: /[^\/]+/ } do
......
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|
......
@admin
Feature: Admin git hooks sample
Background:
Given I sign in as an admin
And I visit git hooks page
Scenario: I can create git hook sample
When I fill in a form and submit
Then I see my git hook saved
\ No newline at end of file
require 'webmock'
class Spinach::Features::AdminGitHooksSample < Spinach::FeatureSteps
include SharedAuthentication
include SharedProject
include SharedPaths
include RSpec::Matchers
include RSpec::Mocks::ExampleMethods
include WebMock::API
step 'I fill in a form and submit' do
fill_in "Commit message", with: "my_string"
click_button "Save Git hooks"
end
step 'I see my git hook saved' do
visit admin_git_hooks_path
expect(page).to have_selector("input[value='my_string']")
end
end
......@@ -199,6 +199,10 @@ module SharedPaths
visit admin_applications_path
end
step 'I visit git hooks page' do
visit admin_git_hooks_path
end
# ----------------------------------------
# Generic Project
# ----------------------------------------
......
......@@ -7,5 +7,9 @@ FactoryGirl.define do
delete_branch_regex "MyString"
project
commit_message_regex "MyString"
factory :git_hook_sample do
is_sample true
end
end
end
......@@ -82,6 +82,19 @@ describe Projects::CreateService do
expect(project.saved?).to be(true)
end
end
context "git hook sample" do
before do
@git_hook_sample = create :git_hook_sample
end
it "creates git hook from sample" do
git_hook = create_project(@user, @opts).git_hook
[:force_push_regex, :deny_delete_tag, :delete_branch_regex, :commit_message_regex].each do |attr_name|
git_hook.send(attr_name).should == @git_hook_sample.send(attr_name)
end
end
end
end
def create_project(user, opts)
......
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