labclient 0.1.2 → 0.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (70) hide show
  1. checksums.yaml +4 -4
  2. data/lib/labclient.rb +16 -6
  3. data/lib/labclient/access_levels.rb +24 -30
  4. data/lib/labclient/branches/branch.rb +25 -0
  5. data/lib/labclient/branches/create.rb +33 -0
  6. data/lib/labclient/client.rb +47 -7
  7. data/lib/labclient/commits/project_helpers.rb +4 -0
  8. data/lib/labclient/commits/show.rb +11 -2
  9. data/lib/labclient/docs.rb +9 -5
  10. data/lib/labclient/epics/epic.rb +13 -0
  11. data/lib/labclient/error.rb +1 -0
  12. data/lib/labclient/files/create.rb +14 -8
  13. data/lib/labclient/files/update.rb +1 -1
  14. data/lib/labclient/generator/generator.rb +9 -21
  15. data/lib/labclient/generator/names.rb +17 -3
  16. data/lib/labclient/generator/template_helper.rb +81 -0
  17. data/lib/labclient/generator/templates/environments.rb +98 -0
  18. data/lib/labclient/generator/templates/pages.rb +24 -30
  19. data/lib/labclient/generator/templates/pipeline_trigger.rb +82 -0
  20. data/lib/labclient/generator/wizard.rb +29 -9
  21. data/lib/labclient/groups/group.rb +1 -1
  22. data/lib/labclient/http.rb +3 -2
  23. data/lib/labclient/issues/issue.rb +23 -1
  24. data/lib/labclient/issues/update.rb +20 -2
  25. data/lib/labclient/jobs/delete.rb +1 -1
  26. data/lib/labclient/jobs/keep.rb +1 -1
  27. data/lib/labclient/jobs/play.rb +1 -1
  28. data/lib/labclient/jobs/trace.rb +2 -2
  29. data/lib/labclient/klass.rb +6 -3
  30. data/lib/labclient/lab_struct.rb +21 -0
  31. data/lib/labclient/license/list.rb +2 -2
  32. data/lib/labclient/members/member.rb +1 -0
  33. data/lib/labclient/merge_requests/accept.rb +15 -6
  34. data/lib/labclient/merge_requests/create.rb +12 -0
  35. data/lib/labclient/merge_requests/merge_request.rb +49 -4
  36. data/lib/labclient/notes/epics/create.rb +12 -4
  37. data/lib/labclient/notes/epics/delete.rb +3 -3
  38. data/lib/labclient/notes/epics/list.rb +21 -4
  39. data/lib/labclient/notes/epics/show.rb +4 -4
  40. data/lib/labclient/notes/epics/update.rb +4 -4
  41. data/lib/labclient/notes/issues/create.rb +11 -1
  42. data/lib/labclient/notes/issues/list.rb +18 -3
  43. data/lib/labclient/notes/issues/show.rb +1 -1
  44. data/lib/labclient/notes/merge_requests/create.rb +8 -0
  45. data/lib/labclient/notes/merge_requests/list.rb +20 -2
  46. data/lib/labclient/notes/snippets/create.rb +1 -1
  47. data/lib/labclient/notes/snippets/list.rb +20 -3
  48. data/lib/labclient/notes/snippets/show.rb +1 -1
  49. data/lib/labclient/notifications/update.rb +1 -1
  50. data/lib/labclient/overview.rb +79 -11
  51. data/lib/labclient/paginated_response.rb +3 -1
  52. data/lib/labclient/pipelines/pipeline.rb +41 -0
  53. data/lib/labclient/projects/environments/project_environment.rb +10 -0
  54. data/lib/labclient/projects/methods.rb +49 -2
  55. data/lib/labclient/projects/reference.rb +12 -0
  56. data/lib/labclient/projects/snippets/project_snippet.rb +12 -0
  57. data/lib/labclient/protected_branches/protect.rb +6 -5
  58. data/lib/labclient/protected_environments/list.rb +29 -0
  59. data/lib/labclient/protected_environments/protect.rb +53 -0
  60. data/lib/labclient/protected_environments/protected_environment.rb +22 -0
  61. data/lib/labclient/protected_environments/show.rb +24 -0
  62. data/lib/labclient/protected_environments/unprotect.rb +31 -0
  63. data/lib/labclient/snippets/snippet.rb +2 -2
  64. data/lib/labclient/users/membership.rb +62 -0
  65. data/lib/labclient/users/memberships.rb +8 -3
  66. data/lib/labclient/users/user.rb +7 -1
  67. data/lib/labclient/version.rb +1 -1
  68. metadata +16 -7
  69. data/lib/labclient/generator/templates/template.rb +0 -23
  70. data/lib/labclient/open_struct.rb +0 -14
