blob: 9c65e0e5a31c9986ff6e31940cf6c15d02e1e086 (
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
|
# frozen_string_literal: true
require 'securerandom'
module QA
module Resource
class ProtectedBranch < Base
attr_accessor :branch_name, :allowed_to_push, :allowed_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-#{SecureRandom.hex(8)}.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'
@allowed_to_push = {
roles: Resource::ProtectedBranch::Roles::DEVS_AND_MAINTAINERS
}
@allowed_to_merge = {
roles: Resource::ProtectedBranch::Roles::DEVS_AND_MAINTAINERS
}
@protected = false
end
def fabricate!
populate(:branch)
project.wait_for_push_new_branch @branch_name
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)
page.select_allowed_to_merge(allowed_to_merge)
page.select_allowed_to_push(allowed_to_push)
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
class Roles
NO_ONE = 'No one'
DEVS_AND_MAINTAINERS = 'Developers + Maintainers'
MAINTAINERS = 'Maintainers'
end
end
end
end
|