labclient 0.1.1 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (66) hide show
  1. checksums.yaml +4 -4
  2. data/lib/labclient.rb +23 -4
  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 +48 -7
  7. data/lib/labclient/docs.rb +9 -5
  8. data/lib/labclient/epics/epic.rb +13 -0
  9. data/lib/labclient/error.rb +1 -0
  10. data/lib/labclient/files/create.rb +14 -8
  11. data/lib/labclient/generator/generator.rb +70 -0
  12. data/lib/labclient/generator/names.rb +68 -0
  13. data/lib/labclient/generator/template_helper.rb +81 -0
  14. data/lib/labclient/generator/templates/environments.rb +98 -0
  15. data/lib/labclient/generator/templates/pages.rb +67 -0
  16. data/lib/labclient/generator/templates/pipeline_trigger.rb +82 -0
  17. data/lib/labclient/generator/wizard.rb +142 -0
  18. data/lib/labclient/groups/group.rb +9 -1
  19. data/lib/labclient/http.rb +3 -2
  20. data/lib/labclient/issues/create.rb +2 -0
  21. data/lib/labclient/issues/issue.rb +31 -1
  22. data/lib/labclient/issues/update.rb +20 -2
  23. data/lib/labclient/jobs/delete.rb +1 -1
  24. data/lib/labclient/jobs/keep.rb +1 -1
  25. data/lib/labclient/jobs/play.rb +1 -1
  26. data/lib/labclient/jobs/trace.rb +2 -2
  27. data/lib/labclient/klass.rb +34 -4
  28. data/lib/labclient/lab_struct.rb +17 -0
  29. data/lib/labclient/license/list.rb +2 -2
  30. data/lib/labclient/members/member.rb +1 -0
  31. data/lib/labclient/merge_requests/accept.rb +15 -6
  32. data/lib/labclient/merge_requests/create.rb +12 -0
  33. data/lib/labclient/merge_requests/merge_request.rb +49 -4
  34. data/lib/labclient/notes/epics/create.rb +12 -4
  35. data/lib/labclient/notes/epics/delete.rb +3 -3
  36. data/lib/labclient/notes/epics/list.rb +21 -4
  37. data/lib/labclient/notes/epics/show.rb +4 -4
  38. data/lib/labclient/notes/epics/update.rb +4 -4
  39. data/lib/labclient/notes/issues/create.rb +11 -1
  40. data/lib/labclient/notes/issues/list.rb +18 -3
  41. data/lib/labclient/notes/issues/show.rb +1 -1
  42. data/lib/labclient/notes/merge_requests/create.rb +8 -0
  43. data/lib/labclient/notes/merge_requests/list.rb +20 -2
  44. data/lib/labclient/notes/snippets/create.rb +1 -1
  45. data/lib/labclient/notes/snippets/list.rb +20 -3
  46. data/lib/labclient/notes/snippets/show.rb +1 -1
  47. data/lib/labclient/notifications/update.rb +1 -1
  48. data/lib/labclient/overview.rb +110 -11
  49. data/lib/labclient/paginated_response.rb +8 -1
  50. data/lib/labclient/pipelines/pipeline.rb +41 -0
  51. data/lib/labclient/projects/methods.rb +71 -2
  52. data/lib/labclient/projects/reference.rb +14 -0
  53. data/lib/labclient/projects/snippets/project_snippet.rb +12 -0
  54. data/lib/labclient/protected_branches/protect.rb +6 -5
  55. data/lib/labclient/protected_environments/list.rb +29 -0
  56. data/lib/labclient/protected_environments/protect.rb +53 -0
  57. data/lib/labclient/protected_environments/protected_environment.rb +22 -0
  58. data/lib/labclient/protected_environments/show.rb +24 -0
  59. data/lib/labclient/protected_environments/unprotect.rb +31 -0
  60. data/lib/labclient/snippets/snippet.rb +2 -2
  61. data/lib/labclient/users/membership.rb +62 -0
  62. data/lib/labclient/users/memberships.rb +8 -3
  63. data/lib/labclient/users/user.rb +13 -1
  64. data/lib/labclient/version.rb +1 -1
  65. metadata +37 -9
  66. data/lib/labclient/open_struct.rb +0 -14
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 0cfc44546096a710f5e2a8ed0b500b202825150b03a029738d8b870cf4258e94
4
- data.tar.gz: c965712946b26eef38ae7546a483688eae0ae20cc82480dad59262aa050ba18c
3
+ metadata.gz: 8a76c9e9a1408f2c357f82a955359b36b16341f2c83cdd4d3224a90fea884acf
4
+ data.tar.gz: 8348d2cf615d5b3911ce71f77f71830ba5020015a02d43e4bac6c572105131be
5
5
  SHA512:
