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 ...@@ -21,7 +21,13 @@ module Emails
private private
def release_email_subject 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}" "New release: #{release_info}"
end end
end end
......
...@@ -69,6 +69,10 @@ class Release < ApplicationRecord ...@@ -69,6 +69,10 @@ class Release < ApplicationRecord
released_at.present? && released_at > Time.zone.now released_at.present? && released_at > Time.zone.now
end end
def name
self.read_attribute(:name) || tag
end
private private
def actual_sha 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 ...@@ -303,7 +303,7 @@ POST /projects/:id/releases
| Attribute | Type | Required | Description | | Attribute | Type | Required | Description |
| -------------------| --------------- | -------- | -------------------------------------------------------------------------------------------------------------------------------- | | -------------------| --------------- | -------- | -------------------------------------------------------------------------------------------------------------------------------- |
| `id` | integer/string | yes | The ID or [URL-encoded path of the project](../README.md#namespaced-path-encoding). | | `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. | | `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). | | `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. | | `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 ...@@ -1299,7 +1299,9 @@ module API
class Release < Grape::Entity class Release < Grape::Entity
include ::API::Helpers::Presentable 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 :tag, as: :tag_name, if: ->(_, _) { can_download_code? }
expose :description expose :description
expose :description_html do |entity| expose :description_html do |entity|
......
...@@ -45,7 +45,7 @@ module API ...@@ -45,7 +45,7 @@ module API
end end
params do params do
requires :tag_name, type: String, desc: 'The name of the tag', as: :tag 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' requires :description, type: String, desc: 'The release notes'
optional :ref, type: String, desc: 'The commit sha or branch name' optional :ref, type: String, desc: 'The commit sha or branch name'
optional :assets, type: Hash do optional :assets, type: Hash do
......
{ {
"type": "object", "type": "object",
"required": ["name", "tag_name"], "required": ["tag_name", "description"],
"properties": { "properties": {
"name": { "type": "string" }, "name": { "type": "string" },
"tag_name": { "type": "string" }, "tag_name": { "type": "string" },
"ref": { "type": "string "},
"description": { "type": "string" }, "description": { "type": "string" },
"description_html": { "type": "string" }, "description_html": { "type": "string" },
"created_at": { "type": "date" }, "created_at": { "type": "date" },
......
...@@ -18,6 +18,7 @@ describe Emails::Releases do ...@@ -18,6 +18,7 @@ describe Emails::Releases do
context 'when the release has a name' do context 'when the release has a name' do
it 'shows the correct subject' do it 'shows the correct subject' do
release.name = 'beta-1'
expected_subject = "#{release.project.name} | New release: #{release.name} - #{release.tag}" expected_subject = "#{release.project.name} | New release: #{release.name} - #{release.tag}"
is_expected.to have_subject(expected_subject) is_expected.to have_subject(expected_subject)
end end
......
...@@ -27,7 +27,7 @@ describe Evidence do ...@@ -27,7 +27,7 @@ describe Evidence do
let(:release) { create(:release, project: project, name: nil) } let(:release) { create(:release, project: project, name: nil) }
it 'creates a valid JSON object' do 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) expect(summary_json).to match_schema(schema_file)
end end
end end
......
...@@ -34,7 +34,7 @@ RSpec.describe Release do ...@@ -34,7 +34,7 @@ RSpec.describe Release do
expect(existing_release_without_name).to be_valid expect(existing_release_without_name).to be_valid
expect(existing_release_without_name.description).to eq("change") 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
end end
...@@ -129,4 +129,16 @@ RSpec.describe Release do ...@@ -129,4 +129,16 @@ RSpec.describe Release do
end end
end 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 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