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
iv
gitlab-ce
Commits
39211391
Commit
39211391
authored
Jul 27, 2014
by
Robert Schilling
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Validate tag-names and references in WebUI, API
parent
551145bc
Changes
9
Show whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
152 additions
and
20 deletions
+152
-20
app/controllers/projects/tags_controller.rb
app/controllers/projects/tags_controller.rb
+9
-4
app/services/create_tag_service.rb
app/services/create_tag_service.rb
+26
-1
app/views/projects/tags/new.html.haml
app/views/projects/tags/new.html.haml
+6
-2
doc/api/repositories.md
doc/api/repositories.md
+3
-0
features/project/commits/branches.feature
features/project/commits/branches.feature
+4
-4
features/project/commits/tags.feature
features/project/commits/tags.feature
+20
-0
features/steps/project/browse_tags.rb
features/steps/project/browse_tags.rb
+45
-1
lib/api/repositories.rb
lib/api/repositories.rb
+9
-4
spec/requests/api/repositories_spec.rb
spec/requests/api/repositories_spec.rb
+30
-4
No files found.
app/controllers/projects/tags_controller.rb
View file @
39211391
...
@@ -13,10 +13,15 @@ class Projects::TagsController < Projects::ApplicationController
...
@@ -13,10 +13,15 @@ class Projects::TagsController < Projects::ApplicationController
end
end
def
create
def
create
@tag
=
CreateTagService
.
new
.
execute
(
@project
,
params
[
:tag_name
],
result
=
CreateTagService
.
new
.
execute
(
@project
,
params
[
:tag_name
],
params
[
:ref
],
current_user
)
params
[
:ref
],
current_user
)
if
result
[
:status
]
==
:success
@tag
=
result
[
:tag
]
redirect_to
project_tags_path
(
@project
)
redirect_to
project_tags_path
(
@project
)
else
@error
=
result
[
:message
]
render
action:
'new'
end
end
end
def
destroy
def
destroy
...
...
app/services/create_tag_service.rb
View file @
39211391
class
CreateTagService
class
CreateTagService
def
execute
(
project
,
tag_name
,
ref
,
current_user
)
def
execute
(
project
,
tag_name
,
ref
,
current_user
)
valid_tag
=
Gitlab
::
GitRefValidator
.
validate
(
tag_name
)
if
valid_tag
==
false
return
error
(
'Tag name invalid'
)
end
repository
=
project
.
repository
repository
=
project
.
repository
existing_tag
=
repository
.
find_tag
(
tag_name
)
if
existing_tag
return
error
(
'Tag already exists'
)
end
repository
.
add_tag
(
tag_name
,
ref
)
repository
.
add_tag
(
tag_name
,
ref
)
new_tag
=
repository
.
find_tag
(
tag_name
)
new_tag
=
repository
.
find_tag
(
tag_name
)
if
new_tag
if
new_tag
Event
.
create_ref_event
(
project
,
current_user
,
new_tag
,
'add'
,
'refs/tags'
)
Event
.
create_ref_event
(
project
,
current_user
,
new_tag
,
'add'
,
'refs/tags'
)
return
success
(
new_tag
)
else
return
error
(
'Invalid reference name'
)
end
end
def
error
(
message
)
{
message:
message
,
status: :error
}
end
end
new_tag
def
success
(
branch
)
{
tag:
branch
,
status: :success
}
end
end
end
end
app/views/projects/tags/new.html.haml
View file @
39211391
-
if
@error
.alert.alert-danger
%button
{
type:
"button"
,
class:
"close"
,
"data-dismiss"
=>
"alert"
}
×
=
@error
%h3
.page-title
%h3
.page-title
%i
.icon-code-fork
%i
.icon-code-fork
New tag
New tag
...
@@ -5,11 +9,11 @@
...
@@ -5,11 +9,11 @@
.form-group
.form-group
=
label_tag
:tag_name
,
'Name for new tag'
,
class:
'control-label'
=
label_tag
:tag_name
,
'Name for new tag'
,
class:
'control-label'
.col-sm-10
.col-sm-10
=
text_field_tag
:tag_name
,
nil
,
placeholder:
'v3.0.1'
,
required:
true
,
tabindex:
1
,
class:
'form-control'
=
text_field_tag
:tag_name
,
params
[
:tag_name
]
,
placeholder:
'v3.0.1'
,
required:
true
,
tabindex:
1
,
class:
'form-control'
.form-group
.form-group
=
label_tag
:ref
,
'Create from'
,
class:
'control-label'
=
label_tag
:ref
,
'Create from'
,
class:
'control-label'
.col-sm-10
.col-sm-10
=
text_field_tag
:ref
,
nil
,
placeholder:
'master'
,
required:
true
,
tabindex:
2
,
class:
'form-control'
=
text_field_tag
:ref
,
params
[
:ref
]
,
placeholder:
'master'
,
required:
true
,
tabindex:
2
,
class:
'form-control'
.light
Branch name or commit SHA
.light
Branch name or commit SHA
.form-actions
.form-actions
=
submit_tag
'Create tag'
,
class:
'btn btn-create'
,
tabindex:
3
=
submit_tag
'Create tag'
,
class:
'btn btn-create'
,
tabindex:
3
...
...
doc/api/repositories.md
View file @
39211391
...
@@ -71,6 +71,9 @@ Parameters:
...
@@ -71,6 +71,9 @@ Parameters:
]
]
```
```
It returns 200 if the operation succeed. In case of an error,
405 with an explaining error message is returned.
## List repository tree
## List repository tree
Get a list of repository files and directories in a project.
Get a list of repository files and directories in a project.
...
...
features/project/commits/branches.feature
View file @
39211391
...
@@ -15,7 +15,7 @@ Feature: Project Browse branches
...
@@ -15,7 +15,7 @@ Feature: Project Browse branches
Scenario
:
I
create a branch
Scenario
:
I
create a branch
Given
I visit project branches page
Given
I visit project branches page
And
I click new branch link
And
I click new branch link
When
I submit new branch form
And
I submit new branch form
Then
I should see new branch created
Then
I should see new branch created
@javascript
@javascript
...
@@ -27,17 +27,17 @@ Feature: Project Browse branches
...
@@ -27,17 +27,17 @@ Feature: Project Browse branches
Scenario
:
I
create a branch with invalid name
Scenario
:
I
create a branch with invalid name
Given
I visit project branches page
Given
I visit project branches page
And
I click new branch link
And
I click new branch link
When
I submit new branch form with invalid name
And
I submit new branch form with invalid name
Then
I should see new an error that branch is invalid
Then
I should see new an error that branch is invalid
Scenario
:
I
create a branch with invalid reference
Scenario
:
I
create a branch with invalid reference
Given
I visit project branches page
Given
I visit project branches page
And
I click new branch link
And
I click new branch link
When
I submit new branch form with invalid reference
And
I submit new branch form with invalid reference
Then
I should see new an error that ref is invalid
Then
I should see new an error that ref is invalid
Scenario
:
I
create a branch that already exists
Scenario
:
I
create a branch that already exists
Given
I visit project branches page
Given
I visit project branches page
And
I click new branch link
And
I click new branch link
When
I submit new branch form with branch that already exists
And
I submit new branch form with branch that already exists
Then
I should see new an error that branch already exists
Then
I should see new an error that branch already exists
features/project/commits/tags.feature
View file @
39211391
...
@@ -7,5 +7,25 @@ Feature: Project Browse tags
...
@@ -7,5 +7,25 @@ Feature: Project Browse tags
Scenario
:
I
can see all git tags
Scenario
:
I
can see all git tags
Then
I should see
"Shop"
all tags list
Then
I should see
"Shop"
all tags list
Scenario
:
I
create a tag
And
I click new tag link
And
I submit new tag form
Then
I should see new tag created
Scenario
:
I
create a tag with invalid name
And
I click new tag link
And
I submit new tag form with invalid name
Then
I should see new an error that tag is invalid
Scenario
:
I
create a tag with invalid reference
And
I click new tag link
And
I submit new tag form with invalid reference
Then
I should see new an error that tag ref is invalid
Scenario
:
I
create a tag that already exists
And
I click new tag link
And
I submit new tag form with tag that already exists
Then
I should see new an error that tag already exists
# @wip
# @wip
# Scenario: I can download project by tag
# Scenario: I can download project by tag
features/steps/project/browse_tags.rb
View file @
39211391
...
@@ -3,8 +3,52 @@ class ProjectBrowseTags < Spinach::FeatureSteps
...
@@ -3,8 +3,52 @@ class ProjectBrowseTags < Spinach::FeatureSteps
include
SharedProject
include
SharedProject
include
SharedPaths
include
SharedPaths
Then
'I should see "Shop" all tags list'
do
step
'I should see "Shop" all tags list'
do
page
.
should
have_content
"Tags"
page
.
should
have_content
"Tags"
page
.
should
have_content
"v1.0.0"
page
.
should
have_content
"v1.0.0"
end
end
step
'I click new tag link'
do
click_link
'New tag'
end
step
'I submit new tag form'
do
fill_in
'tag_name'
,
with:
'v7.0'
fill_in
'ref'
,
with:
'master'
click_button
'Create tag'
end
step
'I submit new tag form with invalid name'
do
fill_in
'tag_name'
,
with:
'v 1.0'
fill_in
'ref'
,
with:
'master'
click_button
'Create tag'
end
step
'I submit new tag form with invalid reference'
do
fill_in
'tag_name'
,
with:
'foo'
fill_in
'ref'
,
with:
'foo'
click_button
'Create tag'
end
step
'I submit new tag form with tag that already exists'
do
fill_in
'tag_name'
,
with:
'v1.0.0'
fill_in
'ref'
,
with:
'master'
click_button
'Create tag'
end
step
'I should see new tag created'
do
page
.
should
have_content
'v7.0'
end
step
'I should see new an error that tag is invalid'
do
page
.
should
have_content
'Tag name invalid'
end
step
'I should see new an error that tag ref is invalid'
do
page
.
should
have_content
'Invalid reference name'
end
step
'I should see new an error that tag already exists'
do
page
.
should
have_content
'Tag already exists'
end
end
end
lib/api/repositories.rb
View file @
39211391
...
@@ -36,10 +36,15 @@ module API
...
@@ -36,10 +36,15 @@ module API
# POST /projects/:id/repository/tags
# POST /projects/:id/repository/tags
post
':id/repository/tags'
do
post
':id/repository/tags'
do
authorize_push_project
authorize_push_project
@tag
=
CreateTagService
.
new
.
execute
(
user_project
,
params
[
:tag_name
],
result
=
CreateTagService
.
new
.
execute
(
user_project
,
params
[
:tag_name
],
params
[
:ref
],
current_user
)
params
[
:ref
],
current_user
)
if
result
[
:status
]
==
:success
present
@tag
,
with:
Entities
::
RepoObject
,
project:
user_project
present
result
[
:tag
],
with:
Entities
::
RepoObject
,
project:
user_project
else
render_api_error!
(
result
[
:message
],
400
)
end
end
end
# Get a project repository tree
# Get a project repository tree
...
...
spec/requests/api/repositories_spec.rb
View file @
39211391
...
@@ -25,20 +25,46 @@ describe API::API, api: true do
...
@@ -25,20 +25,46 @@ describe API::API, api: true do
describe
'POST /projects/:id/repository/tags'
do
describe
'POST /projects/:id/repository/tags'
do
it
'should create a new tag'
do
it
'should create a new tag'
do
post
api
(
"/projects/
#{
project
.
id
}
/repository/tags"
,
user
),
post
api
(
"/projects/
#{
project
.
id
}
/repository/tags"
,
user
),
tag_name:
'v
1
.0.0'
,
tag_name:
'v
2
.0.0'
,
ref:
'master'
ref:
'master'
response
.
status
.
should
==
201
response
.
status
.
should
==
201
json_response
[
'name'
].
should
==
'v
1
.0.0'
json_response
[
'name'
].
should
==
'v
2
.0.0'
end
end
it
'should deny for user without push access'
do
it
'should deny for user without push access'
do
post
api
(
"/projects/
#{
project
.
id
}
/repository/tags"
,
user2
),
post
api
(
"/projects/
#{
project
.
id
}
/repository/tags"
,
user2
),
tag_name:
'v1.0.0'
,
tag_name:
'v1.0.0'
,
ref:
'621491c677087aa243f165eab467bfdfbee00be1'
ref:
'621491c677087aa243f165eab467bfdfbee00be1'
response
.
status
.
should
==
403
response
.
status
.
should
==
403
end
end
it
'should return 400 if tag name is invalid'
do
post
api
(
"/projects/
#{
project
.
id
}
/repository/tags"
,
user
),
tag_name:
'v 1.0.0'
,
ref:
'master'
response
.
status
.
should
==
400
json_response
[
'message'
].
should
==
'Tag name invalid'
end
it
'should return 400 if tag already exists'
do
post
api
(
"/projects/
#{
project
.
id
}
/repository/tags"
,
user
),
tag_name:
'v8.0.0'
,
ref:
'master'
response
.
status
.
should
==
201
post
api
(
"/projects/
#{
project
.
id
}
/repository/tags"
,
user
),
tag_name:
'v8.0.0'
,
ref:
'master'
response
.
status
.
should
==
400
json_response
[
'message'
].
should
==
'Tag already exists'
end
it
'should return 400 if ref name is invalid'
do
post
api
(
"/projects/
#{
project
.
id
}
/repository/tags"
,
user
),
tag_name:
'mytag'
,
ref:
'foo'
response
.
status
.
should
==
400
json_response
[
'message'
].
should
==
'Invalid reference name'
end
end
end
describe
"GET /projects/:id/repository/tree"
do
describe
"GET /projects/:id/repository/tree"
do
...
...
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