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

file_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: 50d31965f931007e758cfa8a592a19138798652d (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
# frozen_string_literal: true

module Atlassian
  module JiraConnect
    module Serializers
      class FileEntity < Grape::Entity
        include Gitlab::Routing

        expose :path do |file|
          file.deleted_file? ? file.old_path : file.new_path
        end
        expose :changeType do |file|
          if file.new_file?
            'ADDED'
          elsif file.deleted_file?
            'DELETED'
          elsif file.renamed_file?
            'MOVED'
          else
            'MODIFIED'
          end
        end
        expose :added_lines, as: :linesAdded
        expose :removed_lines, as: :linesRemoved

        expose :url do |file, options|
          file_path = if file.deleted_file?
                        File.join(options[:commit].parent_id, file.old_path)
                      else
                        File.join(options[:commit].id, file.new_path)
                      end

          project_blob_url(options[:project], file_path)
        end
      end
    end
  end
end