Commit 02b3446e authored by Etienne Baqué's avatar Etienne Baqué

Added evidence_url to Release API

Added url to evidence JSON in release payload.
Updated asset count.
Added tests for release asset count.
parent 8c8030bb
......@@ -55,8 +55,9 @@ class Release < ApplicationRecord
def assets_count(except: [])
links_count = links.count
sources_count = except.include?(:sources) ? 0 : sources.count
count = links_count + sources_count
links_count + sources_count
evidence.present? ? count + 1 : count
end
def sources
......
......@@ -37,6 +37,12 @@ class ReleasePresenter < Gitlab::View::Presenter::Delegated
edit_project_release_url(project, release)
end
def evidence_url
return unless release_evidence_available?
evidence_project_release_url(project, tag, format: :json)
end
private
def can_download_code?
......@@ -54,4 +60,8 @@ class ReleasePresenter < Gitlab::View::Presenter::Delegated
def release_edit_page_available?
::Feature.enabled?(:release_edit_page, project, default_enabled: true)
end
def release_evidence_available?
release.evidence.present?
end
end
......@@ -89,7 +89,7 @@ Example response:
"tag_path":"/root/awesome-app/-/tags/v0.11.1",
"evidence_sha":"760d6cdfb0879c3ffedec13af470e0f71cf52c6cde4d",
"assets":{
"count":6,
"count":7,
"sources":[
{
"format":"zip",
......@@ -121,7 +121,8 @@ Example response:
"url":"http://192.168.10.15:3000",
"external":true
}
]
],
"evidence_url":"https://gitlab.example.com/root/awesome-app/-/releases/v0.2/evidence.json"
},
},
{
......@@ -157,7 +158,7 @@ Example response:
},
"evidence_sha":"760d6cdfb0879c3ffedec13af470e0f71cf52c6cde4d",
"assets":{
"count":4,
"count":5,
"sources":[
{
"format":"zip",
......@@ -178,7 +179,8 @@ Example response:
],
"links":[
]
],
"evidence_url":"https://gitlab.example.com/root/awesome-app/-/releases/v0.1/evidence.json"
},
}
]
......@@ -269,7 +271,7 @@ Example response:
"tag_path":"/root/awesome-app/-/tags/v0.11.1",
"evidence_sha":"760d6cdfb0879c3ffedec13af470e0f71cf52c6cde4d",
"assets":{
"count":4,
"count":5,
"sources":[
{
"format":"zip",
......@@ -290,7 +292,8 @@ Example response:
],
"links":[
]
],
"evidence_url":"https://gitlab.example.com/root/awesome-app/-/releases/v0.1/evidence.json"
},
}
```
......@@ -390,7 +393,7 @@ Example response:
"tag_path":"/root/awesome-app/-/tags/v0.11.1",
"evidence_sha":"760d6cdfb0879c3ffedec13af470e0f71cf52c6cde4d",
"assets":{
"count":5,
"count":6,
"sources":[
{
"format":"zip",
......@@ -416,7 +419,8 @@ Example response:
"url":"https://google.com",
"external":true
}
]
],
"evidence_url":"https://gitlab.example.com/root/awesome-app/-/releases/v0.3/evidence.json"
},
}
```
......@@ -497,7 +501,7 @@ Example response:
"tag_path":"/root/awesome-app/-/tags/v0.11.1",
"evidence_sha":"760d6cdfb0879c3ffedec13af470e0f71cf52c6cde4d",
"assets":{
"count":4,
"count":5,
"sources":[
{
"format":"zip",
......@@ -518,7 +522,8 @@ Example response:
],
"links":[
]
],
"evidence_url":"https://gitlab.example.com/root/awesome-app/-/releases/v0.1/evidence.json"
},
}
```
......@@ -580,7 +585,7 @@ Example response:
"tag_path":"/root/awesome-app/-/tags/v0.11.1",
"evidence_sha":"760d6cdfb0879c3ffedec13af470e0f71cf52c6cde4d",
"assets":{
"count":4,
"count":5,
"sources":[
{
"format":"zip",
......@@ -601,7 +606,8 @@ Example response:
],
"links":[
]
],
"evidence_url":"https://gitlab.example.com/root/awesome-app/-/releases/v0.1/evidence.json"
},
}
```
......
......@@ -1325,6 +1325,7 @@ module API
expose :links, using: Entities::Releases::Link do |release, options|
release.links.sorted
end
expose :evidence_url, expose_nil: false
end
expose :_links do
expose :merge_requests_url, expose_nil: false
......
......@@ -182,15 +182,14 @@ describe Projects::ReleasesController do
before do
sign_in(user)
CreateEvidenceWorker.new.perform(release.id)
end
it 'returns the correct evidence summary as a json' do
it 'returns the correct evidence summary as a json', :sidekiq_inline do
subject
expect(response.body).to eq(release.evidence.summary.to_json)
end
context 'when the release was created before evidence existed' do
context 'when the release was created before evidence existed', :sidekiq_inline do
it 'returns an empty json' do
release.evidence.destroy
subject
......
......@@ -72,6 +72,13 @@ RSpec.describe Release do
expect(assets_count).to eq(1)
end
end
context 'when evidence is available' do
it 'counts this evidence', :sidekiq_inline do
evidence_count = release.assets_count - release.sources.count - release.links.count
expect(evidence_count).to eq(1)
end
end
end
describe '#sources' do
......@@ -145,19 +152,15 @@ RSpec.describe Release do
describe '#evidence_sha' do
let!(:release) { create(:release) }
before do
CreateEvidenceWorker.new.perform(release.id)
end
context 'when a release was created before evidence collection existed' do
it 'is nil' do
it 'is nil', :sidekiq_inline do
allow(release).to receive(:evidence).and_return(nil)
expect(release.evidence_sha).to be_nil
end
end
context 'when a release was created with evidence collection' do
it 'returns the summary sha' do
it 'returns the summary sha', :sidekiq_inline do
expect(release.evidence_sha).to eq(release.evidence.summary_sha)
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