6
- metadata.gz: 77a79ac90bfa375a488633c9aa530581a8235c3b5c0d00fd24644ccb962fd39152facc298e77a016cffb200f65b301e6d2c7a1ed883f2dfd2ea0dc6d96ea185d
7
- data.tar.gz: cc4cb427458a49007775e063fc065df0623c76f4abe05f0b93279e3ca1638b9b0c024074cb8ac57e7ab732543c39da7cb9f436f2ca85263995c72bbf083d1df9
6
+ metadata.gz: 1072af5523d2a6773e329d6674a35f3122eadc488b0961b90b38e9c7b79b5f6cfe516909b16a54f3ad39e227c0a920462cc2b0353b9bd95dbd1e4ce216c8b15b
7
+ data.tar.gz: e4917da6a4d9d202604fc11b54d6d36f0ec675b2faef38ebbcf9529d9cfb56d883d64508b538dcf3cfb7d8c0c82434ad33fc5a7d3570a2bc7ecc961e64946191
@@ -1,9 +1,8 @@
1
1
  # Public Gems
2
2
  require 'oj'
3
- require 'pry'
4
3
  require 'typhoeus'
5
4
  require 'active_support/all'
6
- require 'awesome_print'
5
+ require 'amazing_print'
7
6
  require 'gitlab_chronic_duration'
8
7
  require 'ostruct'
9
8
 
@@ -13,8 +12,8 @@ require 'labclient/http'
13
12
  require 'labclient/access_levels'
14
13
  require 'labclient/common'
15
14
  require 'labclient/curl'
15
+ require 'labclient/lab_struct'
16
16
  require 'labclient/klass'
17
- require 'labclient/open_struct'
18
17
  require 'labclient/class_helpers'
19
18
  require 'labclient/paginated_response'
20
19
  require 'labclient/error'
@@ -36,7 +35,6 @@ require 'labclient/users/current'
36
35
  require 'labclient/users/status'
37
36
  require 'labclient/users/counts'
38
37
  require 'labclient/users/activity'
39
- require 'labclient/users/memberships'
40
38
  require 'labclient/users/search'
41
39
  require 'labclient/users/create'
42
40
  require 'labclient/users/update'
@@ -47,6 +45,8 @@ require 'labclient/users/activate'
47
45
  require 'labclient/users/deactivate'
48
46
  require 'labclient/users/delete'
49
47
  require 'labclient/users/delete_identity'
48
+ require 'labclient/users/memberships'
49
+ require 'labclient/users/membership'
50
50
  require 'labclient/users/user'
51
51
 
52
52
  # ===============================================
@@ -149,6 +149,13 @@ require 'labclient/projects/environments/delete'
149
149
  require 'labclient/projects/environments/stop'
150
150
  require 'labclient/projects/environments/project_environment'
151
151
 
152
+ # Protected Environments
153
+ require 'labclient/protected_environments/list'
154
+ require 'labclient/protected_environments/show'
155
+ require 'labclient/protected_environments/protect'
156
+ require 'labclient/protected_environments/unprotect'
157
+ require 'labclient/protected_environments/protected_environment'
158
+
152
159
  # Project Deployments
153
160
  require 'labclient/projects/deployments/client'
154
161
  require 'labclient/projects/deployments/list'
@@ -768,6 +775,7 @@ require 'labclient/files/delete'
768
775
  # Branches
769
776
  require 'labclient/branches/list'
770
777
  require 'labclient/branches/show'
778
+ require 'labclient/branches/create'
771
779
  require 'labclient/branches/delete'
772
780
  require 'labclient/branches/delete_merged'
773
781
  require 'labclient/branches/branch'
@@ -842,5 +850,16 @@ require 'labclient/resource_labels/merge_requests/show'
842
850
 
843
851
  require 'labclient/resource_labels/resource_label'
844
852
 
853
+ # Generators
854
+ require 'labclient/generator/names'
855
+ require 'labclient/generator/template_helper' # Default Include Template
856
+
857
+ # Wizard
858
+ require 'labclient/generator/generator'
859
+ require 'labclient/generator/wizard'
860
+
861
+ # Dynamically Require Templates (Simplify new template creation)
862
+ Dir["#{File.dirname(__FILE__)}/labclient/generator/templates/*.rb"].sort.each { |file| require file }
863
+
845
864
  # I am Very Last
846
865
  require 'labclient/client'
