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
87f4767e
Commit
87f4767e
authored
Feb 15, 2017
by
Rémy Coutable
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'move_tags_service_to_namespace' into 'master'
Move tag services to `Tags` namespace See merge request !9231
parents
5a13470a
613856fa
Changes
9
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
86 additions
and
78 deletions
+86
-78
app/controllers/projects/tags_controller.rb
app/controllers/projects/tags_controller.rb
+2
-2
app/services/create_tag_service.rb
app/services/create_tag_service.rb
+0
-30
app/services/delete_tag_service.rb
app/services/delete_tag_service.rb
+0
-42
app/services/tags/create_service.rb
app/services/tags/create_service.rb
+32
-0
app/services/tags/destroy_service.rb
app/services/tags/destroy_service.rb
+44
-0
changelogs/unreleased/move_tags_service_to_namespace.yml
changelogs/unreleased/move_tags_service_to_namespace.yml
+4
-0
lib/api/tags.rb
lib/api/tags.rb
+2
-2
spec/services/tags/create_service_spec.rb
spec/services/tags/create_service_spec.rb
+1
-1
spec/services/tags/destroy_service_spec.rb
spec/services/tags/destroy_service_spec.rb
+1
-1
No files found.
app/controllers/projects/tags_controller.rb
View file @
87f4767e
...
@@ -27,7 +27,7 @@ class Projects::TagsController < Projects::ApplicationController
...
@@ -27,7 +27,7 @@ class Projects::TagsController < Projects::ApplicationController
end
end
def
create
def
create
result
=
CreateTag
Service
.
new
(
@project
,
current_user
).
result
=
Tags
::
Create
Service
.
new
(
@project
,
current_user
).
execute
(
params
[
:tag_name
],
params
[
:ref
],
params
[
:message
],
params
[
:release_description
])
execute
(
params
[
:tag_name
],
params
[
:ref
],
params
[
:message
],
params
[
:release_description
])
if
result
[
:status
]
==
:success
if
result
[
:status
]
==
:success
...
@@ -41,7 +41,7 @@ class Projects::TagsController < Projects::ApplicationController
...
@@ -41,7 +41,7 @@ class Projects::TagsController < Projects::ApplicationController
end
end
def
destroy
def
destroy
DeleteTag
Service
.
new
(
project
,
current_user
).
execute
(
params
[
:id
])
Tags
::
Destroy
Service
.
new
(
project
,
current_user
).
execute
(
params
[
:id
])
respond_to
do
|
format
|
respond_to
do
|
format
|
format
.
html
do
format
.
html
do
...
...
app/services/create_tag_service.rb
deleted
100644 → 0
View file @
5a13470a
class
CreateTagService
<
BaseService
def
execute
(
tag_name
,
target
,
message
,
release_description
=
nil
)
valid_tag
=
Gitlab
::
GitRefValidator
.
validate
(
tag_name
)
return
error
(
'Tag name invalid'
)
unless
valid_tag
repository
=
project
.
repository
message
&
.
strip!
new_tag
=
nil
begin
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
return
error
(
ex
.
message
)
end
if
new_tag
if
release_description
CreateReleaseService
.
new
(
@project
,
@current_user
).
execute
(
tag_name
,
release_description
)
end
success
.
merge
(
tag:
new_tag
)
else
error
(
"Target
#{
target
}
is invalid"
)
end
end
end
app/services/delete_tag_service.rb
deleted
100644 → 0
View file @
5a13470a
class
DeleteTagService
<
BaseService
def
execute
(
tag_name
)
repository
=
project
.
repository
tag
=
repository
.
find_tag
(
tag_name
)
unless
tag
return
error
(
'No such tag'
,
404
)
end
if
repository
.
rm_tag
(
current_user
,
tag_name
)
release
=
project
.
releases
.
find_by
(
tag:
tag_name
)
release
&
.
destroy
push_data
=
build_push_data
(
tag
)
EventCreateService
.
new
.
push
(
project
,
current_user
,
push_data
)
project
.
execute_hooks
(
push_data
.
dup
,
:tag_push_hooks
)
project
.
execute_services
(
push_data
.
dup
,
:tag_push_hooks
)
success
(
'Tag was removed'
)
else
error
(
'Failed to remove tag'
)
end
end
def
error
(
message
,
return_code
=
400
)
super
(
message
).
merge
(
return_code:
return_code
)
end
def
success
(
message
)
super
().
merge
(
message:
message
)
end
def
build_push_data
(
tag
)
Gitlab
::
DataBuilder
::
Push
.
build
(
project
,
current_user
,
tag
.
dereferenced_target
.
sha
,
Gitlab
::
Git
::
BLANK_SHA
,
"
#{
Gitlab
::
Git
::
TAG_REF_PREFIX
}#{
tag
.
name
}
"
,
[])
end
end
app/services/tags/create_service.rb
0 → 100644
View file @
87f4767e
module
Tags
class
CreateService
<
BaseService
def
execute
(
tag_name
,
target
,
message
,
release_description
=
nil
)
valid_tag
=
Gitlab
::
GitRefValidator
.
validate
(
tag_name
)
return
error
(
'Tag name invalid'
)
unless
valid_tag
repository
=
project
.
repository
message
&
.
strip!
new_tag
=
nil
begin
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
return
error
(
ex
.
message
)
end
if
new_tag
if
release_description
CreateReleaseService
.
new
(
@project
,
@current_user
).
execute
(
tag_name
,
release_description
)
end
success
.
merge
(
tag:
new_tag
)
else
error
(
"Target
#{
target
}
is invalid"
)
end
end
end
end
app/services/tags/destroy_service.rb
0 → 100644
View file @
87f4767e
module
Tags
class
DestroyService
<
BaseService
def
execute
(
tag_name
)
repository
=
project
.
repository
tag
=
repository
.
find_tag
(
tag_name
)
unless
tag
return
error
(
'No such tag'
,
404
)
end
if
repository
.
rm_tag
(
current_user
,
tag_name
)
release
=
project
.
releases
.
find_by
(
tag:
tag_name
)
release
&
.
destroy
push_data
=
build_push_data
(
tag
)
EventCreateService
.
new
.
push
(
project
,
current_user
,
push_data
)
project
.
execute_hooks
(
push_data
.
dup
,
:tag_push_hooks
)
project
.
execute_services
(
push_data
.
dup
,
:tag_push_hooks
)
success
(
'Tag was removed'
)
else
error
(
'Failed to remove tag'
)
end
end
def
error
(
message
,
return_code
=
400
)
super
(
message
).
merge
(
return_code:
return_code
)
end
def
success
(
message
)
super
().
merge
(
message:
message
)
end
def
build_push_data
(
tag
)
Gitlab
::
DataBuilder
::
Push
.
build
(
project
,
current_user
,
tag
.
dereferenced_target
.
sha
,
Gitlab
::
Git
::
BLANK_SHA
,
"
#{
Gitlab
::
Git
::
TAG_REF_PREFIX
}#{
tag
.
name
}
"
,
[])
end
end
end
changelogs/unreleased/move_tags_service_to_namespace.yml
0 → 100644
View file @
87f4767e
---
title
:
Move tag services to Tags namespace
merge_request
:
author
:
dixpac
lib/api/tags.rb
View file @
87f4767e
...
@@ -40,7 +40,7 @@ module API
...
@@ -40,7 +40,7 @@ module API
post
':id/repository/tags'
do
post
':id/repository/tags'
do
authorize_push_project
authorize_push_project
result
=
CreateTag
Service
.
new
(
user_project
,
current_user
).
result
=
::
Tags
::
Create
Service
.
new
(
user_project
,
current_user
).
execute
(
params
[
:tag_name
],
params
[
:ref
],
params
[
:message
],
params
[
:release_description
])
execute
(
params
[
:tag_name
],
params
[
:ref
],
params
[
:message
],
params
[
:release_description
])
if
result
[
:status
]
==
:success
if
result
[
:status
]
==
:success
...
@@ -59,7 +59,7 @@ module API
...
@@ -59,7 +59,7 @@ module API
delete
":id/repository/tags/:tag_name"
,
requirements:
{
tag_name:
/.+/
}
do
delete
":id/repository/tags/:tag_name"
,
requirements:
{
tag_name:
/.+/
}
do
authorize_push_project
authorize_push_project
result
=
DeleteTag
Service
.
new
(
user_project
,
current_user
).
result
=
::
Tags
::
Destroy
Service
.
new
(
user_project
,
current_user
).
execute
(
params
[
:tag_name
])
execute
(
params
[
:tag_name
])
if
result
[
:status
]
==
:success
if
result
[
:status
]
==
:success
...
...
spec/services/
create_tag
_service_spec.rb
→
spec/services/
tags/create
_service_spec.rb
View file @
87f4767e
require
'spec_helper'
require
'spec_helper'
describe
CreateTag
Service
,
services:
true
do
describe
Tags
::
Create
Service
,
services:
true
do
let
(
:project
)
{
create
(
:project
)
}
let
(
:project
)
{
create
(
:project
)
}
let
(
:repository
)
{
project
.
repository
}
let
(
:repository
)
{
project
.
repository
}
let
(
:user
)
{
create
(
:user
)
}
let
(
:user
)
{
create
(
:user
)
}
...
...
spec/services/
delete_tag
_service_spec.rb
→
spec/services/
tags/destroy
_service_spec.rb
View file @
87f4767e
require
'spec_helper'
require
'spec_helper'
describe
DeleteTag
Service
,
services:
true
do
describe
Tags
::
Destroy
Service
,
services:
true
do
let
(
:project
)
{
create
(
:project
)
}
let
(
:project
)
{
create
(
:project
)
}
let
(
:repository
)
{
project
.
repository
}
let
(
:repository
)
{
project
.
repository
}
let
(
:user
)
{
create
(
:user
)
}
let
(
:user
)
{
create
(
:user
)
}
...
...
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