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
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
gitlab-ce
Commits
2384bed4
Commit
2384bed4
authored
Apr 15, 2016
by
Gabriel Mazetto
Committed by
Dmitriy Zaporozhets
Apr 19, 2016
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Refactor GitTagPushService and fig tags_push system event hook
parent
ee1090e2
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
27 additions
and
28 deletions
+27
-28
app/services/git_tag_push_service.rb
app/services/git_tag_push_service.rb
+13
-14
app/workers/post_receive.rb
app/workers/post_receive.rb
+2
-2
spec/services/git_tag_push_service_spec.rb
spec/services/git_tag_push_service_spec.rb
+12
-12
No files found.
app/services/git_tag_push_service.rb
View file @
2384bed4
class
GitTagPushService
class
GitTagPushService
<
BaseService
attr_accessor
:p
roject
,
:user
,
:p
ush_data
attr_accessor
:push_data
def
execute
(
project
,
user
,
oldrev
,
newrev
,
ref
)
def
execute
project
.
repository
.
before_push_tag
project
.
repository
.
before_push_tag
@project
,
@user
=
project
,
user
@push_data
=
build_push_data
@push_data
=
build_push_data
(
oldrev
,
newrev
,
ref
)
EventCreateService
.
new
.
push
(
project
,
user
,
@push_data
)
EventCreateService
.
new
.
push
(
project
,
current_
user
,
@push_data
)
SystemHooksService
.
new
.
execute_hooks
(
build_system_push_data
.
dup
,
:tag_push_hooks
)
SystemHooksService
.
new
.
execute_hooks
(
build_system_push_data
.
dup
,
:tag_push_hooks
)
project
.
execute_hooks
(
@push_data
.
dup
,
:tag_push_hooks
)
project
.
execute_hooks
(
@push_data
.
dup
,
:tag_push_hooks
)
project
.
execute_services
(
@push_data
.
dup
,
:tag_push_hooks
)
project
.
execute_services
(
@push_data
.
dup
,
:tag_push_hooks
)
CreateCommitBuildsService
.
new
.
execute
(
project
,
@
user
,
@push_data
)
CreateCommitBuildsService
.
new
.
execute
(
project
,
current_
user
,
@push_data
)
ProjectCacheWorker
.
perform_async
(
project
.
id
)
ProjectCacheWorker
.
perform_async
(
project
.
id
)
true
true
...
@@ -19,14 +18,14 @@ class GitTagPushService
...
@@ -19,14 +18,14 @@ class GitTagPushService
private
private
def
build_push_data
(
oldrev
,
newrev
,
ref
)
def
build_push_data
commits
=
[]
commits
=
[]
message
=
nil
message
=
nil
if
!
Gitlab
::
Git
.
blank_ref?
(
newrev
)
if
!
Gitlab
::
Git
.
blank_ref?
(
params
[
:newrev
]
)
tag_name
=
Gitlab
::
Git
.
ref_name
(
ref
)
tag_name
=
Gitlab
::
Git
.
ref_name
(
params
[
:ref
]
)
tag
=
project
.
repository
.
find_tag
(
tag_name
)
tag
=
project
.
repository
.
find_tag
(
tag_name
)
if
tag
&&
tag
.
target
==
newrev
if
tag
&&
tag
.
target
==
params
[
:newrev
]
commit
=
project
.
commit
(
tag
.
target
)
commit
=
project
.
commit
(
tag
.
target
)
commits
=
[
commit
].
compact
commits
=
[
commit
].
compact
message
=
tag
.
message
message
=
tag
.
message
...
@@ -34,11 +33,11 @@ class GitTagPushService
...
@@ -34,11 +33,11 @@ class GitTagPushService
end
end
Gitlab
::
PushDataBuilder
.
Gitlab
::
PushDataBuilder
.
build
(
project
,
user
,
oldrev
,
newrev
,
ref
,
commits
,
message
)
build
(
project
,
current_user
,
params
[
:oldrev
],
params
[
:newrev
],
params
[
:ref
]
,
commits
,
message
)
end
end
def
build_system_push_data
(
oldrev
,
newrev
,
ref
)
def
build_system_push_data
Gitlab
::
PushDataBuilder
.
Gitlab
::
PushDataBuilder
.
build_system
(
project
,
user
,
oldrev
,
newrev
,
ref
)
build_system
(
project
,
current_user
,
params
[
:oldrev
],
params
[
:newrev
],
params
[
:ref
]
)
end
end
end
end
app/workers/post_receive.rb
View file @
2384bed4
...
@@ -39,7 +39,7 @@ class PostReceive
...
@@ -39,7 +39,7 @@ class PostReceive
end
end
if
Gitlab
::
Git
.
tag_ref?
(
ref
)
if
Gitlab
::
Git
.
tag_ref?
(
ref
)
GitTagPushService
.
new
.
execute
(
post_received
.
project
,
@user
,
oldrev
,
newrev
,
ref
)
GitTagPushService
.
new
(
post_received
.
project
,
@user
,
oldrev:
oldrev
,
newrev:
newrev
,
ref:
ref
).
execute
elsif
Gitlab
::
Git
.
branch_ref?
(
ref
)
elsif
Gitlab
::
Git
.
branch_ref?
(
ref
)
GitPushService
.
new
(
post_received
.
project
,
@user
,
oldrev:
oldrev
,
newrev:
newrev
,
ref:
ref
).
execute
GitPushService
.
new
(
post_received
.
project
,
@user
,
oldrev:
oldrev
,
newrev:
newrev
,
ref:
ref
).
execute
end
end
...
@@ -47,7 +47,7 @@ class PostReceive
...
@@ -47,7 +47,7 @@ class PostReceive
end
end
private
private
def
log
(
message
)
def
log
(
message
)
Gitlab
::
GitLogger
.
error
(
"POST-RECEIVE:
#{
message
}
"
)
Gitlab
::
GitLogger
.
error
(
"POST-RECEIVE:
#{
message
}
"
)
end
end
...
...
spec/services/git_tag_push_service_spec.rb
View file @
2384bed4
...
@@ -5,19 +5,17 @@ describe GitTagPushService, services: true do
...
@@ -5,19 +5,17 @@ describe GitTagPushService, services: true do
let
(
:user
)
{
create
:user
}
let
(
:user
)
{
create
:user
}
let
(
:project
)
{
create
:project
}
let
(
:project
)
{
create
:project
}
let
(
:service
)
{
GitTagPushService
.
new
}
let
(
:service
)
{
GitTagPushService
.
new
(
project
,
user
,
oldrev:
oldrev
,
newrev:
newrev
,
ref:
ref
)
}
before
do
let
(
:oldrev
)
{
Gitlab
::
Git
::
BLANK_SHA
}
@oldrev
=
Gitlab
::
Git
::
BLANK_SHA
let
(
:newrev
)
{
"8a2a6eb295bb170b34c24c76c49ed0e9b2eaf34b"
}
# gitlab-test: git rev-parse refs/tags/v1.1.0
@newrev
=
"8a2a6eb295bb170b34c24c76c49ed0e9b2eaf34b"
# gitlab-test: git rev-parse refs/tags/v1.1.0
let
(
:ref
)
{
'refs/tags/v1.1.0'
}
@ref
=
'refs/tags/v1.1.0'
end
describe
"Git Tag Push Data"
do
describe
"Git Tag Push Data"
do
before
do
before
do
service
.
execute
(
project
,
user
,
@oldrev
,
@newrev
,
@ref
)
service
.
execute
@push_data
=
service
.
push_data
@push_data
=
service
.
push_data
@tag_name
=
Gitlab
::
Git
.
ref_name
(
@
ref
)
@tag_name
=
Gitlab
::
Git
.
ref_name
(
ref
)
@tag
=
project
.
repository
.
find_tag
(
@tag_name
)
@tag
=
project
.
repository
.
find_tag
(
@tag_name
)
@commit
=
project
.
commit
(
@tag
.
target
)
@commit
=
project
.
commit
(
@tag
.
target
)
end
end
...
@@ -25,9 +23,9 @@ describe GitTagPushService, services: true do
...
@@ -25,9 +23,9 @@ describe GitTagPushService, services: true do
subject
{
@push_data
}
subject
{
@push_data
}
it
{
is_expected
.
to
include
(
object_kind:
'tag_push'
)
}
it
{
is_expected
.
to
include
(
object_kind:
'tag_push'
)
}
it
{
is_expected
.
to
include
(
ref:
@
ref
)
}
it
{
is_expected
.
to
include
(
ref:
ref
)
}
it
{
is_expected
.
to
include
(
before:
@
oldrev
)
}
it
{
is_expected
.
to
include
(
before:
oldrev
)
}
it
{
is_expected
.
to
include
(
after:
@
newrev
)
}
it
{
is_expected
.
to
include
(
after:
newrev
)
}
it
{
is_expected
.
to
include
(
message:
@tag
.
message
)
}
it
{
is_expected
.
to
include
(
message:
@tag
.
message
)
}
it
{
is_expected
.
to
include
(
user_id:
user
.
id
)
}
it
{
is_expected
.
to
include
(
user_id:
user
.
id
)
}
it
{
is_expected
.
to
include
(
user_name:
user
.
name
)
}
it
{
is_expected
.
to
include
(
user_name:
user
.
name
)
}
...
@@ -80,9 +78,11 @@ describe GitTagPushService, services: true do
...
@@ -80,9 +78,11 @@ describe GitTagPushService, services: true do
describe
"Webhooks"
do
describe
"Webhooks"
do
context
"execute webhooks"
do
context
"execute webhooks"
do
let
(
:service
)
{
GitTagPushService
.
new
(
project
,
user
,
oldrev:
'oldrev'
,
newrev:
'newrev'
,
ref:
'refs/tags/v1.0.0'
)
}
it
"when pushing tags"
do
it
"when pushing tags"
do
expect
(
project
).
to
receive
(
:execute_hooks
)
expect
(
project
).
to
receive
(
:execute_hooks
)
service
.
execute
(
project
,
user
,
'oldrev'
,
'newrev'
,
'refs/tags/v1.0.0'
)
service
.
execute
end
end
end
end
end
end
...
...
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