Commit eb9dfa19 authored by Sean Carroll's avatar Sean Carroll Committed by Michael Kozono

Make name optional for release entity

Use tag if release name is blank

Closes https://gitlab.com/gitlab-org/gitlab/issues/31868

See merge request https://gitlab.com/gitlab-org/gitlab/merge_requests/19705
parent 2f96acf8
......@@ -21,7 +21,13 @@ module Emails
private
def release_email_subject
release_info = [@release.name, @release.tag].select(&:presence).join(' - ')
release_info =
if @release.name == @release.tag
@release.tag
else
[@release.name, @release.tag].select(&:presence).join(' - ')
end
"New release: #{release_info}"
end
end
......
......@@ -69,6 +69,10 @@ class Release < ApplicationRecord
released_at.present? && released_at > Time.zone.now
end
def name
self.read_attribute(:name) || tag
end
private
def actual_sha
......
---
title: Made `name` optional parameter of Release entity
merge_request: 19705
author:
type: changed
......@@ -303,7 +303,7 @@ POST /projects/:id/releases
| Attribute | Type | Required | Description |
| -------------------| --------------- | -------- | -------------------------------------------------------------------------------------------------------------------------------- |
| `id` | integer/string | yes | The ID or [URL-encoded path of the project](../README.md#namespaced-path-encoding). |
| `name` | string | yes | The release name. |
| `name` | string | no | The release name. |
| `tag_name` | string | yes | The tag where the release will be created from. |
| `description` | string | yes | The description of the release. You can use [markdown](../../user/markdown.md). |
| `ref` | string | yes, if `tag_name` doesn't exist | If `tag_name` doesn't exist, the release will be created from `ref`. It can be a commit SHA, another tag name, or a branch name. |
......
......@@ -1299,7 +1299,9 @@ module API
class Release < Grape::Entity
include ::API::Helpers::Presentable
expose :name
expose :name do |release, _|
can_download_code? ? release.name : "Release-#{release.id}"
end
expose :tag, as: :tag_name, if: ->(_, _) { can_download_code? }
expose :description
expose :description_html do |entity|
......
......@@ -45,7 +45,7 @@ module API
end
params do
requires :tag_name, type: String, desc: 'The name of the tag', as: :tag
requires :name, type: String, desc: 'The name of the release'
optional :name, type: String, desc: 'The name of the release'
requires :description, type: String, desc: 'The release notes'
optional :ref, type: String, desc: 'The commit sha or branch name'
optional :assets, type: Hash do
......
{
"type": "object",
"required": ["name", "tag_name"],
"required": ["tag_name", "description"],
"properties": {
"name": { "type": "string" },
"tag_name": { "type": "string" },
"ref": { "type": "string "},
"description": { "type": "string" },
"description_html": { "type": "string" },
"created_at": { "type": "date" },
......
......@@ -18,6 +18,7 @@ describe Emails::Releases do
context 'when the release has a name' do
it 'shows the correct subject' do
release.name = 'beta-1'
expected_subject = "#{release.project.name} | New release: #{release.name} - #{release.tag}"
is_expected.to have_subject(expected_subject)
end
......
......@@ -27,7 +27,7 @@ describe Evidence do
let(:release) { create(:release, project: project, name: nil) }
it 'creates a valid JSON object' do
expect(release.name).to be_nil
expect(release.name).to eq(release.tag)
expect(summary_json).to match_schema(schema_file)
end
end
......
......@@ -34,7 +34,7 @@ RSpec.describe Release do
expect(existing_release_without_name).to be_valid
expect(existing_release_without_name.description).to eq("change")
expect(existing_release_without_name.name).to be_nil
expect(existing_release_without_name.name).not_to be_nil
end
end
......@@ -129,4 +129,16 @@ RSpec.describe Release do
end
end
end
describe '#name' do
context 'name is nil' do
before do
release.update(name: nil)
end
it 'returns tag' do
expect(release.name).to eq(release.tag)
end
end
end
end
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