Skip to content
Snippets Groups Projects
Commit 7ecffe29 authored by Jason Goodman's avatar Jason Goodman Committed by Nick Thomas
Browse files

Show upcoming status for releases

Add released_at field to releases API
Add released_at column to releases table
Return releases to the API sorted by released_at
parent d6391c65
No related branches found
No related tags found
No related merge requests found
Showing
with 93 additions and 20 deletions
Loading
Loading
@@ -28,7 +28,7 @@ export default {
computed: {
releasedTimeAgo() {
return sprintf(__('released %{time}'), {
time: this.timeFormated(this.release.created_at),
time: this.timeFormated(this.release.released_at),
});
},
userImageAltDescription() {
Loading
Loading
@@ -56,8 +56,8 @@ export default {
<div class="card-body">
<h2 class="card-title mt-0">
{{ release.name }}
<gl-badge v-if="release.pre_release" variant="warning" class="align-middle">{{
__('Pre-release')
<gl-badge v-if="release.upcoming_release" variant="warning" class="align-middle">{{
__('Upcoming Release')
}}</gl-badge>
</h2>
 
Loading
Loading
@@ -74,7 +74,7 @@ export default {
 
<div class="append-right-4">
&bull;
<span v-gl-tooltip.bottom :title="tooltipTitle(release.created_at)">
<span v-gl-tooltip.bottom :title="tooltipTitle(release.released_at)">
{{ releasedTimeAgo }}
</span>
</div>
Loading
Loading
Loading
Loading
@@ -12,12 +12,16 @@ class Release < ApplicationRecord
 
has_many :links, class_name: 'Releases::Link'
 
default_value_for :released_at, allows_nil: false do
Time.zone.now
end
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) }
scope :sorted, -> { order(released_at: :desc) }
 
delegate :repository, to: :project
 
Loading
Loading
@@ -44,6 +48,10 @@ class Release < ApplicationRecord
end
end
 
def upcoming_release?
released_at.present? && released_at > Time.zone.now
end
private
 
def actual_sha
Loading
Loading
Loading
Loading
@@ -22,6 +22,10 @@ module Releases
params[:description]
end
 
def released_at
params[:released_at]
end
def release
strong_memoize(:release) do
project.releases.find_by_tag(tag_name)
Loading
Loading
Loading
Loading
@@ -58,6 +58,7 @@ module Releases
author: current_user,
tag: tag.name,
sha: tag.dereferenced_target.sha,
released_at: released_at,
links_attributes: params.dig(:assets, 'links') || []
)
end
Loading
Loading
---
title: Show an Upcoming Status for Releases
merge_request: 29577
author:
type: added
# frozen_string_literal: true
class AddReleasedAtToReleasesTable < ActiveRecord::Migration[5.1]
include Gitlab::Database::MigrationHelpers
DOWNTIME = false
def change
add_column(:releases, :released_at, :datetime_with_timezone)
end
end
# frozen_string_literal: true
class BackfillAndAddNotNullConstraintToReleasedAtColumnOnReleasesTable < ActiveRecord::Migration[5.1]
include Gitlab::Database::MigrationHelpers
DOWNTIME = false
disable_ddl_transaction!
def up
update_column_in_batches(:releases, :released_at, Arel.sql('created_at'))
change_column_null(:releases, :released_at, false)
end
def down
change_column_null(:releases, :released_at, true)
end
end
Loading
Loading
@@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.
 
ActiveRecord::Schema.define(version: 20190628145246) do
ActiveRecord::Schema.define(version: 20190628185004) do
 
# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"
Loading
Loading
@@ -2902,6 +2902,7 @@ ActiveRecord::Schema.define(version: 20190628145246) do
t.integer "author_id"
t.string "name"
t.string "sha"
t.datetime_with_timezone "released_at", null: false
t.index ["author_id"], name: "index_releases_on_author_id", using: :btree
t.index ["project_id", "tag"], name: "index_releases_on_project_id_and_tag", using: :btree
t.index ["project_id"], name: "index_releases_on_project_id", using: :btree
Loading
Loading
Loading
Loading
@@ -1186,8 +1186,10 @@ module API
MarkupHelper.markdown_field(entity, :description)
end
expose :created_at
expose :released_at
expose :author, using: Entities::UserBasic, if: -> (release, _) { release.author.present? }
expose :commit, using: Entities::Commit, if: lambda { |_, _| can_download_code? }
expose :upcoming_release?, as: :upcoming_release
 
expose :assets do
expose :assets_count, as: :count do |release, _|
Loading
Loading
Loading
Loading
@@ -54,6 +54,7 @@ module API
requires :url, type: String
end
end
optional :released_at, type: DateTime, desc: 'The date when the release will be/was ready. Defaults to the current time.'
end
post ':id/releases' do
authorize_create_release!
Loading
Loading
@@ -77,6 +78,7 @@ module API
requires :tag_name, type: String, desc: 'The name of the tag', as: :tag
optional :name, type: String, desc: 'The name of the release'
optional :description, type: String, desc: 'Release notes with markdown support'
optional :released_at, type: DateTime, desc: 'The date when the release will be/was ready. Defaults to the current time.'
end
put ':id/releases/:tag_name', requirements: RELEASE_ENDPOINT_REQUIREMETS do
authorize_update_release!
Loading
Loading
Loading
Loading
@@ -10,6 +10,7 @@ module Gitlab
name: raw_data.name,
description: raw_data.body,
created_at: raw_data.created_at,
released_at: raw_data.published_at,
updated_at: raw_data.created_at
}
end
Loading
Loading
Loading
Loading
@@ -7574,9 +7574,6 @@ msgstr ""
msgid "Please wait while we import the repository for you. Refresh at will."
msgstr ""
 
msgid "Pre-release"
msgstr ""
msgid "Preferences"
msgstr ""
 
Loading
Loading
@@ -11378,6 +11375,9 @@ msgstr ""
msgid "Upcoming"
msgstr ""
 
msgid "Upcoming Release"
msgstr ""
msgid "Update"
msgstr ""
 
Loading
Loading
Loading
Loading
@@ -6,6 +6,7 @@ FactoryBot.define do
description "Awesome release"
project
author
released_at { Time.zone.parse('2018-10-20T18:00:00Z') }
 
trait :legacy do
sha nil
Loading
Loading
Loading
Loading
@@ -16,6 +16,7 @@ describe 'User views releases', :js do
 
expect(page).to have_content(release.name)
expect(page).to have_content(release.tag)
expect(page).not_to have_content('Upcoming Release')
end
 
context 'when there is a link as an asset' do
Loading
Loading
@@ -43,4 +44,15 @@ describe 'User views releases', :js do
end
end
end
context 'with an upcoming release' do
let(:tomorrow) { Time.zone.now + 1.day }
let!(:release) { create(:release, project: project, released_at: tomorrow ) }
it 'sees the upcoming tag' do
visit project_releases_path(project)
expect(page).to have_content('Upcoming Release')
end
end
end
Loading
Loading
@@ -12,8 +12,8 @@ describe ReleasesFinder do
subject { described_class.new(project, user)}
 
before do
v1_0_0.update_attribute(:created_at, 2.days.ago)
v1_1_0.update_attribute(:created_at, 1.day.ago)
v1_0_0.update_attribute(:released_at, 2.days.ago)
v1_1_0.update_attribute(:released_at, 1.day.ago)
end
 
describe '#execute' do
Loading
Loading
@@ -30,7 +30,7 @@ describe ReleasesFinder do
project.add_developer(user)
end
 
it 'sorts by creation date' do
it 'sorts by release date' do
releases = subject.execute
 
expect(releases).to be_present
Loading
Loading
{
"type": "object",
"required": ["name", "tag_name", "commit"],
"required": ["name", "tag_name", "commit", "released_at"],
"properties": {
"name": { "type": "string" },
"tag_name": { "type": "string" },
"description": { "type": "string" },
"description_html": { "type": "string" },
"created_at": { "type": "date" },
"released_at": { "type": "date" },
"upcoming_release": { "type": "boolean" },
"commit": {
"oneOf": [{ "type": "null" }, { "$ref": "commit/basic.json" }]
},
Loading
Loading
{
"type": "object",
"required": ["name"],
"required": ["name", "released_at"],
"properties": {
"name": { "type": "string" },
"description": { "type": "string" },
"description_html": { "type": "string" },
"created_at": { "type": "date" },
"released_at": { "type": "date" },
"upcoming_release": { "type": "boolean" },
"author": {
"oneOf": [{ "type": "null" }, { "$ref": "../user/basic.json" }]
},
Loading
Loading
Loading
Loading
@@ -14,7 +14,7 @@ describe('Release block', () => {
description_html: '<div><h2>changelog</h2><ul><li>line1</li<li>line 2</li></ul></div>',
author_name: 'Release bot',
author_email: 'release-bot@example.com',
created_at: '2012-05-28T05:00:00-07:00',
released_at: '2012-05-28T05:00:00-07:00',
author: {
avatar_url: 'uploads/-/system/user/avatar/johndoe/avatar.png',
id: 482476,
Loading
Loading
@@ -101,7 +101,7 @@ describe('Release block', () => {
});
 
it('renders release date', () => {
expect(vm.$el.textContent).toContain(timeagoMixin.methods.timeFormated(release.created_at));
expect(vm.$el.textContent).toContain(timeagoMixin.methods.timeFormated(release.released_at));
});
 
it('renders number of assets provided', () => {
Loading
Loading
@@ -152,13 +152,13 @@ describe('Release block', () => {
});
});
 
describe('with pre_release flag', () => {
describe('with upcoming_release flag', () => {
beforeEach(() => {
vm = factory(Object.assign({}, release, { pre_release: true }));
vm = factory(Object.assign({}, release, { upcoming_release: true }));
});
 
it('renders pre-release badge', () => {
expect(vm.$el.textContent).toContain('Pre-release');
it('renders upcoming release badge', () => {
expect(vm.$el.textContent).toContain('Upcoming Release');
});
});
});
Loading
Loading
@@ -123,6 +123,7 @@ Release:
- project_id
- created_at
- updated_at
- released_at
Releases::Link:
- id
- release_id
Loading
Loading
Loading
Loading
@@ -132,6 +132,7 @@ describe Gitlab::LegacyGithubImport::Importer do
body: 'Release v1.0.0',
draft: false,
created_at: created_at,
published_at: created_at,
updated_at: updated_at,
url: "#{api_root}/repos/octocat/Hello-World/releases/1"
)
Loading
Loading
@@ -144,6 +145,7 @@ describe Gitlab::LegacyGithubImport::Importer do
body: nil,
draft: false,
created_at: created_at,
published_at: created_at,
updated_at: updated_at,
url: "#{api_root}/repos/octocat/Hello-World/releases/2"
)
Loading
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment