Commit 6fdd9008 authored by Dmitriy Zaporozhets's avatar Dmitriy Zaporozhets

Merge pull request #7014 from asedge/api_create_tag

Add CreateTagService.  Use new service to allow tag creation through API.
parents ec837932 28de31f5
...@@ -13,11 +13,8 @@ class Projects::TagsController < Projects::ApplicationController ...@@ -13,11 +13,8 @@ class Projects::TagsController < Projects::ApplicationController
end end
def create def create
@repository.add_tag(params[:tag_name], params[:ref]) @tag = CreateTagService.new.execute(@project, params[:tag_name],
params[:ref], current_user)
if new_tag = @repository.find_tag(params[:tag_name])
Event.create_ref_event(@project, current_user, new_tag, 'add', 'refs/tags')
end
redirect_to project_tags_path(@project) redirect_to project_tags_path(@project)
end end
......
class CreateTagService
def execute(project, tag_name, ref, current_user)
repository = project.repository
repository.add_tag(tag_name, ref)
new_tag = repository.find_tag(tag_name)
if new_tag
Event.create_ref_event(project, current_user, new_tag, 'add', 'refs/tags')
end
new_tag
end
end
...@@ -37,6 +37,40 @@ Parameters: ...@@ -37,6 +37,40 @@ Parameters:
] ]
``` ```
## Create a new tag
Creates new tag in the repository that points to the supplied ref.
```
POST /projects/:id/repository/tags
```
Parameters:
+ `id` (required) - The ID of a project
+ `tag_name` (required) - The name of a tag
+ `ref` (required) - Create tag using commit sha, another tag name, or branch name.
```json
[
{
"name": "v1.0.0",
"commit": {
"id": "2695effb5807a22ff3d138d593fd856244e155e7",
"parents": [],
"message": "Initial commit",
"authored_date": "2012-05-28T04:42:42-07:00",
"author_name": "John Smith",
"author email": "john@example.com",
"committer_name": "Jack Smith",
"committed_date": "2012-05-28T04:42:42-07:00",
"committer_email": "jack@example.com"
},
"protected": false
}
]
```
## 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.
......
...@@ -26,6 +26,22 @@ module API ...@@ -26,6 +26,22 @@ module API
present user_project.repo.tags.sort_by(&:name).reverse, with: Entities::RepoObject, project: user_project present user_project.repo.tags.sort_by(&:name).reverse, with: Entities::RepoObject, project: user_project
end end
# Create tag
#
# Parameters:
# id (required) - The ID of a project
# tag_name (required) - The name of the tag
# ref (required) - Create tag from commit sha or branch
# Example Request:
# POST /projects/:id/repository/tags
post ':id/repository/tags' do
authorize_push_project
@tag = CreateTagService.new.execute(user_project, params[:tag_name],
params[:ref], current_user)
present @tag, with: Entities::RepoObject, project: user_project
end
# Get a project repository tree # Get a project repository tree
# #
# Parameters: # Parameters:
......
...@@ -23,6 +23,24 @@ describe API::API, api: true do ...@@ -23,6 +23,24 @@ describe API::API, api: true do
end end
end end
describe 'POST /projects/:id/repository/tags' do
it 'should create a new tag' do
post api("/projects/#{project.id}/repository/tags", user),
tag_name: 'v1.0.0',
ref: 'master'
response.status.should == 201
json_response['name'].should == 'v1.0.0'
end
it 'should deny for user without push access' do
post api("/projects/#{project.id}/repository/tags", user2),
tag_name: 'v1.0.0',
ref: '621491c677087aa243f165eab467bfdfbee00be1'
response.status.should == 403
end
end
describe "GET /projects/:id/repository/tree" do describe "GET /projects/:id/repository/tree" do
context "authorized user" do context "authorized user" do
before { project.team << [user2, :reporter] } before { project.team << [user2, :reporter] }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment