Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
gitlab-ce
Commits
ca538143
Commit
ca538143
authored
Mar 25, 2015
by
Valery Sizov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
git hook refactoring
parent
b50b5e4e
Changes
10
Hide whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
78 additions
and
120 deletions
+78
-120
app/controllers/admin/git_hooks_controller.rb
app/controllers/admin/git_hooks_controller.rb
+4
-5
app/controllers/projects/git_hooks_controller.rb
app/controllers/projects/git_hooks_controller.rb
+4
-4
app/models/git_hook.rb
app/models/git_hook.rb
+2
-0
app/services/projects/create_service.rb
app/services/projects/create_service.rb
+3
-2
app/views/admin/git_hooks/index.html.haml
app/views/admin/git_hooks/index.html.haml
+1
-52
app/views/layouts/nav/_admin.html.haml
app/views/layouts/nav/_admin.html.haml
+1
-1
app/views/projects/git_hooks/index.html.haml
app/views/projects/git_hooks/index.html.haml
+4
-55
app/views/shared/_git_hooks_form.html.haml
app/views/shared/_git_hooks_form.html.haml
+52
-0
db/migrate/20150324223425_add_is_sample_to_git_hooks.rb
db/migrate/20150324223425_add_is_sample_to_git_hooks.rb
+5
-0
db/schema.rb
db/schema.rb
+2
-1
No files found.
app/controllers/admin/git_hooks_controller.rb
View file @
ca538143
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
app/controllers/projects/git_hooks_controller.rb
View file @
ca538143
...
...
@@ -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
...
...
app/models/git_hook.rb
View file @
ca538143
class
GitHook
<
ActiveRecord
::
Base
belongs_to
:project
validates
:project
,
presence:
true
,
unless:
"is_sample?"
def
commit_message_allowed?
(
message
)
if
commit_message_regex
.
present?
...
...
app/services/projects/create_service.rb
View file @
ca538143
...
...
@@ -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
...
...
app/views/admin/git_hooks/index.html.haml
View file @
ca538143
...
...
@@ -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
app/views/layouts/nav/_admin.html.haml
View file @
ca538143
...
...
@@ -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
...
...
app/views/projects/git_hooks/index.html.haml
View file @
ca538143
...
...
@@ -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
app/views/shared/_git_hooks_form.html.haml
0 → 100644
View file @
ca538143
.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
db/migrate/20150324223425_add_is_sample_to_git_hooks.rb
0 → 100644
View file @
ca538143
class
AddIsSampleToGitHooks
<
ActiveRecord
::
Migration
def
change
add_column
:git_hooks
,
:is_sample
,
:boolean
,
default:
false
end
end
db/schema.rb
View file @
ca538143
...
...
@@ -11,7 +11,7 @@
#
# It's strongly recommended that you check this file into your version control system.
ActiveRecord
::
Schema
.
define
(
version:
20150324
155957
)
do
ActiveRecord
::
Schema
.
define
(
version:
20150324
223425
)
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
|
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment