summaryrefslogtreecommitdiff
path: root/app/models/evidence.rb
blob: 69a00f1cb3f636515cd8b5831c40e9edcbad1f9d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# frozen_string_literal: true

class Evidence < ApplicationRecord
  include ShaAttribute

  belongs_to :release

  before_validation :generate_summary_and_sha

  default_scope { order(created_at: :asc) }

  sha_attribute :summary_sha

  def milestones
    @milestones ||= release.milestones.includes(:issues)
  end

  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