summaryrefslogtreecommitdiff
path: root/lib/api/merge_request_diffs.rb
blob: 470f78a7dc2aca5f2cb36c4dee0526a36463d549 (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
52
# frozen_string_literal: true

module API
  # MergeRequestDiff API
  class MergeRequestDiffs < ::API::Base
    include PaginationParams

    before { authenticate! }

    feature_category :code_review

    params do
      requires :id, type: String, desc: 'The ID of a project'
    end
    resource :projects, requirements: API::NAMESPACE_OR_PROJECT_REQUIREMENTS do
      desc 'Get a list of merge request diff versions' do
        detail 'This feature was introduced in GitLab 8.12.'
        success Entities::MergeRequestDiff
      end

      params do
        requires :merge_request_iid, type: Integer, desc: 'The IID of a merge request'
        use :pagination
      end
      get ":id/merge_requests/:merge_request_iid/versions" do
        not_found!("Merge Request") unless can?(current_user, :read_merge_request, user_project)

        merge_request = find_merge_request_with_access(params[:merge_request_iid])

        present paginate(merge_request.merge_request_diffs.order_id_desc), with: Entities::MergeRequestDiff
      end

      desc 'Get a single merge request diff version' do
        detail 'This feature was introduced in GitLab 8.12.'
        success Entities::MergeRequestDiffFull
      end

      params do
        requires :merge_request_iid, type: Integer, desc: 'The IID of a merge request'
        requires :version_id, type: Integer, desc: 'The ID of a merge request diff version'
      end

      get ":id/merge_requests/:merge_request_iid/versions/:version_id" do
        not_found!("Merge Request") unless can?(current_user, :read_merge_request, user_project)

        merge_request = find_merge_request_with_access(params[:merge_request_iid])

        present_cached merge_request.merge_request_diffs.find(params[:version_id]), with: Entities::MergeRequestDiffFull, cache_context: nil
      end
    end
  end
end