summaryrefslogtreecommitdiff
path: root/lib/gitlab/signed_commit.rb
blob: 809e0a3f0340f51237cfe6bdd57d4e02a60445b9 (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
28
29
30
31
32
33
34
# frozen_string_literal: true

module Gitlab
  class SignedCommit
    include Gitlab::Utils::StrongMemoize

    def initialize(commit)
      @commit = commit

      if commit.project
        repo = commit.project.repository.raw_repository
        @signature_data = Gitlab::Git::Commit.extract_signature_lazily(repo, commit.sha || commit.id)
      end

      lazy_signature
    end

    def signature
      return unless @commit.has_signature?
    end

    def signature_text
      strong_memoize(:signature_text) do
        @signature_data.itself ? @signature_data[0] : nil
      end
    end

    def signed_text
      strong_memoize(:signed_text) do
        @signature_data.itself ? @signature_data[1] : nil
      end
    end
  end
end