summaryrefslogtreecommitdiff
path: root/qa/qa/specs/features/api/3_create/merge_request/push_options_labels_spec.rb
blob: 26ca6de29f7d4ed46c42c7b5a74b1cba7a0c0a3f (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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
# frozen_string_literal: true

module QA
  RSpec.describe 'Create' do
    describe 'Merge request push options' do
      # If run locally on GDK, push options need to be enabled on the host with the following command:
      #
      # git config --global receive.advertisepushoptions true

      let(:branch) { "push-options-test-#{SecureRandom.hex(8)}" }
      let(:title) { "MR push options test #{SecureRandom.hex(8)}" }
      let(:commit_message) { 'Add README.md' }

      let(:project) do
        Resource::Project.fabricate_via_api! do |project|
          project.name = 'merge-request-push-options'
          project.initialize_with_readme = true
        end
      end

      def create_new_mr_via_push
        Resource::Repository::ProjectPush.fabricate! do |push|
          push.project = project
          push.commit_message = commit_message
          push.branch_name = branch
          push.merge_request_push_options = {
            create: true,
            title: title,
            label: %w[one two three]
          }
        end
      end

      it 'sets labels', testcase: 'https://gitlab.com/gitlab-org/quality/testcases/-/quality/test_cases/1244' do
        create_new_mr_via_push

        merge_request = project.merge_request_with_title(title)

        expect(merge_request).not_to be_nil, "There was a problem creating the merge request"
        expect(merge_request[:labels]).to include('one').and include('two').and include('three')
      end

      context 'when labels are set already' do
        before do
          create_new_mr_via_push
        end

        it 'removes them on subsequent push', testcase: 'https://gitlab.com/gitlab-org/quality/testcases/-/quality/test_cases/1243' do
          Resource::Repository::ProjectPush.fabricate! do |push|
            push.project = project
            push.file_content = "Unlabel test #{SecureRandom.hex(8)}"
            push.commit_message = commit_message
            push.branch_name = branch
            push.new_branch = false
            push.merge_request_push_options = {
              title: title,
              unlabel: %w[one three]
            }
          end

          merge_request = project.merge_request_with_title(title)

          expect(merge_request).not_to be_nil, "There was a problem creating the merge request"

          aggregate_failures do
            expect(merge_request[:labels]).to include('two')
            expect(merge_request[:labels]).not_to include('one')
            expect(merge_request[:labels]).not_to include('three')
          end
        end
      end
    end
  end
end