2019-10-17 11:06:17 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2020-03-24 08:09:42 -04:00
|
|
|
class Releases::Evidence < ApplicationRecord
|
2019-10-17 11:06:17 -04:00
|
|
|
include ShaAttribute
|
2020-03-24 08:09:42 -04:00
|
|
|
include Presentable
|
2019-10-17 11:06:17 -04:00
|
|
|
|
2020-03-24 08:09:42 -04:00
|
|
|
belongs_to :release, inverse_of: :evidences
|
2019-10-17 11:06:17 -04:00
|
|
|
|
|
|
|
before_validation :generate_summary_and_sha
|
|
|
|
|
|
|
|
default_scope { order(created_at: :asc) }
|
|
|
|
|
|
|
|
sha_attribute :summary_sha
|
2020-03-24 08:09:42 -04:00
|
|
|
alias_attribute :collected_at, :created_at
|
2019-10-17 11:06:17 -04:00
|
|
|
|
|
|
|
def milestones
|
|
|
|
@milestones ||= release.milestones.includes(:issues)
|
|
|
|
end
|
|
|
|
|
2020-01-02 16:07:38 -05:00
|
|
|
##
|
|
|
|
# Return `summary` without sensitive information.
|
|
|
|
#
|
|
|
|
# Removing issues from summary in order to prevent leaking confidential ones.
|
|
|
|
# See more https://gitlab.com/gitlab-org/gitlab/issues/121930
|
|
|
|
def summary
|
|
|
|
safe_summary = read_attribute(:summary)
|
|
|
|
|
|
|
|
safe_summary.dig('release', 'milestones')&.each do |milestone|
|
|
|
|
milestone.delete('issues')
|
|
|
|
end
|
|
|
|
|
|
|
|
safe_summary
|
|
|
|
end
|
|
|
|
|
2019-10-17 11:06:17 -04:00
|
|
|
private
|
|
|
|
|
|
|
|
def generate_summary_and_sha
|
|
|
|
summary = Evidences::EvidenceSerializer.new.represent(self) # rubocop: disable CodeReuse/Serializer
|
|
|
|
return unless summary
|
|
|
|
|
|
|
|
self.summary = summary
|
|
|
|
self.summary_sha = Gitlab::CryptoHelper.sha256(summary)
|
|
|
|
end
|
|
|
|
end
|