summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSean Edge <asedge@gmail.com>2014-06-23 21:35:36 -0400
committerSean Edge <asedge@gmail.com>2014-09-04 09:47:20 -0400
commit468b2e8e0b46e7a7cee7cc9d9ce9b5c22e79c467 (patch)
treec19de65b8133c26a38a9813b9c6c5be412842e75
parent487f78be129d44ae3dc098c9bd17925975435097 (diff)
downloadgitlab-ce-468b2e8e0b46e7a7cee7cc9d9ce9b5c22e79c467.tar.gz
Added annotated tags. Updated tag haml file and call to gitlab-shell. Updated API for annotated tags. Added tests for API. Strip leading/trailing whitespace from message, if present. Update CHANGELOG.
-rw-r--r--CHANGELOG1
-rw-r--r--app/controllers/projects/tags_controller.rb3
-rw-r--r--app/models/repository.rb4
-rw-r--r--app/services/create_tag_service.rb8
-rw-r--r--app/views/projects/tags/new.html.haml5
-rw-r--r--doc/api/repositories.md1
-rw-r--r--lib/api/repositories.rb5
-rw-r--r--lib/gitlab/backend/shell.rb9
-rw-r--r--spec/requests/api/repositories_spec.rb29
9 files changed, 51 insertions, 14 deletions
diff --git a/CHANGELOG b/CHANGELOG
index f9cd92a83c6..ac44c0db2ea 100644
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -15,6 +15,7 @@ v 7.3.0
- API: filter issues by labels (Julien Bianchi)
- Add system hook for ssh key changes
- Add blob permalink link (Ciro Santilli)
+ - Create annotated tags through UI and API (Sean Edge)
v 7.2.0
- Explore page
diff --git a/app/controllers/projects/tags_controller.rb b/app/controllers/projects/tags_controller.rb
index b84c497131a..86788b9963b 100644
--- a/app/controllers/projects/tags_controller.rb
+++ b/app/controllers/projects/tags_controller.rb
@@ -14,7 +14,8 @@ class Projects::TagsController < Projects::ApplicationController
def create
result = CreateTagService.new.execute(@project, params[:tag_name],
- params[:ref], current_user)
+ params[:ref], params[:message],
+ current_user)
if result[:status] == :success
@tag = result[:tag]
redirect_to project_tags_path(@project)
diff --git a/app/models/repository.rb b/app/models/repository.rb
index e970c449a73..9dd8603621f 100644
--- a/app/models/repository.rb
+++ b/app/models/repository.rb
@@ -64,10 +64,10 @@ class Repository
gitlab_shell.add_branch(path_with_namespace, branch_name, ref)
end
- def add_tag(tag_name, ref)
+ def add_tag(tag_name, ref, message = nil)
Rails.cache.delete(cache_key(:tag_names))
- gitlab_shell.add_tag(path_with_namespace, tag_name, ref)
+ gitlab_shell.add_tag(path_with_namespace, tag_name, ref, message)
end
def rm_branch(branch_name)
diff --git a/app/services/create_tag_service.rb b/app/services/create_tag_service.rb
index 6869acbe467..3716abd4b2b 100644
--- a/app/services/create_tag_service.rb
+++ b/app/services/create_tag_service.rb
@@ -1,5 +1,5 @@
class CreateTagService
- def execute(project, tag_name, ref, current_user)
+ def execute(project, tag_name, ref, message, current_user)
valid_tag = Gitlab::GitRefValidator.validate(tag_name)
if valid_tag == false
return error('Tag name invalid')
@@ -11,7 +11,11 @@ class CreateTagService
return error('Tag already exists')
end
- repository.add_tag(tag_name, ref)
+ if message
+ message.gsub!(/^\s+|\s+$/, '')
+ end
+
+ repository.add_tag(tag_name, ref, message)
new_tag = repository.find_tag(tag_name)
if new_tag
diff --git a/app/views/projects/tags/new.html.haml b/app/views/projects/tags/new.html.haml
index f3a34d37df5..45ee61caf68 100644
--- a/app/views/projects/tags/new.html.haml
+++ b/app/views/projects/tags/new.html.haml
@@ -15,6 +15,11 @@
.col-sm-10
= text_field_tag :ref, params[:ref], placeholder: 'master', required: true, tabindex: 2, class: 'form-control'
.light Branch name or commit SHA
+ .form-group
+ = label_tag :message, 'Message', class: 'control-label'
+ .col-sm-10
+ = text_field_tag :message, nil, placeholder: 'Enter message.', required: false, tabindex: 3, class: 'form-control'
+ .light (Optional) Entering a message will create an annotated tag.
.form-actions
= submit_tag 'Create tag', class: 'btn btn-create', tabindex: 3
= link_to 'Cancel', project_tags_path(@project), class: 'btn btn-cancel'
diff --git a/doc/api/repositories.md b/doc/api/repositories.md
index c9f6a45c347..a412f60c0d9 100644
--- a/doc/api/repositories.md
+++ b/doc/api/repositories.md
@@ -50,6 +50,7 @@ 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.
+- `message` (optional) - Creates annotated tag.
```json
[
diff --git a/lib/api/repositories.rb b/lib/api/repositories.rb
index a3773d2c593..ce89177ef65 100644
--- a/lib/api/repositories.rb
+++ b/lib/api/repositories.rb
@@ -32,12 +32,15 @@ module API
# id (required) - The ID of a project
# tag_name (required) - The name of the tag
# ref (required) - Create tag from commit sha or branch
+ # message (optional) - Specifying a message creates an annotated tag.
# Example Request:
# POST /projects/:id/repository/tags
post ':id/repository/tags' do
authorize_push_project
+ message = params[:message] || nil
result = CreateTagService.new.execute(user_project, params[:tag_name],
- params[:ref], current_user)
+ params[:ref], message,
+ current_user)
if result[:status] == :success
present result[:tag],
with: Entities::RepoObject,
diff --git a/lib/gitlab/backend/shell.rb b/lib/gitlab/backend/shell.rb
index 53bff3037e5..907373ab991 100644
--- a/lib/gitlab/backend/shell.rb
+++ b/lib/gitlab/backend/shell.rb
@@ -107,12 +107,17 @@ module Gitlab
# path - project path with namespace
# tag_name - new tag name
# ref - HEAD for new tag
+ # message - optional message for tag (annotated tag)
#
# Ex.
# add_tag("gitlab/gitlab-ci", "v4.0", "master")
+ # add_tag("gitlab/gitlab-ci", "v4.0", "master", "message")
#
- def add_tag(path, tag_name, ref)
- system "#{gitlab_shell_path}/bin/gitlab-projects", "create-tag", "#{path}.git", tag_name, ref
+ def add_tag(path, tag_name, ref, message = nil)
+ cmd = %W(#{gitlab_shell_path}/bin/gitlab-projects create-tag #{path}.git
+ #{tag_name} #{ref})
+ cmd << message unless message.nil? || message.empty?
+ system *cmd
end
# Remove repository tag
diff --git a/spec/requests/api/repositories_spec.rb b/spec/requests/api/repositories_spec.rb
index ffcdbc4255e..3ada945ae05 100644
--- a/spec/requests/api/repositories_spec.rb
+++ b/spec/requests/api/repositories_spec.rb
@@ -23,12 +23,29 @@ describe API::API, api: true do
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: 'v2.0.0',
- ref: 'master'
- response.status.should == 201
- json_response['name'].should == 'v2.0.0'
+ context 'lightweight 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
+ end
+ context 'annotated tag' do
+ it 'should create a new annotated tag' do
+ post api("/projects/#{project.id}/repository/tags", user),
+ tag_name: 'v1.0.0',
+ ref: 'master',
+ message: 'tag message'
+
+ response.status.should == 201
+ json_response['name'].should == 'v1.0.0'
+ # The message is not part of the JSON response.
+ # Additional changes to the gitlab_git gem may be required.
+ # json_response['message'].should == 'tag message'
+ end
end
it 'should deny for user without push access' do