Refactor release code a bit
Signed-off-by: Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>
This commit is contained in:
parent
14518ba65a
commit
b67fdfff3c
5 changed files with 15 additions and 15 deletions
|
@ -10,9 +10,7 @@ class Projects::ReleasesController < Projects::ApplicationController
|
|||
end
|
||||
|
||||
def update
|
||||
description = params[:release][:description]
|
||||
release.update_attributes(description: description)
|
||||
release.save
|
||||
release.update_attributes(release_params)
|
||||
|
||||
redirect_to namespace_project_tag_path(@project.namespace, @project, @tag.name)
|
||||
end
|
||||
|
@ -26,4 +24,8 @@ class Projects::ReleasesController < Projects::ApplicationController
|
|||
def release
|
||||
@release ||= @project.releases.find_or_initialize_by(tag: @tag.name)
|
||||
end
|
||||
|
||||
def release_params
|
||||
params.require(:release).permit(:description)
|
||||
end
|
||||
end
|
||||
|
|
|
@ -24,12 +24,6 @@ class Projects::TagsController < Projects::ApplicationController
|
|||
if result[:status] == :success
|
||||
@tag = result[:tag]
|
||||
|
||||
if params[:release_description]
|
||||
release = @project.releases.find_or_initialize_by(tag: @tag.name)
|
||||
release.update_attributes(description: params[:release_description])
|
||||
release.save
|
||||
end
|
||||
|
||||
redirect_to namespace_project_tag_path(@project.namespace, @project, @tag.name)
|
||||
else
|
||||
@error = result[:message]
|
||||
|
@ -39,8 +33,6 @@ class Projects::TagsController < Projects::ApplicationController
|
|||
|
||||
def destroy
|
||||
DeleteTagService.new(project, current_user).execute(params[:id])
|
||||
release = project.releases.find_by(tag: params[:id])
|
||||
release.destroy if release
|
||||
|
||||
redirect_to namespace_project_tags_path(@project.namespace, @project)
|
||||
end
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
class Release < ActiveRecord::Base
|
||||
belongs_to :project
|
||||
|
||||
validates :description, :project, presence: true
|
||||
validates :description, :project, :tag, presence: true
|
||||
end
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
require_relative 'base_service'
|
||||
|
||||
class CreateTagService < BaseService
|
||||
def execute(tag_name, ref, message)
|
||||
def execute(tag_name, ref, message, release_description = nil)
|
||||
valid_tag = Gitlab::GitRefValidator.validate(tag_name)
|
||||
if valid_tag == false
|
||||
return error('Tag name invalid')
|
||||
|
@ -19,8 +19,12 @@ class CreateTagService < BaseService
|
|||
new_tag = repository.find_tag(tag_name)
|
||||
|
||||
if new_tag
|
||||
push_data = create_push_data(project, current_user, new_tag)
|
||||
if release_description
|
||||
release = project.releases.find_or_initialize_by(tag: tag_name)
|
||||
release.update_attributes(description: release_description)
|
||||
end
|
||||
|
||||
push_data = create_push_data(project, current_user, new_tag)
|
||||
EventCreateService.new.push(project, current_user, push_data)
|
||||
project.execute_hooks(push_data.dup, :tag_push_hooks)
|
||||
project.execute_services(push_data.dup, :tag_push_hooks)
|
||||
|
|
|
@ -11,8 +11,10 @@ class DeleteTagService < BaseService
|
|||
end
|
||||
|
||||
if repository.rm_tag(tag_name)
|
||||
release = project.releases.find_by(tag: tag_name)
|
||||
release.destroy if release
|
||||
|
||||
push_data = build_push_data(tag)
|
||||
|
||||
EventCreateService.new.push(project, current_user, push_data)
|
||||
project.execute_hooks(push_data.dup, :tag_push_hooks)
|
||||
project.execute_services(push_data.dup, :tag_push_hooks)
|
||||
|
|
Loading…
Reference in a new issue