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.
This commit is contained in:
parent
487f78be12
commit
468b2e8e0b
9 changed files with 51 additions and 14 deletions
|
@ -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
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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'
|
||||
|
|
|
@ -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
|
||||
[
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue