Commit b67fdfff authored by Dmitriy Zaporozhets's avatar Dmitriy Zaporozhets

Refactor release code a bit

Signed-off-by: default avatarDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>
parent 14518ba6
...@@ -10,9 +10,7 @@ class Projects::ReleasesController < Projects::ApplicationController ...@@ -10,9 +10,7 @@ class Projects::ReleasesController < Projects::ApplicationController
end end
def update def update
description = params[:release][:description] release.update_attributes(release_params)
release.update_attributes(description: description)
release.save
redirect_to namespace_project_tag_path(@project.namespace, @project, @tag.name) redirect_to namespace_project_tag_path(@project.namespace, @project, @tag.name)
end end
...@@ -26,4 +24,8 @@ class Projects::ReleasesController < Projects::ApplicationController ...@@ -26,4 +24,8 @@ class Projects::ReleasesController < Projects::ApplicationController
def release def release
@release ||= @project.releases.find_or_initialize_by(tag: @tag.name) @release ||= @project.releases.find_or_initialize_by(tag: @tag.name)
end end
def release_params
params.require(:release).permit(:description)
end
end end
...@@ -24,12 +24,6 @@ class Projects::TagsController < Projects::ApplicationController ...@@ -24,12 +24,6 @@ class Projects::TagsController < Projects::ApplicationController
if result[:status] == :success if result[:status] == :success
@tag = result[:tag] @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) redirect_to namespace_project_tag_path(@project.namespace, @project, @tag.name)
else else
@error = result[:message] @error = result[:message]
...@@ -39,8 +33,6 @@ class Projects::TagsController < Projects::ApplicationController ...@@ -39,8 +33,6 @@ class Projects::TagsController < Projects::ApplicationController
def destroy def destroy
DeleteTagService.new(project, current_user).execute(params[:id]) 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) redirect_to namespace_project_tags_path(@project.namespace, @project)
end end
......
class Release < ActiveRecord::Base class Release < ActiveRecord::Base
belongs_to :project belongs_to :project
validates :description, :project, presence: true validates :description, :project, :tag, presence: true
end end
require_relative 'base_service' require_relative 'base_service'
class CreateTagService < BaseService 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) valid_tag = Gitlab::GitRefValidator.validate(tag_name)
if valid_tag == false if valid_tag == false
return error('Tag name invalid') return error('Tag name invalid')
...@@ -19,8 +19,12 @@ class CreateTagService < BaseService ...@@ -19,8 +19,12 @@ class CreateTagService < BaseService
new_tag = repository.find_tag(tag_name) new_tag = repository.find_tag(tag_name)
if new_tag 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) EventCreateService.new.push(project, current_user, push_data)
project.execute_hooks(push_data.dup, :tag_push_hooks) project.execute_hooks(push_data.dup, :tag_push_hooks)
project.execute_services(push_data.dup, :tag_push_hooks) project.execute_services(push_data.dup, :tag_push_hooks)
......
...@@ -11,8 +11,10 @@ class DeleteTagService < BaseService ...@@ -11,8 +11,10 @@ class DeleteTagService < BaseService
end end
if repository.rm_tag(tag_name) if repository.rm_tag(tag_name)
push_data = build_push_data(tag) 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) EventCreateService.new.push(project, current_user, push_data)
project.execute_hooks(push_data.dup, :tag_push_hooks) project.execute_hooks(push_data.dup, :tag_push_hooks)
project.execute_services(push_data.dup, :tag_push_hooks) project.execute_services(push_data.dup, :tag_push_hooks)
......
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