diff options
-rw-r--r-- | app/controllers/projects/tags_controller.rb | 7 | ||||
-rw-r--r-- | app/services/create_tag_service.rb | 13 | ||||
-rw-r--r-- | doc/api/repositories.md | 34 | ||||
-rw-r--r-- | lib/api/repositories.rb | 16 | ||||
-rw-r--r-- | spec/requests/api/repositories_spec.rb | 18 |
5 files changed, 83 insertions, 5 deletions
diff --git a/app/controllers/projects/tags_controller.rb b/app/controllers/projects/tags_controller.rb index 0b99165bf62..e03a9f4d66d 100644 --- a/app/controllers/projects/tags_controller.rb +++ b/app/controllers/projects/tags_controller.rb @@ -13,11 +13,8 @@ class Projects::TagsController < Projects::ApplicationController end def create - @repository.add_tag(params[:tag_name], params[:ref]) - - if new_tag = @repository.find_tag(params[:tag_name]) - Event.create_ref_event(@project, current_user, new_tag, 'add', 'refs/tags') - end + @tag = CreateTagService.new.execute(@project, params[:tag_name], + params[:ref], current_user) redirect_to project_tags_path(@project) end diff --git a/app/services/create_tag_service.rb b/app/services/create_tag_service.rb new file mode 100644 index 00000000000..97766677405 --- /dev/null +++ b/app/services/create_tag_service.rb @@ -0,0 +1,13 @@ +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 diff --git a/doc/api/repositories.md b/doc/api/repositories.md index ecb0fa3f6a0..26ae3e87232 100644 --- a/doc/api/repositories.md +++ b/doc/api/repositories.md @@ -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 Get a list of repository files and directories in a project. diff --git a/lib/api/repositories.rb b/lib/api/repositories.rb index a587d4a7bdf..03806d9343b 100644 --- a/lib/api/repositories.rb +++ b/lib/api/repositories.rb @@ -26,6 +26,22 @@ module API present user_project.repo.tags.sort_by(&:name).reverse, with: Entities::RepoObject, project: user_project 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 # # Parameters: diff --git a/spec/requests/api/repositories_spec.rb b/spec/requests/api/repositories_spec.rb index a902a1542cc..5afb3bddcb7 100644 --- a/spec/requests/api/repositories_spec.rb +++ b/spec/requests/api/repositories_spec.rb @@ -23,6 +23,24 @@ describe API::API, api: true do 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 context "authorized user" do before { project.team << [user2, :reporter] } |