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

protected_branch.rb « resource « qa « qa - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: c27647cf3ce2a02352948a246d0deb115bdffb62 (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
75
76
77
78
79
80
81
82
83
84
# frozen_string_literal: true

module QA
  module Resource
    class ProtectedBranch < Base
      attr_accessor :branch_name, :allow_to_push, :allow_to_merge, :protected

      attribute :project do
        Project.fabricate_via_api! do |resource|
          resource.name = 'protected-branch-project'
          resource.initialize_with_readme = true
        end
      end

      attribute :branch do
        Repository::ProjectPush.fabricate! do |project_push|
          project_push.project = project
          project_push.file_name = 'new_file.md'
          project_push.commit_message = 'Add new file'
          project_push.branch_name = branch_name
          project_push.new_branch = true
          project_push.remote_branch = @branch_name
        end
      end

      def initialize
        @branch_name = 'test/branch'
        @allow_to_push = true
        @allow_to_merge = true
        @protected = false
      end

      def fabricate!
        populate(:branch)

        project.wait_for_push_new_branch @branch_name

        # The upcoming process will make it access the Protected Branches page,
        # select the already created branch and protect it according
        # to `allow_to_push` variable.
        return branch unless @protected

        project.visit!
        Page::Project::Menu.perform(&:go_to_repository_settings)

        Page::Project::Settings::Repository.perform do |setting|
          setting.expand_protected_branches do |page|
            page.select_branch(branch_name)

            if allow_to_push
              page.allow_devs_and_maintainers_to_push
            else
              page.allow_no_one_to_push
            end

            if allow_to_merge
              page.allow_devs_and_maintainers_to_merge
            else
              page.allow_no_one_to_merge
            end

            page.wait(reload: false) do
              !page.first('.btn-success').disabled?
            end

            page.protect_branch
          end
        end
      end

      def self.unprotect_via_api!(&block)
        self.remove_via_api!(&block)
      end

      def api_get_path
        "/projects/#{@project.api_resource[:id]}/protected_branches/#{@branch_name}"
      end

      def api_delete_path
        "/projects/#{@project.api_resource[:id]}/protected_branches/#{@branch_name}"
      end
    end
  end
end