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

commit_entity.rb « serializers « jira_connect « atlassian « lib - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 8aa469846430167e4f59819d7117b06db6caffaf (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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# frozen_string_literal: true

module Atlassian
  module JiraConnect
    module Serializers
      class CommitEntity < BaseEntity
        CommitAuthor = Struct.new(:name, :email)

        expose :id
        expose :issueKeys do |commit|
          JiraIssueKeyExtractor.new(commit.safe_message).issue_keys
        end
        expose :id, as: :hash
        expose :short_id, as: :displayId
        expose :safe_message, as: :message
        expose :flags do |commit|
          if commit.merge_commit?
            ['MERGE_COMMIT']
          else
            []
          end
        end
        expose :author, using: JiraConnect::Serializers::AuthorEntity
        expose :fileCount do |commit|
          # n+1: https://gitlab.com/gitlab-org/gitaly/-/issues/3375
          Gitlab::GitalyClient.allow_n_plus_1_calls do
            commit.stats.total
          end
        end
        expose :files do |commit, options|
          # n+1: https://gitlab.com/gitlab-org/gitaly/-/issues/3374
          files = Gitlab::GitalyClient.allow_n_plus_1_calls do
            commit.diffs(max_files: 10).diff_files
          end
          JiraConnect::Serializers::FileEntity.represent files, options.merge(commit: commit)
        end
        expose :created_at, as: :authorTimestamp

        expose :url do |commit, options|
          project_commit_url(options[:project], commit.id)
        end

        private

        def author
          object.author || CommitAuthor.new(object.author_name, object.author_email)
        end
      end
    end
  end
end