Commit c5e16007 authored by Stan Hu's avatar Stan Hu

Merge branch...

Merge branch '218287-release-evidence-is-not-being-collected-if-release-is-created-via-ui' into 'master'

Fix creating release evidence via UI

See merge request gitlab-org/gitlab!32441
parents 03081a03 1d49c76a
......@@ -49,6 +49,8 @@ module Releases
notify_create_release(release)
create_evidence!(release)
success(tag: tag, release: release)
rescue => e
error(e.message, 400)
......@@ -70,5 +72,15 @@ module Releases
milestones: milestones
)
end
def create_evidence!(release)
return if release.historical_release?
if release.upcoming_release?
CreateEvidenceWorker.perform_at(release.released_at, release.id)
else
CreateEvidenceWorker.perform_async(release.id)
end
end
end
end
---
title: Fix creating release evidence if release is created via UI
merge_request: 32441
author:
type: fixed
......@@ -67,7 +67,6 @@ module API
if result[:status] == :success
log_release_created_audit_event(result[:release])
create_evidence!
present result[:release], with: Entities::Release, current_user: current_user
else
......@@ -169,16 +168,6 @@ module API
def log_release_milestones_updated_audit_event
# This is a separate method so that EE can extend its behaviour
end
def create_evidence!
return if release.historical_release?
if release.upcoming_release?
CreateEvidenceWorker.perform_at(release.released_at, release.id) # rubocop:disable CodeReuse/Worker
else
CreateEvidenceWorker.perform_async(release.id) # rubocop:disable CodeReuse/Worker
end
end
end
end
end
......
......@@ -10,7 +10,6 @@ describe API::Releases do
let(:guest) { create(:user) }
let(:non_project_member) { create(:user) }
let(:commit) { create(:commit, project: project) }
let(:last_release) { project.releases.last }
before do
project.add_maintainer(maintainer)
......@@ -733,109 +732,6 @@ describe API::Releases do
expect(response).to have_gitlab_http_status(:conflict)
end
end
context 'Evidence collection' do
let(:params) do
{
name: 'New release',
tag_name: 'v0.1',
description: 'Super nice release',
released_at: released_at
}.compact
end
around do |example|
Timecop.freeze { example.run }
end
subject do
post api("/projects/#{project.id}/releases", maintainer), params: params
end
context 'historical release' do
let(:released_at) { 3.weeks.ago }
it 'does not execute CreateEvidenceWorker' do
expect { subject }.not_to change(CreateEvidenceWorker.jobs, :size)
end
it 'does not create an Evidence object', :sidekiq_inline do
expect { subject }.not_to change(Releases::Evidence, :count)
end
it 'is a historical release' do
subject
expect(last_release.historical_release?).to be_truthy
end
it 'is not an upcoming release' do
subject
expect(last_release.upcoming_release?).to be_falsy
end
end
context 'immediate release' do
let(:released_at) { nil }
it 'sets `released_at` to the current dttm' do
subject
expect(last_release.updated_at).to be_like_time(Time.now)
end
it 'queues CreateEvidenceWorker' do
expect { subject }.to change(CreateEvidenceWorker.jobs, :size).by(1)
end
it 'creates Evidence', :sidekiq_inline do
expect { subject }.to change(Releases::Evidence, :count).by(1)
end
it 'is not a historical release' do
subject
expect(last_release.historical_release?).to be_falsy
end
it 'is not an upcoming release' do
subject
expect(last_release.upcoming_release?).to be_falsy
end
end
context 'upcoming release' do
let(:released_at) { 1.day.from_now }
it 'queues CreateEvidenceWorker' do
expect { subject }.to change(CreateEvidenceWorker.jobs, :size).by(1)
end
it 'queues CreateEvidenceWorker at the released_at timestamp' do
subject
expect(CreateEvidenceWorker.jobs.last['at']).to eq(released_at.to_i)
end
it 'creates Evidence', :sidekiq_inline do
expect { subject }.to change(Releases::Evidence, :count).by(1)
end
it 'is not a historical release' do
subject
expect(last_release.historical_release?).to be_falsy
end
it 'is an upcoming release' do
subject
expect(last_release.upcoming_release?).to be_truthy
end
end
end
end
describe 'PUT /projects/:id/releases/:tag_name' do
......
......@@ -186,4 +186,107 @@ describe Releases::CreateService do
end
end
end
context 'Evidence collection' do
let(:params) do
{
name: 'New release',
ref: 'master',
tag: 'v0.1',
description: 'Super nice release',
released_at: released_at
}.compact
end
let(:last_release) { project.releases.last }
around do |example|
Timecop.freeze { example.run }
end
subject { service.execute }
context 'historical release' do
let(:released_at) { 3.weeks.ago }
it 'does not execute CreateEvidenceWorker' do
expect { subject }.not_to change(CreateEvidenceWorker.jobs, :size)
end
it 'does not create an Evidence object', :sidekiq_inline do
expect { subject }.not_to change(Releases::Evidence, :count)
end
it 'is a historical release' do
subject
expect(last_release.historical_release?).to be_truthy
end
it 'is not an upcoming release' do
subject
expect(last_release.upcoming_release?).to be_falsy
end
end
context 'immediate release' do
let(:released_at) { nil }
it 'sets `released_at` to the current dttm' do
subject
expect(last_release.updated_at).to be_like_time(Time.current)
end
it 'queues CreateEvidenceWorker' do
expect { subject }.to change(CreateEvidenceWorker.jobs, :size).by(1)
end
it 'creates Evidence', :sidekiq_inline do
expect { subject }.to change(Releases::Evidence, :count).by(1)
end
it 'is not a historical release' do
subject
expect(last_release.historical_release?).to be_falsy
end
it 'is not an upcoming release' do
subject
expect(last_release.upcoming_release?).to be_falsy
end
end
context 'upcoming release' do
let(:released_at) { 1.day.from_now }
it 'queues CreateEvidenceWorker' do
expect { subject }.to change(CreateEvidenceWorker.jobs, :size).by(1)
end
it 'queues CreateEvidenceWorker at the released_at timestamp' do
subject
expect(CreateEvidenceWorker.jobs.last['at'].to_i).to eq(released_at.to_i)
end
it 'creates Evidence', :sidekiq_inline do
expect { subject }.to change(Releases::Evidence, :count).by(1)
end
it 'is not a historical release' do
subject
expect(last_release.historical_release?).to be_falsy
end
it 'is an upcoming release' do
subject
expect(last_release.upcoming_release?).to be_truthy
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