@@ -2,46 +2,40 @@
2
2
  module LabClient
3
3
  # Shared Methods
4
4
  module AccessLevel
5
+ HUMAN_ACCESS_LEVELS = {
6
+ 0 => :none,
7
+ 10 => :guest,
8
+ 20 => :reporter,
9
+ 30 => :developer,
10
+ 40 => :maintainer,
11
+ 50 => :owner,
12
+ 60 => :admin
13
+ }.freeze
14
+
15
+ MACHINE_ACCESS_LEVELS = {
16
+ none: 0,
17
+ guest: 10,
18
+ reporter: 20,
19
+ developer: 30,
20
+ maintainer: 40,
21
+ owner: 50,
22
+ admin: 60
23
+ }.freeze
24
+
5
25
  def human_access_level(level = 10)
6
- case level
7
- when 0 then :none
8
- when 10 then :guest
9
- when 20 then :reporter
10
- when 30 then :developer
11
- when 40 then :maintainer
12
- when 50 then :owner
13
- when 60 then :admin
14
- end
26
+ HUMAN_ACCESS_LEVELS[level]
15
27
  end
16
28
 
17
29
  def machine_access_level(level = :developer)
18
- case level
19
- when :none then 0
20
- when :guest then 10
21
- when :reporter then 20
22
- when :developer then 30
23
- when :maintainer then 40
24
- when :owner then 50
25
- when :admin then 60
26
- end
30
+ MACHINE_ACCESS_LEVELS[level]
27
31
  end
28
32
 
29
33
  def machine_protected_access_level(level = :developer)
30
- case level
31
- when :none then 0
32
- when :developer then 30
33
- when :maintainer then 40
34
- when :admin then 60
35
- end
34
+ MACHINE_ACCESS_LEVELS[level]
36
35
  end
37
36
 
38
37
  def human_protected_access_level(level = 10)
39
- case level
40
- when 0 then :none
41
- when 30 then :developer
42
- when 40 then :maintainer
43
- when 60 then :admin
44
- end
38
+ HUMAN_ACCESS_LEVELS[level]
45
39
  end
46
40
  end
47
41
  end
@@ -11,5 +11,30 @@ module LabClient
11
11
  def commit
12
12
  Commit.new(@table[:commit], response, client)
13
13
  end
14
+
15
+ def pipelines
16
+ project_id = collect_project_id
17
+ client.pipelines.list(project_id, ref: name)
18
+ end
19
+
20
+ # Wait for Import / Set a Hard Limit
21
+ def wait_for_pipelines(total_time = 300, sleep_time = 15)
22
+ Timeout.timeout(total_time) do
23
+ loop do
24
+ reload
25
+ puts 'Waiting for Pipelines'
26
+ break unless pipelines.empty?
27
+
28
+ sleep sleep_time
29
+ end
30
+ end
31
+ end
32
+
33
+ help do
34
+ subtitle 'Branch'
35
+ option 'commit', 'Show Commit information for branch'
36
+ option 'pipelines', 'Show Pipelines for this Branch/Ref'
37
+ option 'wait_for_pipelines', 'Looping, on newly created branches, wait for pipelines to populate (not finish) [Timeout, Interval]'
38
+ end
14
39
  end
15
40
  end
