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
Show 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
new_commit
=
create_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
)
end
...
...
app/services/create_branch_service.rb
View file @
dc7c6bed
...
...
@@ -14,7 +14,7 @@ class CreateBranchService < BaseService
else
error
(
'Invalid reference name'
)
end
rescue
GitHooksService
::
PreReceiveError
=>
ex
rescue
Git
lab
::
Git
::
HooksService
::
PreReceiveError
=>
ex
error
(
ex
.
message
)
end
...
...
app/services/delete_branch_service.rb
View file @
dc7c6bed
...
...
@@ -16,7 +16,7 @@ class DeleteBranchService < BaseService
else
error
(
'Failed to remove branch'
)
end
rescue
GitHooksService
::
PreReceiveError
=>
ex
rescue
Git
lab
::
Git
::
HooksService
::
PreReceiveError
=>
ex
error
(
ex
.
message
)
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
end
def
with_hooks
(
ref
,
newrev
,
oldrev
)
GitHooksService
.
new
.
execute
(
Git
lab
::
Git
::
HooksService
.
new
.
execute
(
committer
,
repository
,
oldrev
,
...
...
app/services/merge_requests/merge_service.rb
View file @
dc7c6bed
...
...
@@ -49,7 +49,7 @@ module MergeRequests
raise
MergeError
,
'Conflicts detected during merge'
unless
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
rescue
StandardError
=>
e
raise
MergeError
,
"Something went wrong during merge:
#{
e
.
message
}
"
...
...
app/services/tags/create_service.rb
View file @
dc7c6bed
...
...
@@ -13,7 +13,7 @@ module Tags
new_tag
=
repository
.
add_tag
(
current_user
,
tag_name
,
target
,
message
)
rescue
Rugged
::
TagError
return
error
(
"Tag
#{
tag_name
}
already exists"
)
rescue
GitHooksService
::
PreReceiveError
=>
ex
rescue
Git
lab
::
Git
::
HooksService
::
PreReceiveError
=>
ex
return
error
(
ex
.
message
)
end
...
...
app/services/tags/destroy_service.rb
View file @
dc7c6bed
...
...
@@ -21,7 +21,7 @@ module Tags
else
error
(
'Failed to remove tag'
)
end
rescue
GitHooksService
::
PreReceiveError
=>
ex
rescue
Git
lab
::
Git
::
HooksService
::
PreReceiveError
=>
ex
error
(
ex
.
message
)
end
...
...
app/services/validate_new_branch_service.rb
View file @
dc7c6bed
...
...
@@ -13,7 +13,7 @@ class ValidateNewBranchService < BaseService
end
success
rescue
GitHooksService
::
PreReceiveError
=>
ex
rescue
Git
lab
::
Git
::
HooksService
::
PreReceiveError
=>
ex
error
(
ex
.
message
)
end
end
db/fixtures/development/17_cycle_analytics.rb
View file @
dc7c6bed
...
...
@@ -15,7 +15,7 @@ class Gitlab::Seeder::CycleAnalytics
# to disable the `pre_receive` hook in order to remove this
# dependency on the GitLab API.
def
stub_git_pre_receive!
GitHooksService
.
class_eval
do
Git
lab
::
Git
::
HooksService
.
class_eval
do
def
run_hook
(
name
)
[
true
,
''
]
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
# GitHooksService will be migrated.
# Git
lab::Git::
HooksService will be migrated.
module
Gitlab
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
context
'when pre-receive hook fails'
,
js:
true
do
before
do
allow_any_instance_of
(
GitHooksService
).
to
receive
(
:execute
)
.
and_raise
(
GitHooksService
::
PreReceiveError
,
'Do not delete tags'
)
allow_any_instance_of
(
Git
lab
::
Git
::
HooksService
).
to
receive
(
:execute
)
.
and_raise
(
Git
lab
::
Git
::
HooksService
::
PreReceiveError
,
'Do not delete tags'
)
end
scenario
'shows the error message'
do
...
...
spec/lib/gitlab/git_access_spec.rb
View file @
dc7c6bed
...
...
@@ -384,7 +384,7 @@ describe Gitlab::GitAccess do
def
stub_git_hooks
# 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
)
end
end
...
...
spec/models/repository_spec.rb
View file @
dc7c6bed
...
...
@@ -847,7 +847,7 @@ describe Repository, models: true do
expect
do
repository
.
add_branch
(
user
,
'new_feature'
,
'master'
)
end
.
to
raise_error
(
GitHooksService
::
PreReceiveError
)
end
.
to
raise_error
(
Git
lab
::
Git
::
HooksService
::
PreReceiveError
)
end
it
'does not create the branch'
do
...
...
@@ -855,7 +855,7 @@ describe Repository, models: true do
expect
do
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
end
end
...
...
@@ -885,7 +885,7 @@ describe Repository, models: true do
context
'when pre hooks were successful'
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'
)
expect
{
repository
.
rm_branch
(
user
,
'feature'
)
}.
not_to
raise_error
...
...
@@ -906,7 +906,7 @@ describe Repository, models: true do
expect
do
repository
.
rm_branch
(
user
,
'feature'
)
end
.
to
raise_error
(
GitHooksService
::
PreReceiveError
)
end
.
to
raise_error
(
Git
lab
::
Git
::
HooksService
::
PreReceiveError
)
end
it
'does not delete the branch'
do
...
...
@@ -914,7 +914,7 @@ describe Repository, models: true do
expect
do
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
end
end
...
...
@@ -926,8 +926,8 @@ describe Repository, models: true do
context
'when pre hooks were successful'
do
before
do
service
=
GitHooksService
.
new
expect
(
GitHooksService
).
to
receive
(
:new
).
and_return
(
service
)
service
=
Git
lab
::
Git
::
HooksService
.
new
expect
(
Git
lab
::
Git
::
HooksService
).
to
receive
(
:new
).
and_return
(
service
)
expect
(
service
).
to
receive
(
:execute
)
.
with
(
committer
,
repository
,
old_rev
,
new_rev
,
'refs/heads/feature'
)
.
and_yield
(
service
).
and_return
(
true
)
...
...
@@ -1030,7 +1030,7 @@ describe Repository, models: true do
GitOperationService
.
new
(
committer
,
repository
).
with_branch
(
'feature'
)
do
new_rev
end
end
.
to
raise_error
(
GitHooksService
::
PreReceiveError
)
end
.
to
raise_error
(
Git
lab
::
Git
::
HooksService
::
PreReceiveError
)
end
end
...
...
spec/services/files/update_service_spec.rb
View file @
dc7c6bed
...
...
@@ -76,7 +76,7 @@ describe Files::UpdateService do
let
(
:branch_name
)
{
"
#{
project
.
default_branch
}
-new"
}
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
end
...
...
spec/services/git_hooks_service_spec.rb
View file @
dc7c6bed
require
'spec_helper'
describe
GitHooksService
do
describe
Git
lab
::
Git
::
HooksService
do
include
RepoHelpers
let
(
:user
)
{
create
(
:user
)
}
...
...
@@ -31,7 +31,7 @@ describe GitHooksService do
expect
do
service
.
execute
(
user
,
project
,
@blankrev
,
@newrev
,
@ref
)
end
.
to
raise_error
(
GitHooksService
::
PreReceiveError
)
end
.
to
raise_error
(
Git
lab
::
Git
::
HooksService
::
PreReceiveError
)
end
end
...
...
@@ -43,7 +43,7 @@ describe GitHooksService do
expect
do
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
...
...
spec/services/merge_requests/merge_service_spec.rb
View file @
dc7c6bed
...
...
@@ -217,7 +217,7 @@ describe MergeRequests::MergeService do
it
'logs and saves error if there is an PreReceiveError exception'
do
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
)
service
.
execute
(
merge_request
)
...
...
spec/services/tags/create_service_spec.rb
View file @
dc7c6bed
...
...
@@ -41,7 +41,7 @@ describe Tags::CreateService do
it
'returns an error'
do
expect
(
repository
).
to
receive
(
:add_tag
)
.
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'
)
...
...
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