Commit a7b5d2aa authored by Etienne Baqué's avatar Etienne Baqué

Added evidence_sha to Release API entity

Updated Release API and docs.
Updated Release model.
Added tests accordingly.
parent fbcdd6f7
......@@ -73,6 +73,10 @@ class Release < ApplicationRecord
self.read_attribute(:name) || tag
end
def evidence_sha
evidence&.summary_sha
end
private
def actual_sha
......
......@@ -87,6 +87,7 @@ Example response:
],
"commit_path":"/root/awesome-app/commit/588440f66559714280628a4f9799f0c4eb880a4a",
"tag_path":"/root/awesome-app/-/tags/v0.11.1",
"evidence_sha":"760d6cdfb0879c3ffedec13af470e0f71cf52c6cde4d",
"assets":{
"count":6,
"sources":[
......@@ -154,6 +155,7 @@ Example response:
"committer_email":"admin@example.com",
"committed_date":"2019-01-03T01:53:28.000Z"
},
"evidence_sha":"760d6cdfb0879c3ffedec13af470e0f71cf52c6cde4d",
"assets":{
"count":4,
"sources":[
......@@ -265,6 +267,7 @@ Example response:
],
"commit_path":"/root/awesome-app/commit/588440f66559714280628a4f9799f0c4eb880a4a",
"tag_path":"/root/awesome-app/-/tags/v0.11.1",
"evidence_sha":"760d6cdfb0879c3ffedec13af470e0f71cf52c6cde4d",
"assets":{
"count":4,
"sources":[
......@@ -385,6 +388,7 @@ Example response:
],
"commit_path":"/root/awesome-app/commit/588440f66559714280628a4f9799f0c4eb880a4a",
"tag_path":"/root/awesome-app/-/tags/v0.11.1",
"evidence_sha":"760d6cdfb0879c3ffedec13af470e0f71cf52c6cde4d",
"assets":{
"count":5,
"sources":[
......@@ -491,6 +495,7 @@ Example response:
],
"commit_path":"/root/awesome-app/commit/588440f66559714280628a4f9799f0c4eb880a4a",
"tag_path":"/root/awesome-app/-/tags/v0.11.1",
"evidence_sha":"760d6cdfb0879c3ffedec13af470e0f71cf52c6cde4d",
"assets":{
"count":4,
"sources":[
......@@ -573,6 +578,7 @@ Example response:
},
"commit_path":"/root/awesome-app/commit/588440f66559714280628a4f9799f0c4eb880a4a",
"tag_path":"/root/awesome-app/-/tags/v0.11.1",
"evidence_sha":"760d6cdfb0879c3ffedec13af470e0f71cf52c6cde4d",
"assets":{
"count":4,
"sources":[
......
......@@ -1315,6 +1315,7 @@ module API
expose :milestones, using: Entities::Milestone, if: -> (release, _) { release.milestones.present? }
expose :commit_path, expose_nil: false
expose :tag_path, expose_nil: false
expose :evidence_sha, if: -> (release, _) { release.evidence.present? }
expose :assets do
expose :assets_count, as: :count do |release, _|
assets_to_exclude = can_download_code? ? [] : [:sources]
......
......@@ -141,4 +141,25 @@ RSpec.describe Release do
end
end
end
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
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
expect(release.evidence_sha).to eq(release.evidence.summary_sha)
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