gitlab-customer-support-operations_gitlab 1.0.0

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 (35) hide show
  1. checksums.yaml +7 -0
  2. data/lib/support_ops_gitlab/gitlab/badges.rb +229 -0
  3. data/lib/support_ops_gitlab/gitlab/base.rb +552 -0
  4. data/lib/support_ops_gitlab/gitlab/client.rb +51 -0
  5. data/lib/support_ops_gitlab/gitlab/commits.rb +198 -0
  6. data/lib/support_ops_gitlab/gitlab/configuration.rb +86 -0
  7. data/lib/support_ops_gitlab/gitlab/epics.rb +325 -0
  8. data/lib/support_ops_gitlab/gitlab/events.rb +167 -0
  9. data/lib/support_ops_gitlab/gitlab/gpg_keys.rb +64 -0
  10. data/lib/support_ops_gitlab/gitlab/group_memberships.rb +33 -0
  11. data/lib/support_ops_gitlab/gitlab/groups.rb +431 -0
  12. data/lib/support_ops_gitlab/gitlab/invitations.rb +72 -0
  13. data/lib/support_ops_gitlab/gitlab/issues.rb +606 -0
  14. data/lib/support_ops_gitlab/gitlab/jobs.rb +61 -0
  15. data/lib/support_ops_gitlab/gitlab/markdown.rb +54 -0
  16. data/lib/support_ops_gitlab/gitlab/merge_requests.rb +411 -0
  17. data/lib/support_ops_gitlab/gitlab/milestones.rb +195 -0
  18. data/lib/support_ops_gitlab/gitlab/namespaces.rb +184 -0
  19. data/lib/support_ops_gitlab/gitlab/notes.rb +182 -0
  20. data/lib/support_ops_gitlab/gitlab/pipelines.rb +258 -0
  21. data/lib/support_ops_gitlab/gitlab/project_access_tokens.rb +245 -0
  22. data/lib/support_ops_gitlab/gitlab/project_memberships.rb +33 -0
  23. data/lib/support_ops_gitlab/gitlab/project_webhook_events.rb +33 -0
  24. data/lib/support_ops_gitlab/gitlab/project_webhooks.rb +218 -0
  25. data/lib/support_ops_gitlab/gitlab/projects.rb +741 -0
  26. data/lib/support_ops_gitlab/gitlab/repository_files.rb +102 -0
  27. data/lib/support_ops_gitlab/gitlab/repository_submodules.rb +78 -0
  28. data/lib/support_ops_gitlab/gitlab/ssh_keys.rb +67 -0
  29. data/lib/support_ops_gitlab/gitlab/user_emails.rb +147 -0
  30. data/lib/support_ops_gitlab/gitlab/user_memberships.rb +21 -0
  31. data/lib/support_ops_gitlab/gitlab/user_tokens.rb +344 -0
  32. data/lib/support_ops_gitlab/gitlab/users.rb +1059 -0
  33. data/lib/support_ops_gitlab/gitlab.rb +45 -0
  34. data/lib/support_ops_gitlab.rb +28 -0
  35. metadata +251 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 58b7dc8a1f70df08c86c005e99bf1c927ddda146d3b00ca25e31d56b87818144
