Welcome to mirror list, hosted at ThFree Co, Russian Federation.

commit_signature.rb « entities « api « lib - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 505ce462edf68c7cb3d5523da2902ecd3c95b116 (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
# frozen_string_literal: true

module API
  module Entities
    class CommitSignature < Grape::Entity
      expose :signature_type

      expose :signature, merge: true do |commit, options|
        if commit.signature.is_a?(GpgSignature) || commit.raw_commit_from_rugged?
          ::API::Entities::GpgCommitSignature.represent commit_signature(commit), options
        elsif commit.signature.is_a?(X509CommitSignature)
          ::API::Entities::X509Signature.represent commit.signature, options
        end
      end

      expose :commit_source do |commit, _|
        commit.raw_commit_from_rugged? ? "rugged" : "gitaly"
      end

      private

      def commit_signature(commit)
        if commit.raw_commit_from_rugged?
          commit.gpg_commit.signature
        else
          commit.signature
        end
      end
    end
  end
end