@@ -33,7 +33,7 @@ module LabClient
33
33
  desc 'via Project'
34
34
  example <<~DOC
35
35
  project = client.projects.show(264)
36
- project.file_create('other.md',
36
+ project.file_update('other.md',
37
37
  branch: :master,
38
38
  commit_message: "New File!",
39
39
  content: "Content!")
@@ -43,40 +43,28 @@ module LabClient
43
43
 
44
44
  doc 'Wizard' do
45
45
  markdown <<~DOC
46
- | Setting | Type | Description |
47
- | -------- | ------- | ------------------------------------------------------ |
48
- | random | Boolean | Run Populate. Setup random Users, Projects, and Groups |
49
- | count | Hash | Settings for random. User, Project, Group count |
50
- | password | String | Default password for generated Users |
51
- | domain | String | Defaults to client url. Default email domain for users |
52
-
46
+ | Setting | Type | Description |
47
+ | ----------------- | ------- | ------------------------------------------------------ |
48
+ | random | Boolean | Run Populate. Setup random Users, Projects, and Groups |
49
+ | count | Hash | Settings for random. User, Project, Group count |
50
+ | password | String | Default password for generated Users |
51
+ | domain | String | Defaults to client url. Default email domain for users |
52
+ | skip_confirmation | Boolean | Enable/Disable skip_confirmation on new users |
53
53
  DOC
54
54
  end
55
55
 
56
56
  doc 'Wizard' do
57
- title 'Templates'
57
+ title 'Run one templates'
58
58
  desc <<-DOC
59
59
  Outside of the wizard at large, you can also select and manually run specific templates.
60
60
  DOC
61
61
 
62
62
  example <<~DOC
63
- pages = client.wizard.pages
63
+ pages = client.wizard.template(:pages)
64
64
  => #<LabClient::Template Pages>
65
65
  pages.run! # Run pages template
66
66
  DOC
67
67
  end
68
-
69
- doc 'Pages' do
70
- markdown <<~DOC
71
- Create GitLab Pages group and test projects. Projects imported from Gitlab's [demo pages projects](https://gitlab.com/pages)
72
-
73
- | Setting | Default | Type | Description |
74
- | ---------- | --------- | ------- | -------------------------------------- |
75
- | group_name | Generated | String | Parent Group name for pages projects |
76
- | group_path | Generated | String | Parent Group path |
77
- | count | 5 | Integer | Number of projects to import (max: 28) |
78
- DOC
79
- end
80
68
  end
81
69
  end
82
70
  end
@@ -4,20 +4,34 @@ module LabClient
4
4
  module Generator
5
5
  # Name Helper
6
6
  module Names
7
+ def create_file(content, branch = :master, message = nil)
8
+ {
9
+ branch: branch,
10
+ commit_message: message || gen_description,
11
+ content: content
12
+ }
13
+ end
14
+
7
15
  def gen_groups
8
16
  [
9
17
  Faker::Games::LeagueOfLegends.location,
10
18
  Faker::Movies::LordOfTheRings.location,
11
19
  Faker::TvShows::RickAndMorty.location,
12
20
  Faker::TvShows::StarTrek.location,
13
- Faker::Games::ElderScrolls.region
21
+ Faker::Games::ElderScrolls.region,
22
+ Faker::Games::ElderScrolls.city,
23
+ Faker::Games::Zelda.location,
24
+ Faker::Games::SuperSmashBros.stage
14
25
  ].map { |x| x.gsub(/[^0-9A-Za-z]/, '') }
15
26
  end
16
27
 
17
28
  def gen_projects
18
29
  [
19
30
  Faker::Games::ElderScrolls.creature,
31
+ Faker::Movies::LordOfTheRings.location,
20
32
  Faker::Games::LeagueOfLegends.summoner_spell,
33
+ Faker::Games::Pokemon.move,
34
+ Faker::TvShows::RickAndMorty.location,
21
35
  Faker::Games::LeagueOfLegends.masteries,
22
36
  Faker::Superhero.power
23
37
  ].map { |x| x.gsub(/[^0-9A-Za-z]/, '') }
@@ -45,8 +59,8 @@ module LabClient
45
59
  # rubocop:disable Metrics/AbcSize
46
60
  def generate_names
47
61
  @user_names = Array.new(count[:users]) { gen_people }.flatten.uniq.sample(count[:users])
48
- @group_names = Array.new(count[:groups]) { gen_groups }.flatten.uniq
49
- @project_names = Array.new(rand(count[:projects])) { gen_projects.sample }.uniq
62
+ @group_names = Array.new(count[:groups]) { gen_groups }.flatten.uniq.sample(count[:groups])
63
+ @project_names = Array.new(count[:projects]) { gen_projects }.flatten.uniq.sample(count[:projects])
50
64
  end
51
65
  # rubocop:enable Metrics/AbcSize
52
66
  end
@@ -0,0 +1,81 @@
1
+ module LabClient
2
+ module Generator
3
+ # Public Method Helpers
4
+ module TemplateMethods
5
+ extend ActiveSupport::Concern
6
+
7
+ @group_prefix = 'Environment'
8
+
9
+ class_methods do
10
+ def template_name
11
+ name.demodulize.underscore.to_sym
12
+ end
13
+ end
14
+ end
15
+
16
+ # Common Helper Class
17
+ class TemplateHelper
18
+ include TemplateMethods
19
+
20
+ attr_reader :client
21
+ attr_accessor :opts
22
+
23
+ def inspect
24
+ "#<LabClient::Template #{self.class.to_s.demodulize}>"
25
+ end
26
+
27
+ def initialize(client, opts = {})
28
+ @client = client
29
+ self.opts = opts
30
+ setup
31
+ end
32
+
33
+ def setup
34
+ # Blank Place Holder
35
+ end
36
+ end
37
+
38
+ # ====================================================
39
+ # Helper for Common Group/Project Templates
40
+ # - Create Group, @group
41
+ # - Execute any `setup_` methods
42
+ # - Print all @projects, and @group
43
+ class GroupTemplateHelper < TemplateHelper
44
+ @group_prefix = 'Environment'
45
+ include Names
46
+ attr_accessor :group_name, :group_path, :group_suffix, :project_name
47
+
48
+ def run!
49
+ puts "Running: #{group_suffix}"
50
+ generate_group
51
+
52
+ # Run `setup_` prefixed classes
53
+ self.class.instance_methods.grep(/setup_/).each { |x| send(x) }
54
+
55
+ # Print Created Groups/Project
56
+ puts "#{@group.name} - #{@group.web_url}"
57
+ @projects.each do |project|
58
+ puts " - #{project.name} - #{project.web_url}"
59
+ end
60
+
61
+ {
62
+ group: @group,
63
+ projects: @projects
64
+ }
65
+ end
66
+
67
+ def setup
68
+ self.group_suffix = self.class.name.demodulize
69
+ self.group_name = opts[:group_name] || "#{gen_groups.sample} #{group_suffix}"
70
+ self.group_path = opts[:group_path] || group_name.downcase.gsub(' ', '-')
71
+
72
+ @projects = []
73
+ end
74
+
75
+ def generate_group
76
+ @group = client.groups.create(name: group_name, path: group_path)
77
+ raise 'Unable to Create Group' unless @group.success?
78
+ end
79
+ end
80
+ end
81
+ end
@@ -0,0 +1,98 @@
1
+ module LabClient
2
+ module Generator
3
+ # Docs for the wizard
4
+ class GeneratorDocs
5
+ doc 'Templates' do
6
+ title 'Environments'
7
+ markdown <<~DOC
8
+ - On Stop: Create environment on new branch. Stop environment on merge
9
+
10
+ | Setting | Default | Type | Description |
11
+ | ---------- | --------- | ------- | -------------------------------------- |
12
+ | group_name | Generated | String | Parent Group name for pages projects |
13
+ | group_path | Generated | String | Parent Group path |
14
+ DOC
15
+ end
16
+ end
17
+
18
+ # Child and other Trigger Examples
19
+ # https://docs.gitlab.com/ee/ci/yaml/#trigger
20
+ class Environments < GroupTemplateHelper
21
+ def on_stop_yaml
22
+ <<~YAML
23
+ image: busybox:latest
24
+
25
+ build:
26
+ stage: build
27
+ script:
28
+ - echo "Build on both master and branches"
29
+
30
+ branch-review:
31
+ stage: deploy
32
+ environment:
33
+ name: ${CI_COMMIT_REF_NAME}
34
+ on_stop: review-teardown
35
+ script:
36
+ - echo "branch-review"
37
+ only:
38
+ - branches
39
+ except:
40
+ - master
41
+
42
+ review-teardown:
43
+ stage: deploy
44
+ when: manual
45
+ variables:
46
+ GIT_STRATEGY: none
47
+ environment:
48
+ name: ${CI_COMMIT_REF_NAME}
49
+ action: stop
50
+ script:
51
+ - echo "review-teardown"
52
+ only:
53
+ - branches
54
+ except:
55
+ - master
56
+ YAML
57
+ end
58
+
59
+ # rubocop:disable Metrics/MethodLength
60
+ def setup_master_branch_environment_on_stop
61
+ project = @group.project_create(
62
+ name: 'On Stop',
63
+ description: 'Environments created on non-master branches, stopped on merge',
64
+ auto_devops_enabled: false,
65
+ only_allow_merge_if_pipeline_succeeds: true
66
+ )
67
+
68
+ # Create Parent
69
+ project.file_create('README.md', create_file("# #{project.name}"))
70
+
71
+ # # Create Branch
72
+ project.branch_create(branch: :branch, ref: :master)
73
+
74
+ # Create Branch Files
75
+ project.file_create('.gitlab-ci.yml', create_file(on_stop_yaml, :branch))
76
+
77
+ # Create Merge Request
78
+ merge_request = project.merge_request_create(
79
+ title: 'Merge Test Branch!',
80
+ source_branch: :branch,
81
+ target_branch: :master
82
+ )
83
+
84
+ # Wait for Merge
85
+ merge_request.wait_for_merge_status
86
+
87
+ # Merge
88
+ merge_request.accept(
89
+ should_remove_source_branch: true,
90
+ merge_when_pipeline_succeeds: true
91
+ )
92
+
93
+ @projects.push project
94
+ end
95
+ # rubocop:enable Metrics/MethodLength
96
+ end
97
+ end
98
+ end
@@ -1,9 +1,24 @@
1
1
  module LabClient
2
2
  module Generator
3
+ # Docs for the wizard
4
+ class GeneratorDocs
5
+ doc 'Templates' do
6
+ title 'Pages'
7
+ markdown <<~DOC
8
+ Create GitLab Pages group and test projects. Projects imported from Gitlab's [demo pages projects](https://gitlab.com/pages)
9
+
10
+ | Setting | Default | Type | Description |
11
+ | ---------- | --------- | ------- | -------------------------------------- |
12
+ | group_name | Generated | String | Parent Group name for pages projects |
13
+ | group_path | Generated | String | Parent Group path |
14
+ | count | 5 | Integer | Number of projects to import (max: 28) |
15
+ DOC
16
+ end
17
+ end
18
+
3
19
  # Page Import Creation
4
- class Pages < TemplateHelper
5
- include Names
6
- attr_accessor :group_name, :group_path, :count
20
+ class Pages < GroupTemplateHelper
21
+ attr_accessor :count
7
22
 
8
23
  # All Available Pages Projects
9
24
  def list
@@ -17,23 +32,10 @@ module LabClient
17
32
  end
18
33
 
19
34
  def setup
20
- self.group_name = opts[:group_name] || "#{gen_groups.sample} Pages"
21
- self.group_path = opts[:group_path] || group_name.downcase.gsub(' ', '-')
35
+ super
22
36
  self.count = opts[:count] || 5
23
37
  end
24
38
 
25
- def generate_group
26
- @group = client.groups.create(name: group_name, path: group_path)
27
- puts "#{@group.name} - #{@group.web_url}"
28
- raise 'Unable to Create Group' unless @group.success?
29
- end
30
-
31
- def generate_projects
32
- @projects = list.sample(count).map do |name|
33
- generate_project(name)
34
- end
35
- end
36
-
37
39
  def generate_project(name)
38
40
  @group.project_create(
39
41
  name: name,
@@ -52,21 +54,13 @@ module LabClient
52
54
  @projects.each(&:wait_for_import)
53
55
  end
54
56
 
55
- # Execute Template
56
- def run!
57
- generate_group
58
- generate_projects
59
- wait_for_import
60
- generate_pipelines
61
-
62
- @projects.each do |project|
63
- puts "#{project.name} - #{project.web_url}"
57
+ def setup_projects
58
+ @projects = list.sample(count).map do |name|
59
+ generate_project(name)
64
60
  end
65
61
 
66
- {
67
- group: @group,
68
- projects: @projects
69
- }
62
+ wait_for_import
63
+ generate_pipelines
70
64
  end
71
65
  end
72
66
  end
@@ -0,0 +1,82 @@
1
+ module LabClient
2
+ module Generator
3
+ # Docs for the wizard
4
+ class GeneratorDocs
5
+ doc 'Templates' do
6
+ title 'Pipeline Triggers'
7
+ markdown <<~DOC
8
+ Create GitLab Pipeline Triggers group and test projects.
9
+
10
+ - Child Pipeline: Parent pipeline with artifact, that is then executed as a child pipeline
11
+
12
+ | Setting | Default | Type | Description |
13
+ | ---------- | --------- | ------- | -------------------------------------- |
14
+ | group_name | Generated | String | Parent Group name for pages projects |
15
+ | group_path | Generated | String | Parent Group path |
16
+ DOC
17
+ end
18
+ end
19
+
20
+ # Child and other Trigger Examples
21
+ # https://docs.gitlab.com/ee/ci/yaml/#trigger
22
+ class PipelineTrigger < GroupTemplateHelper
23
+ def setup_projects
24
+ create_child_pipeline
25
+ end
26
+
27
+ def trigger_child_pipeline_yaml
28
+ <<~YAML
29
+ image: busybox:latest
30
+
31
+ build_child:
32
+ stage: build
33
+ script:
34
+ - cp child_pipeline.yml artifact.yml
35
+ artifacts:
36
+ paths:
37
+ - artifact.yml
38
+
39
+ trigger_child:
40
+ stage: deploy
41
+ trigger:
42
+ include:
43
+ - artifact: artifact.yml
44
+ job: build_child
45
+
46
+ YAML
47
+ end
48
+
49
+ def child_pipeline_yaml
50
+ <<~YAML
51
+ image: busybox:latest
52
+
53
+ child:
54
+ script:
55
+ - echo "Do your build here"
56
+ YAML
57
+ end
58
+
59
+ def create_child_pipeline
60
+ project = @group.project_create(
61
+ name: 'Child Pipeline',
62
+ description: 'Child Pipeline',
63
+ auto_devops_enabled: false
64
+ )
65
+
66
+ # Create Child
67
+ project.file_create(
68
+ 'child_pipeline.yml',
69
+ create_file(child_pipeline_yaml)
70
+ )
71
+
72
+ # Create Parent
73
+ project.file_create(
74
+ '.gitlab-ci.yml',
75
+ create_file(trigger_child_pipeline_yaml)
76
+ )
77
+
78
+ @projects.push project
79
+ end
80
+ end
81
+ end
82
+ end