4
+ data.tar.gz: ad3e1f77cc3593abb33bfcab7d84a97d398ca870d70b67a6279b819567336848
5
+ SHA512:
6
+ metadata.gz: 5ebfb432d9f3e5a397ed0de90353490a426ac70abed7525bb4440ded553041cd5be57315b4330fb864a4d403d4ab2a8237934b2a908b5bffe46edb8c6bf78201
7
+ data.tar.gz: 7fc196553f5906cbb3b9971cc1f396f915733c9b7eecd921de76b71641dc4fc748bb7d51718effd026c4ff749837f86241389b2b04c471de5cb24c9878b6f1e7
@@ -0,0 +1,229 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Defines the module SupportOps.
4
+ module SupportOps
5
+ # Defines the module GitLab
6
+ module GitLab
7
+ ##
8
+ # Defines the class Badges within the module {SupportOps::GitLab}.
9
+ #
10
+ # @author Jason Colyer
11
+ # @since 1.0.0
12
+ # @attr [Integer] group_id The ID of the group the badge is in
13
+ # @attr [Integer] id The ID of the badge
14
+ # @attr [String] image_url URL of the badge image
15
+ # @attr [String] kind The type of badge it is (project or group)
16
+ # @attr [String] link_url URL of the badge link
17
+ # @attr [String] name Name of the badge
18
+ # @attr [Integer] project_id The ID of the project the badge is in
19
+ # @attr [String] rendered_image_url The URL of the rendered badge image
20
+ # @attr [String] rendered_link_url The URL of the rendered badge link
21
+ # @todo Get a badge of a project > https://docs.gitlab.com/api/project_badges/#get-a-badge-of-a-project
22
+ # @todo Get a badge of a group > https://docs.gitlab.com/api/group_badges/#get-a-badge-of-a-group
23
+ # @todo Preview a badge from a project > https://docs.gitlab.com/api/project_badges/#preview-a-badge-from-a-project
24
+ # @todo Preview a badge from a group > https://docs.gitlab.com/api/group_badges/#preview-a-badge-from-a-group
25
+ class Badges < SupportOps::GitLab::Base
26
+ # @!parse
27
+ # # Creates/updates a badge
28
+ # #
29
+ # # @author Jason Colyer
30
+ # # @since 1.0.0
31
+ # # @return [Object] Instance of {SupportOps::GitLab::Badges}
32
+ # # @note This is inherited from {SupportOps::GitLab::Base#save!}
33
+ # # @see
34
+ # # https://docs.gitlab.com/api/project_badges/#add-a-badge-to-a-project
35
+ # # GitLab API > Projects > Badge > Add a badge to a project
36
+ # # @see
37
+ # # https://docs.gitlab.com/api/group_badges/#add-a-badge-to-a-group
38
+ # # GitLab API > Groups > Badge > Add a badge to a group
39
+ # # @see
40
+ # # https://docs.gitlab.com/api/project_badges/#edit-a-badge-to-a-project
41
+ # # GitLab API > Projects > Badge > Edit a badge to a project
42
+ # # @see
43
+ # # https://docs.gitlab.com/api/group_badges/#edit-a-badge-to-a-group
44
+ # # GitLab API > Groups > Badge > Edit a badge to a group
45
+ # # @example
46
+ # # require 'support_ops_gitlab'
47
+ # #
48
+ # # SupportOps::GitLab::Configuration.configure do |config|
49
+ # # config.token = ENV.fetch('GL_TOKEN')
50
+ # # config.url = 'https://gitlab.com/api/v4'
51
+ # # end
52
+ # #
53
+ # # new_badge = SupportOps::GitLab::Badges.new
54
+ # # new_badge.name = 'Awesome Badge'
55
+ # # new_badge.link_url = 'https://google.com'
56
+ # # new_badge.image_url = 'https://img.shields.io/badge/Awesome-Badge-purple'
57
+ # # new_badge.group_id = 1
58
+ # #
59
+ # # new_badge.save!
60
+ # #
61
+ # # pp new_badge.id
62
+ # # # => 33
63
+ # # @example
64
+ # # require 'support_ops_gitlab'
65
+ # #
66
+ # # SupportOps::GitLab::Configuration.configure do |config|
67
+ # # config.token = ENV.fetch('GL_TOKEN')
68
+ # # config.url = 'https://gitlab.com/api/v4'
69
+ # # end
70
+ # #
71
+ # # badges = SupportOps::GitLab::Badges.list(project_id: 123)
72
+ # # badge = badges.last
73
+ # # badge.link_url = 'https://duckduckgo.com/'
74
+ # #
75
+ # # badge.save!
76
+ # #
77
+ # # pp badge.rendered_link_url
78
+ # # # => "https://duckduckgo.com/"
79
+ # def save!; end
80
+ # @!parse
81
+ # # Deletes a badge
82
+ # #
83
+ # # @author Jason Colyer
84
+ # # @since 1.0.0
85
+ # # @return [Boolean]
86
+ # # @note This is inherited from {SupportOps::GitLab::Base#delete!}
87
+ # # @see
88
+ # # https://docs.gitlab.com/api/project_badges/#remove-a-badge-from-a-project
89
+ # # GitLab API > Projects > Badges > Remove a badge from a project
90
+ # # @see
91
+ # # https://docs.gitlab.com/api/group_badges/#remove-a-badge-from-a-group
92
+ # # GitLab API > Groups > Badges > Remove a badge from a group
93
+ # # @example
94
+ # # require 'support_ops_gitlab'
95
+ # #
96
+ # # SupportOps::GitLab::Configuration.configure do |config|
97
+ # # config.token = ENV.fetch('GL_TOKEN')
98
+ # # config.url = 'https://gitlab.com/api/v4'
99
+ # # end
100
+ # #
101
+ # # badges = SupportOps::GitLab::Badges.list(project_id: 123)
102
+ # # badge = badges.last
103
+ # # badge.delete!
104
+ # def delete!; end
105
+ define_attributes :group_id, :id, :image_url, :kind, :link_url, :name,
106
+ :project_id, :rendered_image_url, :rendered_link_url
107
+ readonly_attributes :id, :group_id, :project_id, :rendered_image_url,
108
+ :rendered_link_url
109
+
110
+ ##
111
+ # List all badges
112
+ #
113
+ # @author Jason Colyer
114
+ # @since 1.0.0
115
+ # overload list(key: value)
116
+ # @param group_id [Integer semi-optional] The ID of the group to get
117
+ # badges from
118
+ # @param name [String optional] Name of the badges to return
119
+ # (case-sensitive)
120
+ # @param project_id [Integer semi-optional] The ID of the project to get
121
+ # badges from
122
+ # @return [Array]
123
+ # #see
124
+ # https://docs.gitlab.com/api/group_badges/#list-all-badges-of-a-group
125
+ # GitLab API > Groups > Badges > List all badges of a group
126
+ # #see
127
+ # https://docs.gitlab.com/api/project_badges/#list-all-badges-of-a-project
128
+ # GitLab API > Project > Badges > List all badges of a project
129
+ # @example
130
+ # require 'support_ops_gitlab'
131
+ #
132
+ # SupportOps::GitLab::Configuration.configure do |config|
133
+ # config.url = 'https://gitlab.example.com/api/v4'
134
+ # config.token = 'abc123'
135
+ # end
136
+ #
137
+ # tokens = SupportOps::GitLab::ProjectAccessTokens.list(project_id: 5, limit: 10)
138
+ # pp tokens.count
139
+ # # => 10
140
+ # pp tokens.last.revoked
141
+ # # => false
142
+ def self.list(**args)
143
+ args[:group_id] = nil unless args[:group_id]
144
+ args[:project_id] = nil unless args[:project_id]
145
+ args[:name] = nil unless args[:name]
146
+ params = ''
147
+ params += "name=#{args[:name]}&" unless args[:name].nil?
148
+ url = if args[:group_id].nil? && !args[:project_id].nil?
149
+ "projects/#{args[:project_id]}/badges"
150
+ elsif !args[:group_id].nil? && args[:project_id].nil?
151
+ "groups/#{args[:group_id]}/badges"
152
+ else
153
+ raise 'You have to provide a group_id or a project_id (and you cannot provide both)'
154
+ end
155
+ array = []
156
+ page = 1
157
+ loop do
158
+ response = client.connection.get("#{url}?#{params}&page=#{page}&per_page=100")
159
+ body = Oj.load(response.body)
160
+ array += body.map do |b|
161
+ if args[:group_id].nil? && !args[:project_id].nil?
162
+ b['project_id'] = args[:project_id]
163
+ elsif !args[:group_id].nil? && args[:project_id].nil?
164
+ b['group_id'] = args[:group_id]
165
+ else
166
+ raise 'You have to provide a group_id or a project_id (and you cannot provide both)'
167
+ end
168
+ Badges.new(b)
169
+ end
170
+ break if body.count < 100
171
+
172
+ page += 1
173
+ end
174
+ array
175
+ end
176
+
177
+ private
178
+
179
+ ##
180
+ # @private
181
+ def create_record
182
+ url = if self.group_id.nil? && !self.project_id.nil?
183
+ "projects/#{self.project_id}/badges"
184
+ elsif self.group_id.nil? && self.project_id.nil?
185
+ "groups/#{self.group_id}/badges"
186
+ else
187
+ raise 'You have to provide a group_id or a project_id (and you cannot provide both)'
188
+ end
189
+ response = self.client.connection.post(url, attributes_for_save.to_json)
190
+ body = Oj.load(response.body)
191
+ raise "Failed to create badge => #{body}" if response.status != 201
192
+ body
193
+ end
194
+
195
+ ##
196
+ # @private
197
+ def update_record
198
+ raise "Failed to update badge => You didn't change anything in the object" if attributes_for_save.keys == [:id]
199
+ url = if self.group_id.nil? && !self.project_id.nil?
200
+ "projects/#{self.project_id}/badges/#{self.id}"
201
+ elsif self.group_id.nil? && self.project_id.nil?
202
+ "groups/#{self.group_id}/badges/#{self.id}"
203
+ else
204
+ raise 'You have to provide a group_id or a project_id (and you cannot provide both)'
205
+ end
206
+ response = self.client.connection.put(url, attributes_for_save.to_json)
207
+ body = Oj.load(response.body)
208
+ raise "Failed to update badge #{self.id} => #{body}" if response.status != 200
209
+ body
210
+ end
211
+
212
+ ##
213
+ # @private
214
+ def delete_record
215
+ url = if self.group_id.nil? && !self.project_id.nil?
216
+ "projects/#{self.project_id}/badges/#{self.id}"
217
+ elsif self.group_id.nil? && self.project_id.nil?
218
+ "groups/#{self.group_id}/badges/#{self.id}"
219
+ else
220
+ raise 'You have to provide a group_id or a project_id (and you cannot provide both)'
221
+ end
222
+ response = self.client.connection.delete(url)
223
+ body = Oj.load(response.body)
224
+ raise "Failed to delete badge #{self.id} => #{body}" unless response.status == 204
225
+ true
226
+ end
227
+ end
228
+ end
229
+ end