diff options
author | Jason Goodman <jgoodman@gitlab.com> | 2019-04-09 06:52:15 +0000 |
---|---|---|
committer | Rémy Coutable <remy@rymai.me> | 2019-04-09 06:52:15 +0000 |
commit | 5b7003282b6b3ce1bfc313b3271bd6827a230c34 (patch) | |
tree | 63ef06c4bb6b87acbcc56d39bdd944a58f06931a /app | |
parent | 74ac04a6aa7a9398ed908f47080e64ec40e0dee8 (diff) | |
download | gitlab-ce-5b7003282b6b3ce1bfc313b3271bd6827a230c34.tar.gz |
Set release name when adding release notes to an existing tag
Also set the release sha and author
Diffstat (limited to 'app')
-rw-r--r-- | app/controllers/projects/tags/releases_controller.rb | 10 | ||||
-rw-r--r-- | app/models/release.rb | 1 | ||||
-rw-r--r-- | app/services/releases/concerns.rb | 2 | ||||
-rw-r--r-- | app/services/releases/create_service.rb | 20 |
4 files changed, 20 insertions, 13 deletions
diff --git a/app/controllers/projects/tags/releases_controller.rb b/app/controllers/projects/tags/releases_controller.rb index 334e1847cc8..5e4c601a693 100644 --- a/app/controllers/projects/tags/releases_controller.rb +++ b/app/controllers/projects/tags/releases_controller.rb @@ -12,16 +12,13 @@ class Projects::Tags::ReleasesController < Projects::ApplicationController end def update - # Release belongs to Tag which is not active record object, - # it exists only to save a description to each Tag. - # If description is empty we should destroy the existing record. if release_params[:description].present? release.update(release_params) else release.destroy end - redirect_to project_tag_path(@project, @tag.name) + redirect_to project_tag_path(@project, tag.name) end private @@ -30,11 +27,10 @@ class Projects::Tags::ReleasesController < Projects::ApplicationController @tag ||= @repository.find_tag(params[:tag_id]) end - # rubocop: disable CodeReuse/ActiveRecord def release - @release ||= @project.releases.find_or_initialize_by(tag: @tag.name) + @release ||= Releases::CreateService.new(project, current_user, tag: @tag.name) + .find_or_build_release end - # rubocop: enable CodeReuse/ActiveRecord def release_params params.require(:release).permit(:description) diff --git a/app/models/release.rb b/app/models/release.rb index 746fc31a038..0f9e94373c7 100644 --- a/app/models/release.rb +++ b/app/models/release.rb @@ -15,6 +15,7 @@ class Release < ApplicationRecord accepts_nested_attributes_for :links, allow_destroy: true validates :description, :project, :tag, presence: true + validates :name, presence: true, on: :create scope :sorted, -> { order(created_at: :desc) } diff --git a/app/services/releases/concerns.rb b/app/services/releases/concerns.rb index a04bb8f9e14..ff6b696ca96 100644 --- a/app/services/releases/concerns.rb +++ b/app/services/releases/concerns.rb @@ -15,7 +15,7 @@ module Releases end def name - params[:name] + params[:name] || tag_name end def description diff --git a/app/services/releases/create_service.rb b/app/services/releases/create_service.rb index c6e143d440d..a271a7e5e49 100644 --- a/app/services/releases/create_service.rb +++ b/app/services/releases/create_service.rb @@ -15,6 +15,10 @@ module Releases create_release(tag) end + def find_or_build_release + release || build_release(existing_tag) + end + private def ensure_tag @@ -38,7 +42,17 @@ module Releases end def create_release(tag) - release = project.releases.create!( + release = build_release(tag) + + release.save! + + success(tag: tag, release: release) + rescue => e + error(e.message, 400) + end + + def build_release(tag) + project.releases.build( name: name, description: description, author: current_user, @@ -46,10 +60,6 @@ module Releases sha: tag.dereferenced_target.sha, links_attributes: params.dig(:assets, 'links') || [] ) - - success(tag: tag, release: release) - rescue => e - error(e.message, 400) end end end |