Commit 075460a3 authored by Sean Carroll's avatar Sean Carroll

Optional name for Release entity

Release entity is accessed via the API, the name attribute is optional.
If set to nil the tag will be returned instead.

Closes #31868
parent 29cabf06
Pipeline #94720611 failed with stages
in 29 minutes and 20 seconds
......@@ -21,7 +21,11 @@ module Emails
private
def release_email_subject
release_info = [@release.name, @release.tag].select(&:presence).join(' - ')
if @release.name == @release.tag
release_info = @release.tag
else
release_info = [@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: https://gitlab.com/gitlab-org/gitlab/merge_requests/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. |
......
......@@ -1298,7 +1298,9 @@ module API
class Release < Grape::Entity
include ::API::Helpers::Presentable
expose :name
expose :name do |release, options|
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
......
......@@ -129,4 +129,14 @@ RSpec.describe Release do
end
end
end
describe '#name' do
context 'name is nil' do
before { release.update(name: nil) }
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