@@ -0,0 +1,33 @@
1
+ # Top namespace
2
+ module LabClient
3
+ # Specifics
4
+ class Branches < Common
5
+ doc 'Create' do
6
+ desc 'Get a list of repository branches from a project, sorted by name alphabetically. [Project ID, String]'
7
+ example 'client.branches.create(264, branch: :branch, ref: :master)'
8
+ result '[#<Branch name: feature>, #<Branch name: master>]'
9
+
10
+ markdown <<~DOC
11
+ | Attribute | Type | Required | Description |
12
+ |----------|--------|---------|-------------------------------------------------------------------------------------------------------------|
13
+ | id | integer | yes | ID or [URL-encoded path of the project](README.md#namespaced-path-encoding) owned by the authenticated user. |
14
+ | branch | string | yes | Name of the branch. |
15
+ | ref | string | yes | Branch name or commit SHA to create branch from. |
16
+ DOC
17
+ end
18
+
19
+ doc 'Create' do
20
+ desc 'via Project'
21
+ example <<~DOC
22
+ project = client.projects.show(264)
23
+ project.branch_create(branch: :branch, ref: :master)
24
+ DOC
25
+ end
26
+
27
+ def create(project_id, query)
28
+ project_id = format_id(project_id)
29
+
30
+ client.request(:post, "projects/#{project_id}/repository/branches", Branch, query)
31
+ end
32
+ end
33
+ end
@@ -1,6 +1,7 @@
1
1
  # Top Namespace
2
2
  module LabClient
3
3
  # API Specifics
4
+ # rubocop:disable Metrics/ClassLength
4
5
  class Client
5
6
  # include HTTParty
6
7
  attr_accessor :settings, :resp, :klass, :link, :http
@@ -37,6 +38,7 @@ module LabClient
37
38
  epics: Epics,
38
39
  events: Events,
39
40
  files: Files,
41
+ wizard: Generator::Wizard,
40
42
  groups: Groups,
41
43
  impersonation_tokens: ImpersonationTokens,
42
44
  issues: Issues,
@@ -54,6 +56,7 @@ module LabClient
54
56
  project_runners: ProjectRunners,
55
57
  projects: Projects,
56
58
  protected_branches: ProtectedBranches,
59
+ protected_environments: ProtectedEnvironments,
57
60
  protected_tags: ProtectedTags,
58
61
  registry: Registry,
59
62
  repo: Repositories,
@@ -90,27 +93,64 @@ module LabClient
90
93
  end
91
94
 
92
95
  # Default setup, pull in settings
93
- def initialize(settings = nil)
94
- @settings = settings
96
+ def initialize(user_settings = nil)
97
+ @settings = user_settings
98
+ setup_profile if user_settings&.key?(:profile) || ENV['LABCLIENT_PROFILE']
95
99
  @settings ||= fill_configuration
96
100
 
97
101
  # Set Unspecified Defaults
98
102
  unspecified_defaults
99
103
 
100
- raise 'LabClient Error - Missing URL!' if @settings[:url].nil?
104
+ prompt_for_url if @settings[:url].blank?
105
+
106
+ # Only prompt if explicitly set to nil
107
+ prompt_for_token if @settings[:token].nil?
101
108
 
102
109
  self.http = HTTP.new(@settings)
103
110
  end
104
111
 
112
+ def prompt_for_url
113
+ print 'Enter GitLab URL (e.g. https://gitlab.com): '
114
+ @settings[:url] = $stdin.gets.chomp
115
+ raise 'LabClient Error - Missing URL!' if @settings[:url].blank?
116
+ end
117
+
118
+ def prompt_for_token
119
+ print 'Enter Personal Access Token: '
120
+ @settings[:token] = $stdin.gets.chomp
121
+ end
122
+
105
123
  def unspecified_defaults
106
124
  @settings[:paginate] = true if @settings[:paginate].nil?
107
125
  @settings[:ssl_verify] = true if @settings[:ssl_verify].nil?
126
+ @settings[:quiet] = false if @settings[:quiet].nil?
108
127
  end
109
128
 
110
129
  def home_file
111
- ENV['HOME'] + '/.gitlab-labclient'
130
+ "#{ENV['HOME']}/.gitlab-labclient"
131
+ end
132
+
133
+ # Easier Profile Name Access
134
+ def profile
135
+ if settings&.key? :profile
136
+ settings[:profile].to_sym
137
+ else
138
+ ENV['LABCLIENT_PROFILE'].to_sym
139
+ end
140
+ end
141
+
142
+ # Support for Named Profiles
143
+ def setup_profile
144
+ return false unless File.exist? home_file
145
+
146
+ config = Oj.load_file(home_file, { symbol_keys: true })
147
+ return false unless config.key? profile
148
+
149
+ self.settings ||= {}
150
+ settings.merge! config[profile]
112
151
  end
113
152
 
153
+ # Load default profile
114
154
  def fill_configuration
115
155
  if File.exist? home_file
116
156
  Oj.load_file(home_file, { symbol_keys: true })
@@ -134,14 +174,14 @@ module LabClient
134
174
 
135
175
  process resp
136
176
  rescue LabClient::Error => e
137
- puts e.message
177
+ puts e.message unless settings[:quiet]
138
178
  resp
139
179
  end
140
180
 
141
- # Assume we want OpenStruct if @klass is ever nil
181
+ # Assume we want LabStruct if @klass is ever nil
142
182
  def process(resp)
143
183
  case resp.data
144
- when OpenStruct
184
+ when LabStruct
145
185
  klass ? klass.new(resp.data, resp, self) : resp.data
146
186
  when Array
147
187
  if @klass.nil?
@@ -154,4 +194,5 @@ module LabClient
154
194
  end
155
195
  end
156
196
  end
197
+ # rubocop:enable Metrics/ClassLength
157
198
  end
@@ -26,11 +26,11 @@ module LabClient
26
26
  # ---------------------------------
27
27
 
28
28
  # Klass Helper
29
- def help
29
+ def help(&block)
30
30
  # require 'active_support/inflector'
31
31
  @group_name ||= group_name.pluralize
32
32
  doc 'Reference' do
33
- yield
33
+ block.call
34
34
  end
35
35
  end
36
36
 
@@ -50,10 +50,14 @@ module LabClient
50
50
  end
51
51
 
52
52
  def desc(value)
53
- # @result[:desc] = simple_format value
54
53
  @result[:desc] = value
55
54
  end
56
55
 
56
+ def demo(value)
57
+ @result[:demo_url] = "https://asciinema.org/a/#{value}.js"
58
+ @result[:demo] = "<script id='asciicast-#{value}' src='#{@result[:demo_url]}' data-autoplay='true' data-loop='true' async></script>"
59
+ end
60
+
57
61
  def example(value)
58
62
  @result[:example] = value
59
63
  end
@@ -81,10 +85,10 @@ module LabClient
81
85
  subnav = subgroup.gsub(' ', '_')
82
86
 
83
87
  # Title
84
- subnav += '_' + @result[:title].gsub(' ', '_') if @result.key? :title
88
+ subnav += "_#{@result[:title].gsub(' ', '_')}" if @result.key? :title
85
89
 
86
90
  @result[:nav] = nav
87
- @result[:nav] += '-' + subnav if subnav
91
+ @result[:nav] += "-#{subnav}" if subnav
88
92
  end
89
93
 
90
94
  def doc(subgroup)
@@ -51,6 +51,15 @@ module LabClient
51
51
  client.resource_labels.epics.show(group_id, id, resource_event_id)
52
52
  end
53
53
 
54
+ # Notes
55
+ def notes
56
+ client.notes.epics.list(group_id, iid)
57
+ end
58
+
59
+ def note_create(query)
60
+ client.notes.epics.create(group_id, iid, query)
61
+ end
62
+
54
63
  date_time_attrs %i[created_at closed_at updated_at]
55
64
 
56
65
  help do
@@ -64,6 +73,10 @@ module LabClient
64
73
  option 'issue_remove', 'Remove issue from Epic [Epic Issue ID]'
65
74
  option 'issue_update', 'Update issue association [Epic Issue ID, Hash]'
66
75
 
76
+ # Notes
77
+ option 'notes', 'List notes/comments. [Hash]'
78
+ option 'note_create', 'Creates a new note. [Hash]'
79
+
67
80
  # Resource Labels
68
81
  option 'resource_labels', 'List of all label events'
69
82
  option 'resource_label', 'Show single label event [Resource Event ID]'
@@ -3,6 +3,7 @@ module LabClient
3
3
  # Class Shim
4
4
  class Error < StandardError
5
5
  attr_reader :resp
6
+
6
7
  def initialize(resp)
7
8
  super
8
9
  @resp = resp
@@ -16,15 +16,18 @@ module LabClient
16
16
  result '{:file_path=>"new.md", :branch=>"master"}'
17
17
 
18
18
  markdown <<~DOC
19
- **Parameters**:
19
+ Parameters
20
+
21
+ | **Attribute** | **Required** | **Description** |
22
+ | -------------- | ------------ | ----------------------------------------------- |
23
+ | branch | yes | Name of the branch |
24
+ | content | yes | File content |
25
+ | start_branch | no | Name of the branch to start the new commit from |
26
+ | encoding | no | Change encoding to ‘base64’. Default is text. |
27
+ | author_email | no | Specify the commit author’s email address |
28
+ | author_name | no | Specify the commit author’s name |
29
+ | commit_message | no | Commit message |
20
30
 
21
- * branch (required) - Name of the branch
22
- * start_branch (optional) - Name of the branch to start the new commit from
23
- * encoding (optional) - Change encoding to ‘base64’. Default is text.
24
- * author_email (optional) - Specify the commit author’s email address
25
- * author_name (optional) - Specify the commit author’s name
26
- * content (required) - File content
27
- * commit_message (required) - Commit message
28
31
 
29
32
  DOC
30
33
  end
@@ -43,6 +46,9 @@ module LabClient
43
46
  def create(project_id, file_path, query)
44
47
  project_id = format_id(project_id)
45
48
 
49
+ # Path Name Encoding
50
+ file_path = CGI.escape(file_path)
51
+
46
52
  client.request(:post, "projects/#{project_id}/repository/files/#{file_path}", nil, query)
47
53
  end
48
54
  end