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
0
Merge Requests
0
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
Boxiang Sun
gitlab-ce
Commits
dc7c6bed
Commit
dc7c6bed
authored
Aug 22, 2017
by
Jacob Vosmaer
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Move GitHooksService to Gitlab::Git
parent
65f83941
Changes
19
Hide whitespace changes
Inline
Side-by-side
Showing
19 changed files
with
65 additions
and
60 deletions
+65
-60
app/services/commits/create_service.rb
app/services/commits/create_service.rb
+1
-1
app/services/create_branch_service.rb
app/services/create_branch_service.rb
+1
-1
app/services/delete_branch_service.rb
app/services/delete_branch_service.rb
+1
-1
app/services/git_hooks_service.rb
app/services/git_hooks_service.rb
+0
-32
app/services/git_operation_service.rb
app/services/git_operation_service.rb
+1
-1
app/services/merge_requests/merge_service.rb
app/services/merge_requests/merge_service.rb
+1
-1
app/services/tags/create_service.rb
app/services/tags/create_service.rb
+1
-1
app/services/tags/destroy_service.rb
app/services/tags/destroy_service.rb
+1
-1
app/services/validate_new_branch_service.rb
app/services/validate_new_branch_service.rb
+1
-1
db/fixtures/development/17_cycle_analytics.rb
db/fixtures/development/17_cycle_analytics.rb
+1
-1
lib/gitlab/git/hook.rb
lib/gitlab/git/hook.rb
+2
-2
lib/gitlab/git/hooks_service.rb
lib/gitlab/git/hooks_service.rb
+37
-0
spec/features/tags/master_deletes_tag_spec.rb
spec/features/tags/master_deletes_tag_spec.rb
+2
-2
spec/lib/gitlab/git_access_spec.rb
spec/lib/gitlab/git_access_spec.rb
+1
-1
spec/models/repository_spec.rb
spec/models/repository_spec.rb
+8
-8
spec/services/files/update_service_spec.rb
spec/services/files/update_service_spec.rb
+1
-1
spec/services/git_hooks_service_spec.rb
spec/services/git_hooks_service_spec.rb
+3
-3
spec/services/merge_requests/merge_service_spec.rb
spec/services/merge_requests/merge_service_spec.rb
+1
-1
spec/services/tags/create_service_spec.rb
spec/services/tags/create_service_spec.rb
+1
-1
No files found.
app/services/commits/create_service.rb
View file @
dc7c6bed
...
@@ -17,7 +17,7 @@ module Commits
...
@@ -17,7 +17,7 @@ module Commits
new_commit
=
create_commit!
new_commit
=
create_commit!
success
(
result:
new_commit
)
success
(
result:
new_commit
)
rescue
ValidationError
,
ChangeError
,
Gitlab
::
Git
::
Index
::
IndexError
,
Repository
::
CommitError
,
GitHooksService
::
PreReceiveError
=>
ex
rescue
ValidationError
,
ChangeError
,
Gitlab
::
Git
::
Index
::
IndexError
,
Repository
::
CommitError
,
Git
lab
::
Git
::
HooksService
::
PreReceiveError
=>
ex
error
(
ex
.
message
)
error
(
ex
.
message
)
end
end
...
...
app/services/create_branch_service.rb
View file @
dc7c6bed
...
@@ -14,7 +14,7 @@ class CreateBranchService < BaseService
...
@@ -14,7 +14,7 @@ class CreateBranchService < BaseService
else
else
error
(
'Invalid reference name'
)
error
(
'Invalid reference name'
)
end
end
rescue
GitHooksService
::
PreReceiveError
=>
ex
rescue
Git
lab
::
Git
::
HooksService
::
PreReceiveError
=>
ex
error
(
ex
.
message
)
error
(
ex
.
message
)
end
end
...
...
app/services/delete_branch_service.rb
View file @
dc7c6bed
...
@@ -16,7 +16,7 @@ class DeleteBranchService < BaseService
...
@@ -16,7 +16,7 @@ class DeleteBranchService < BaseService
else
else
error
(
'Failed to remove branch'
)
error
(
'Failed to remove branch'
)
end
end
rescue
GitHooksService
::
PreReceiveError
=>
ex
rescue
Git
lab
::
Git
::
HooksService
::
PreReceiveError
=>
ex
error
(
ex
.
message
)
error
(
ex
.
message
)
end
end
...
...
app/services/git_hooks_service.rb
deleted
100644 → 0
View file @
65f83941
class
GitHooksService
PreReceiveError
=
Class
.
new
(
StandardError
)
attr_accessor
:oldrev
,
:newrev
,
:ref
def
execute
(
committer
,
repository
,
oldrev
,
newrev
,
ref
)
@repository
=
repository
@gl_id
=
committer
.
gl_id
@oldrev
=
oldrev
@newrev
=
newrev
@ref
=
ref
%w(pre-receive update)
.
each
do
|
hook_name
|
status
,
message
=
run_hook
(
hook_name
)
unless
status
raise
PreReceiveError
,
message
end
end
yield
(
self
).
tap
do
run_hook
(
'post-receive'
)
end
end
private
def
run_hook
(
name
)
hook
=
Gitlab
::
Git
::
Hook
.
new
(
name
,
@repository
)
hook
.
trigger
(
@gl_id
,
oldrev
,
newrev
,
ref
)
end
end
app/services/git_operation_service.rb
View file @
dc7c6bed
...
@@ -121,7 +121,7 @@ class GitOperationService
...
@@ -121,7 +121,7 @@ class GitOperationService
end
end
def
with_hooks
(
ref
,
newrev
,
oldrev
)
def
with_hooks
(
ref
,
newrev
,
oldrev
)
GitHooksService
.
new
.
execute
(
Git
lab
::
Git
::
HooksService
.
new
.
execute
(
committer
,
committer
,
repository
,
repository
,
oldrev
,
oldrev
,
...
...
app/services/merge_requests/merge_service.rb
View file @
dc7c6bed
...
@@ -49,7 +49,7 @@ module MergeRequests
...
@@ -49,7 +49,7 @@ module MergeRequests
raise
MergeError
,
'Conflicts detected during merge'
unless
commit_id
raise
MergeError
,
'Conflicts detected during merge'
unless
commit_id
merge_request
.
update
(
merge_commit_sha:
commit_id
)
merge_request
.
update
(
merge_commit_sha:
commit_id
)
rescue
GitHooksService
::
PreReceiveError
=>
e
rescue
Git
lab
::
Git
::
HooksService
::
PreReceiveError
=>
e
raise
MergeError
,
e
.
message
raise
MergeError
,
e
.
message
rescue
StandardError
=>
e
rescue
StandardError
=>
e
raise
MergeError
,
"Something went wrong during merge:
#{
e
.
message
}
"
raise
MergeError
,
"Something went wrong during merge:
#{
e
.
message
}
"
...
...
app/services/tags/create_service.rb
View file @
dc7c6bed
...
@@ -13,7 +13,7 @@ module Tags
...
@@ -13,7 +13,7 @@ module Tags
new_tag
=
repository
.
add_tag
(
current_user
,
tag_name
,
target
,
message
)
new_tag
=
repository
.
add_tag
(
current_user
,
tag_name
,
target
,
message
)
rescue
Rugged
::
TagError
rescue
Rugged
::
TagError
return
error
(
"Tag
#{
tag_name
}
already exists"
)
return
error
(
"Tag
#{
tag_name
}
already exists"
)
rescue
GitHooksService
::
PreReceiveError
=>
ex
rescue
Git
lab
::
Git
::
HooksService
::
PreReceiveError
=>
ex
return
error
(
ex
.
message
)
return
error
(
ex
.
message
)
end
end
...
...
app/services/tags/destroy_service.rb
View file @
dc7c6bed
...
@@ -21,7 +21,7 @@ module Tags
...
@@ -21,7 +21,7 @@ module Tags
else
else
error
(
'Failed to remove tag'
)
error
(
'Failed to remove tag'
)
end
end
rescue
GitHooksService
::
PreReceiveError
=>
ex
rescue
Git
lab
::
Git
::
HooksService
::
PreReceiveError
=>
ex
error
(
ex
.
message
)
error
(
ex
.
message
)
end
end
...
...
app/services/validate_new_branch_service.rb
View file @
dc7c6bed
...
@@ -13,7 +13,7 @@ class ValidateNewBranchService < BaseService
...
@@ -13,7 +13,7 @@ class ValidateNewBranchService < BaseService
end
end
success
success
rescue
GitHooksService
::
PreReceiveError
=>
ex
rescue
Git
lab
::
Git
::
HooksService
::
PreReceiveError
=>
ex
error
(
ex
.
message
)
error
(
ex
.
message
)
end
end
end
end
db/fixtures/development/17_cycle_analytics.rb
View file @
dc7c6bed
...
@@ -15,7 +15,7 @@ class Gitlab::Seeder::CycleAnalytics
...
@@ -15,7 +15,7 @@ class Gitlab::Seeder::CycleAnalytics
# to disable the `pre_receive` hook in order to remove this
# to disable the `pre_receive` hook in order to remove this
# dependency on the GitLab API.
# dependency on the GitLab API.
def
stub_git_pre_receive!
def
stub_git_pre_receive!
GitHooksService
.
class_eval
do
Git
lab
::
Git
::
HooksService
.
class_eval
do
def
run_hook
(
name
)
def
run_hook
(
name
)
[
true
,
''
]
[
true
,
''
]
end
end
...
...
lib/gitlab/git/hook.rb
View file @
dc7c6bed
# Gitaly note: JV: looks like this is only used by GitHooksService in
# Gitaly note: JV: looks like this is only used by Git
lab::Git::
HooksService in
# app/services. We shouldn't bother migrating this until we know how
# app/services. We shouldn't bother migrating this until we know how
# GitHooksService will be migrated.
# Git
lab::Git::
HooksService will be migrated.
module
Gitlab
module
Gitlab
module
Git
module
Git
...
...
lib/gitlab/git/hooks_service.rb
0 → 100644
View file @
dc7c6bed
module
Gitlab
module
Git
class
HooksService
PreReceiveError
=
Class
.
new
(
StandardError
)
attr_accessor
:oldrev
,
:newrev
,
:ref
def
execute
(
committer
,
repository
,
oldrev
,
newrev
,
ref
)
@repository
=
repository
@gl_id
=
committer
.
gl_id
@oldrev
=
oldrev
@newrev
=
newrev
@ref
=
ref
%w(pre-receive update)
.
each
do
|
hook_name
|
status
,
message
=
run_hook
(
hook_name
)
unless
status
raise
PreReceiveError
,
message
end
end
yield
(
self
).
tap
do
run_hook
(
'post-receive'
)
end
end
private
def
run_hook
(
name
)
hook
=
Gitlab
::
Git
::
Hook
.
new
(
name
,
@repository
)
hook
.
trigger
(
@gl_id
,
oldrev
,
newrev
,
ref
)
end
end
end
end
spec/features/tags/master_deletes_tag_spec.rb
View file @
dc7c6bed
...
@@ -36,8 +36,8 @@ feature 'Master deletes tag' do
...
@@ -36,8 +36,8 @@ feature 'Master deletes tag' do
context
'when pre-receive hook fails'
,
js:
true
do
context
'when pre-receive hook fails'
,
js:
true
do
before
do
before
do
allow_any_instance_of
(
GitHooksService
).
to
receive
(
:execute
)
allow_any_instance_of
(
Git
lab
::
Git
::
HooksService
).
to
receive
(
:execute
)
.
and_raise
(
GitHooksService
::
PreReceiveError
,
'Do not delete tags'
)
.
and_raise
(
Git
lab
::
Git
::
HooksService
::
PreReceiveError
,
'Do not delete tags'
)
end
end
scenario
'shows the error message'
do
scenario
'shows the error message'
do
...
...
spec/lib/gitlab/git_access_spec.rb
View file @
dc7c6bed
...
@@ -384,7 +384,7 @@ describe Gitlab::GitAccess do
...
@@ -384,7 +384,7 @@ describe Gitlab::GitAccess do
def
stub_git_hooks
def
stub_git_hooks
# Running the `pre-receive` hook is expensive, and not necessary for this test.
# Running the `pre-receive` hook is expensive, and not necessary for this test.
allow_any_instance_of
(
GitHooksService
).
to
receive
(
:execute
)
do
|
service
,
&
block
|
allow_any_instance_of
(
Git
lab
::
Git
::
HooksService
).
to
receive
(
:execute
)
do
|
service
,
&
block
|
block
.
call
(
service
)
block
.
call
(
service
)
end
end
end
end
...
...
spec/models/repository_spec.rb
View file @
dc7c6bed
...
@@ -847,7 +847,7 @@ describe Repository, models: true do
...
@@ -847,7 +847,7 @@ describe Repository, models: true do
expect
do
expect
do
repository
.
add_branch
(
user
,
'new_feature'
,
'master'
)
repository
.
add_branch
(
user
,
'new_feature'
,
'master'
)
end
.
to
raise_error
(
GitHooksService
::
PreReceiveError
)
end
.
to
raise_error
(
Git
lab
::
Git
::
HooksService
::
PreReceiveError
)
end
end
it
'does not create the branch'
do
it
'does not create the branch'
do
...
@@ -855,7 +855,7 @@ describe Repository, models: true do
...
@@ -855,7 +855,7 @@ describe Repository, models: true do
expect
do
expect
do
repository
.
add_branch
(
user
,
'new_feature'
,
'master'
)
repository
.
add_branch
(
user
,
'new_feature'
,
'master'
)
end
.
to
raise_error
(
GitHooksService
::
PreReceiveError
)
end
.
to
raise_error
(
Git
lab
::
Git
::
HooksService
::
PreReceiveError
)
expect
(
repository
.
find_branch
(
'new_feature'
)).
to
be_nil
expect
(
repository
.
find_branch
(
'new_feature'
)).
to
be_nil
end
end
end
end
...
@@ -885,7 +885,7 @@ describe Repository, models: true do
...
@@ -885,7 +885,7 @@ describe Repository, models: true do
context
'when pre hooks were successful'
do
context
'when pre hooks were successful'
do
it
'runs without errors'
do
it
'runs without errors'
do
expect_any_instance_of
(
GitHooksService
).
to
receive
(
:execute
)
expect_any_instance_of
(
Git
lab
::
Git
::
HooksService
).
to
receive
(
:execute
)
.
with
(
committer
,
repository
,
old_rev
,
blank_sha
,
'refs/heads/feature'
)
.
with
(
committer
,
repository
,
old_rev
,
blank_sha
,
'refs/heads/feature'
)
expect
{
repository
.
rm_branch
(
user
,
'feature'
)
}.
not_to
raise_error
expect
{
repository
.
rm_branch
(
user
,
'feature'
)
}.
not_to
raise_error
...
@@ -906,7 +906,7 @@ describe Repository, models: true do
...
@@ -906,7 +906,7 @@ describe Repository, models: true do
expect
do
expect
do
repository
.
rm_branch
(
user
,
'feature'
)
repository
.
rm_branch
(
user
,
'feature'
)
end
.
to
raise_error
(
GitHooksService
::
PreReceiveError
)
end
.
to
raise_error
(
Git
lab
::
Git
::
HooksService
::
PreReceiveError
)
end
end
it
'does not delete the branch'
do
it
'does not delete the branch'
do
...
@@ -914,7 +914,7 @@ describe Repository, models: true do
...
@@ -914,7 +914,7 @@ describe Repository, models: true do
expect
do
expect
do
repository
.
rm_branch
(
user
,
'feature'
)
repository
.
rm_branch
(
user
,
'feature'
)
end
.
to
raise_error
(
GitHooksService
::
PreReceiveError
)
end
.
to
raise_error
(
Git
lab
::
Git
::
HooksService
::
PreReceiveError
)
expect
(
repository
.
find_branch
(
'feature'
)).
not_to
be_nil
expect
(
repository
.
find_branch
(
'feature'
)).
not_to
be_nil
end
end
end
end
...
@@ -926,8 +926,8 @@ describe Repository, models: true do
...
@@ -926,8 +926,8 @@ describe Repository, models: true do
context
'when pre hooks were successful'
do
context
'when pre hooks were successful'
do
before
do
before
do
service
=
GitHooksService
.
new
service
=
Git
lab
::
Git
::
HooksService
.
new
expect
(
GitHooksService
).
to
receive
(
:new
).
and_return
(
service
)
expect
(
Git
lab
::
Git
::
HooksService
).
to
receive
(
:new
).
and_return
(
service
)
expect
(
service
).
to
receive
(
:execute
)
expect
(
service
).
to
receive
(
:execute
)
.
with
(
committer
,
repository
,
old_rev
,
new_rev
,
'refs/heads/feature'
)
.
with
(
committer
,
repository
,
old_rev
,
new_rev
,
'refs/heads/feature'
)
.
and_yield
(
service
).
and_return
(
true
)
.
and_yield
(
service
).
and_return
(
true
)
...
@@ -1030,7 +1030,7 @@ describe Repository, models: true do
...
@@ -1030,7 +1030,7 @@ describe Repository, models: true do
GitOperationService
.
new
(
committer
,
repository
).
with_branch
(
'feature'
)
do
GitOperationService
.
new
(
committer
,
repository
).
with_branch
(
'feature'
)
do
new_rev
new_rev
end
end
end
.
to
raise_error
(
GitHooksService
::
PreReceiveError
)
end
.
to
raise_error
(
Git
lab
::
Git
::
HooksService
::
PreReceiveError
)
end
end
end
end
...
...
spec/services/files/update_service_spec.rb
View file @
dc7c6bed
...
@@ -76,7 +76,7 @@ describe Files::UpdateService do
...
@@ -76,7 +76,7 @@ describe Files::UpdateService do
let
(
:branch_name
)
{
"
#{
project
.
default_branch
}
-new"
}
let
(
:branch_name
)
{
"
#{
project
.
default_branch
}
-new"
}
it
'fires hooks only once'
do
it
'fires hooks only once'
do
expect
(
GitHooksService
).
to
receive
(
:new
).
once
.
and_call_original
expect
(
Git
lab
::
Git
::
HooksService
).
to
receive
(
:new
).
once
.
and_call_original
subject
.
execute
subject
.
execute
end
end
...
...
spec/services/git_hooks_service_spec.rb
View file @
dc7c6bed
require
'spec_helper'
require
'spec_helper'
describe
GitHooksService
do
describe
Git
lab
::
Git
::
HooksService
do
include
RepoHelpers
include
RepoHelpers
let
(
:user
)
{
create
(
:user
)
}
let
(
:user
)
{
create
(
:user
)
}
...
@@ -31,7 +31,7 @@ describe GitHooksService do
...
@@ -31,7 +31,7 @@ describe GitHooksService do
expect
do
expect
do
service
.
execute
(
user
,
project
,
@blankrev
,
@newrev
,
@ref
)
service
.
execute
(
user
,
project
,
@blankrev
,
@newrev
,
@ref
)
end
.
to
raise_error
(
GitHooksService
::
PreReceiveError
)
end
.
to
raise_error
(
Git
lab
::
Git
::
HooksService
::
PreReceiveError
)
end
end
end
end
...
@@ -43,7 +43,7 @@ describe GitHooksService do
...
@@ -43,7 +43,7 @@ describe GitHooksService do
expect
do
expect
do
service
.
execute
(
user
,
project
,
@blankrev
,
@newrev
,
@ref
)
service
.
execute
(
user
,
project
,
@blankrev
,
@newrev
,
@ref
)
end
.
to
raise_error
(
GitHooksService
::
PreReceiveError
)
end
.
to
raise_error
(
Git
lab
::
Git
::
HooksService
::
PreReceiveError
)
end
end
end
end
end
end
...
...
spec/services/merge_requests/merge_service_spec.rb
View file @
dc7c6bed
...
@@ -217,7 +217,7 @@ describe MergeRequests::MergeService do
...
@@ -217,7 +217,7 @@ describe MergeRequests::MergeService do
it
'logs and saves error if there is an PreReceiveError exception'
do
it
'logs and saves error if there is an PreReceiveError exception'
do
error_message
=
'error message'
error_message
=
'error message'
allow
(
service
).
to
receive
(
:repository
).
and_raise
(
GitHooksService
::
PreReceiveError
,
error_message
)
allow
(
service
).
to
receive
(
:repository
).
and_raise
(
Git
lab
::
Git
::
HooksService
::
PreReceiveError
,
error_message
)
allow
(
service
).
to
receive
(
:execute_hooks
)
allow
(
service
).
to
receive
(
:execute_hooks
)
service
.
execute
(
merge_request
)
service
.
execute
(
merge_request
)
...
...
spec/services/tags/create_service_spec.rb
View file @
dc7c6bed
...
@@ -41,7 +41,7 @@ describe Tags::CreateService do
...
@@ -41,7 +41,7 @@ describe Tags::CreateService do
it
'returns an error'
do
it
'returns an error'
do
expect
(
repository
).
to
receive
(
:add_tag
)
expect
(
repository
).
to
receive
(
:add_tag
)
.
with
(
user
,
'v1.1.0'
,
'master'
,
'Foo'
)
.
with
(
user
,
'v1.1.0'
,
'master'
,
'Foo'
)
.
and_raise
(
GitHooksService
::
PreReceiveError
,
'something went wrong'
)
.
and_raise
(
Git
lab
::
Git
::
HooksService
::
PreReceiveError
,
'something went wrong'
)
response
=
service
.
execute
(
'v1.1.0'
,
'master'
,
'Foo'
)
response
=
service
.
execute
(
'v1.1.0'
,
'master'
,
'Foo'
)
...
...
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