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
@@ -0,0 +1,184 @@
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 Namespaces within the module {SupportOps::GitLab}.
9
+ #
10
+ # @author Jason Colyer
11
+ # @since 1.0.0
12
+ # @attr [String] avatar_url The URL to the avatar of a namespace
13
+ # @attr [Integer] billable_members_count The billable user count of a namespace
14
+ # @attr [String] end_date
15
+ # @attr [String] full_path The full path of the namespace
16
+ # @attr [Integer] id The ID of the namespace
17
+ # @attr [String] kind The type of namespace, can be group or user
18
+ # @attr [Integer] max_seats_used The historical max seats used over the last year
19
+ # @attr [Integer] members_count_with_descendants The count of members include descendents for the namespace
20
+ # @attr [String] name The name of the namespace
21
+ # @attr [Integer] parent_id The parent group ID for creating nested namespace
22
+ # @attr [String] path The path of the namespace
23
+ # @attr [String] plan The subscription plan currently in use for the namespace
24
+ # @attr [Integer] projects_count Number of projects in the namespace
25
+ # @attr [Integer] root_repository_size
26
+ # @attr [Integer] seats_in_use The billable seats in use
27
+ # @attr [Boolean] trial If the namespace is using a trial
28
+ # @attr [String] trial_ends_on Timestamp the trial ends on
29
+ # @attr [String] web_url The URL of the namespace
30
+ # @todo List all namespaces => https://docs.gitlab.com/api/namespaces/#list-all-namespaces
31
+ class Namespaces < SupportOps::GitLab::Base
32
+ # @!parse
33
+ # # Determines if a namespace is on a paid subscription currently
34
+ # #
35
+ # # @author Jason Colyer
36
+ # # @since 1.0.0
37
+ # # @return [Object] Instance of {SupportOps::GitLab::Namespaces}
38
+ # # @note This is inherited from {SupportOps::GitLab::Base#paid?}
39
+ # # @example
40
+ # # require 'support_ops_gitlab'
41
+ # #
42
+ # # SupportOps::GitLab::Configuration.configure do |config|
43
+ # # config.token = ENV.fetch('GL_TOKEN')
44
+ # # config.url = 'https://gitlab.com/api/v4'
45
+ # # end
46
+ # #
47
+ # # namespace = SupportOps::GitLab::Namespaces.get!('test')
48
+ # # pp namespace.paid?
49
+ # # # => false
50
+ define_attributes :avatar_url, :billable_members_count, :end_date,
51
+ :full_path, :id, :kind, :max_seats_used,
52
+ :members_count_with_descendants, :name, :parent_id,
53
+ :path, :plan, :projects_count, :root_repository_size,
54
+ :seats_in_use, :trial, :trial_ends_on, :web_url
55
+ readonly_attributes :avatar_url, :billable_members_count, :end_date,
56
+ :full_path, :id, :kind, :max_seats_used,
57
+ :members_count_with_descendants, :name, :parent_id,
58
+ :path, :plan, :projects_count, :root_repository_size,
59
+ :seats_in_use, :trial, :trial_ends_on, :web_url
60
+
61
+ ##
62
+ # Locates a specific namespace in the GitLab system
63
+ #
64
+ # @author Jason Colyer
65
+ # @since 1.0.0
66
+ # @see
67
+ # https://docs.gitlab.com/api/namespaces/#get-details-on-a-namespace
68
+ # GitLab API > Namespaces > Get details on a namespace
69
+ # @see SupportOps::GitLab::Configuration Setting up a client
70
+ # @example
71
+ # require 'support_ops_gitlab'
72
+ #
73
+ # SupportOps::GitLab::Configuration.configure do |config|
74
+ # config.url = 'https://gitlab.com/api/v4'
75
+ # config.token = 'abc123'
76
+ # end
77
+ #
78
+ # namespace = SupportOps::GitLab::Namespaces.get(123456)
79
+ # pp namespace.plan
80
+ # # => "ultimate"
81
+ # @example
82
+ # require 'support_ops_gitlab'
83
+ #
84
+ # SupportOps::GitLab::Configuration.configure do |config|
85
+ # config.url = 'https://gitlab.com/api/v4'
86
+ # config.token = 'abc123'
87
+ # end
88
+ #
89
+ # namespace = SupportOps::GitLab::Namespaces.get('jcolyer-is-awesome')
90
+ # pp namespace.plan
91
+ # # => "ultimate"
92
+ def self.get(object)
93
+ if object.is_a? Namespaces
94
+ Namespaces.new(id: id).find
95
+ else
96
+ Namespaces.new(id: object).find
97
+ end
98
+ end
99
+
100
+ ##
101
+ # Locates a specific namespace in the GitLab system
102
+ #
103
+ # @author Jason Colyer
104
+ # @since 1.0.0
105
+ # @see
106
+ # https://docs.gitlab.com/api/namespaces/#get-details-on-a-namespace
107
+ # GitLab API > Namespaces > Get details on a namespace
108
+ # @see SupportOps::GitLab::Configuration Setting up a client
109
+ # @example
110
+ # require 'support_ops_gitlab'
111
+ #
112
+ # SupportOps::GitLab::Configuration.configure do |config|
113
+ # config.url = 'https://gitlab.com/api/v4'
114
+ # config.token = 'abc123'
115
+ # end
116
+ #
117
+ # namespace = SupportOps::GitLab::Namespaces.get(123456)
118
+ # pp namespace.plan
119
+ # # => "ultimate"
120
+ # @example
121
+ # require 'support_ops_gitlab'
122
+ #
123
+ # SupportOps::GitLab::Configuration.configure do |config|
124
+ # config.url = 'https://gitlab.com/api/v4'
125
+ # config.token = 'abc123'
126
+ # end
127
+ #
128
+ # namespace = SupportOps::GitLab::Namespaces.get('jcolyer-is-awesome')
129
+ # pp namespace.plan
130
+ # # => "ultimate"
131
+ def self.get!(object)
132
+ if object.is_a? Namespaces
133
+ Namespaces.new(id: id).find!
134
+ else
135
+ Namespaces.new(id: object).find!
136
+ end
137
+ end
138
+
139
+ ##
140
+ # Verifies if a specified namespace already exists
141
+ #
142
+ # @author Jason Colyer
143
+ # @since 1.0.0
144
+ # @see
145
+ # https://docs.gitlab.com/api/namespaces/#verify-namespace-availability
146
+ # GitLab API > Namespaces > Verify namespace availability
147
+ # @see SupportOps::GitLab::Configuration Setting up a client
148
+ # @example
149
+ # require 'support_ops_gitlab'
150
+ #
151
+ # SupportOps::GitLab::Configuration.configure do |config|
152
+ # config.url = 'https://gitlab.com/api/v4'
153
+ # config.token = 'abc123'
154
+ # end
155
+ #
156
+ # pp SupportOps::GitLab::Namespaces.exists?('test')
157
+ # # => true
158
+ # pp SupportOps::GitLab::Namespaces.exists?('testaaaaaaaaaaaa')
159
+ # # => false
160
+ def self.exists?(path)
161
+ response = client.connection.get("namespaces/#{ERB::Util.url_encode(path)}/exists")
162
+ body = Oj.load(response.body)
163
+ body['exists']
164
+ end
165
+
166
+ private
167
+
168
+ ##
169
+ # @private
170
+ def get_record
171
+ response = self.client.connection.get("namespaces/#{self.id}")
172
+ return nil if response.status != 200
173
+
174
+ Oj.load(response.body)
175
+ end
176
+
177
+ ##
178
+ # @private
179
+ def is_paid_record
180
+ %w[bronze silver gold premium ultimate].include? self.plan
181
+ end
182
+ end
183
+ end
184
+ end
@@ -0,0 +1,182 @@
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 Notes within the module {SupportOps::GitLab}.
9
+ #
10
+ # @author Jason Colyer
11
+ # @since 1.0.0
12
+ # @attr [Hash] author Information about the author of a note
13
+ # @attr [String] body The content of a note
14
+ # @attr [Boolean] confidential If the note is confidential or not
15
+ # @attr [String] created_at The timestamp of when the note was created
16
+ # @attr [Integer] id The ID of the note
17
+ # @attr [Boolean] imported If the note was imported or not
18
+ # @attr [String] imported_from Where the note was imported from
19
+ # @attr [Boolean] internal If the note is internal or not
20
+ # @attr [String] merge_request_diff_head_sha The SHA of the head commit, which ensures the merge request wasn’t updated after the API request was sent
21
+ # @attr [Integer] noteable_id The ID of the item the note is attached to
22
+ # @attr [Integer] noteable_iid The IID of the item the note is attached to
23
+ # @attr [String] noteable_type The type of item the note is attached to
24
+ # @attr [Integer] project_id The project ID the note is within
25
+ # @attr [Boolean] resolvable If the note is resolvable or not
26
+ # @attr [Boolean] system If the note is from the system or not
27
+ # @attr [String] updated_at The timestamp of when the note was last updated
28
+ # @todo Get single issue note => https://docs.gitlab.com/api/notes/#get-single-issue-note
29
+ # @todo Get single snippet note => https://docs.gitlab.com/api/notes/#get-single-snippet-note
30
+ # @todo Get single merge request note => https://docs.gitlab.com/api/notes/#get-single-merge-request-note
31
+ # @todo Get single epic note => https://docs.gitlab.com/api/notes/#get-single-epic-note
32
+ # @todo Get single wiki page note (projects) => https://docs.gitlab.com/api/notes/#get-single-wiki-page-note
33
+ # @todo Get single wiki page note (groups) => https://docs.gitlab.com/api/notes/#get-single-wiki-page-note-1
34
+ # @todo Create/update for notes other than Issue and MergeRequest
35
+ # @todo Document save!
36
+ # @todo Document delete!
37
+ class Notes < SupportOps::GitLab::Base
38
+ define_attributes :author, :body, :confidential, :created_at, :id,
39
+ :imported, :imported_from, :internal,
40
+ :merge_request_diff_head_sha, :noteable_id,
41
+ :noteable_iid, :noteable_type, :project_id, :resolvable,
42
+ :system, :updated_at
43
+ readonly_attributes :author, :created_at, :id, :imported, :imported_from,
44
+ :noteable_id, :noteable_iid, :project_id, :resolvable,
45
+ :system, :updated_at
46
+
47
+ ##
48
+ def self.base_url(type, type_id, project_id = nil, group_id = nil)
49
+ return "projects/#{project_id}/issues/#{type_id}/notes" if type == 'Issue'
50
+ return "projects/#{project_id}/snippets/#{type_id}/notes" if type == 'Snippet'
51
+ return "projects/#{project_id}/merge_requests/#{type_id}/notes" if type == 'MergeRequest'
52
+ return "groups/#{group_id}/epics/#{type_id}/notes" if type == 'Epic'
53
+ return "groups/#{group_id}/epics/#{type_id}/notes" if type == 'Epic'
54
+ if type == 'WikiPage::Meta'
55
+ return "projects/#{project_id}/wiki_pages/#{type_id}/notes" if group_id.nil?
56
+ return "groups/#{project_id}/wiki_pages/#{type_id}/notes" if project_id.nil?
57
+ end
58
+ raise "Unable to determine based on type of '#{type}'"
59
+ end
60
+
61
+ ##
62
+ # Lists notes (comments)
63
+ #
64
+ # @author Jason Colyer
65
+ # @since 1.0.0
66
+ # @overload list(key: value)
67
+ # @param type [String required] The place to look for the notes, can be
68
+ # one of the following: Issue, Snippet, MergeRequest, Epic,
69
+ # WikiPage::Meta
70
+ # @param group_id [Integer semi-optional] The group ID to look within;
71
+ # required when type is Epic, WikiPage::Meta (for project wikis)
72
+ # @param project_id [Integer semi-optional] The project ID to look
73
+ # within; required when type is Issue, Snippet, MergeRequest,
74
+ # WikiPage::Meta (for project wikis)
75
+ # @param type_id [Integer required] The ID of the type to look within
76
+ # @param limit [Integer optional] The limit to the number of users
77
+ # returned. Default to 0 (i.e. no limit)
78
+ # @return [Array]
79
+ # @see
80
+ # https://docs.gitlab.com/api/notes/#list-project-issue-notes
81
+ # GitLab API > Notes (Comments) > List project issue notes
82
+ # https://docs.gitlab.com/api/notes/#list-all-snippet-notes
83
+ # GitLab API > Notes (Comments) > List all snippet notes
84
+ # https://docs.gitlab.com/api/notes/#list-all-merge-request-notes
85
+ # GitLab API > Notes (Comments) > List all merge request notes
86
+ # https://docs.gitlab.com/api/notes/#list-all-epic-notes
87
+ # GitLab API > Notes (Comments) > List all epic notes
88
+ # https://docs.gitlab.com/api/notes/#list-all-project-wiki-notes
89
+ # GitLab API > Notes (Comments) > List all project wiki notes
90
+ # https://docs.gitlab.com/api/notes/#list-all-group-wiki-notes
91
+ # GitLab API > Notes (Comments) > List all group wiki notes
92
+ # @see SupportOps::GitLab::Configuration Setting up a client
93
+ # @example
94
+ # require 'support_ops_gitlab'
95
+ #
96
+ # SupportOps::GitLab::Configuration.configure do |config|
97
+ # config.url = 'https://gitlab.example.com/api/v4'
98
+ # config.token = 'abc123'
99
+ # end
100
+ #
101
+ # xxx = SupportOps::GitLab::Notes.list(xxx)
102
+ # pp xxx.count
103
+ # # => 30
104
+ # pp xxx.last.author['id']
105
+ # # => 123
106
+ def self.list(**args)
107
+ args[:type] = nil unless args[:type_id]
108
+ args[:group_id] = nil unless args[:type_id]
109
+ args[:project_id] = nil unless args[:type_id]
110
+ args[:type_id] = nil unless args[:type_id]
111
+ args[:limit] = 0 unless args[:limit]
112
+ raise 'You must provide a type' if args[:type].nil?
113
+ raise 'You must provide a type_id' if args[:type_id].nil?
114
+ raise 'You must provide a project_id' if ['Issue', 'Snippet', 'MergeRequest', 'WikiPage::Meta'].include?(args[:type]) && args[:project_id].nil?
115
+ raise 'You must provide a group_id' if ['Epic', 'WikiPage::Meta'].include?(args[:type]) && args[:group_id].nil?
116
+ url = base_url(args[:type], args[:type_id], args[:project_id], args[:group_id])
117
+ array = []
118
+ page = 1
119
+ loop do
120
+ response = client.connection.get("#{url}?page=#{page}&per_page=100")
121
+ body = Oj.load(response.body)
122
+ array += body.map { |n| Notes.new(n) }
123
+ break if args[:limit].to_i.positive? && array.count >= args[:limit].to_i
124
+ break if body.count < 100
125
+ end
126
+ return array if args[:limit].to_i.zero?
127
+
128
+ array.first(args[:limit].to_i)
129
+ end
130
+
131
+ private
132
+
133
+ ##
134
+ # @private
135
+ def create_record
136
+ raise "This has not been implemented yet for #{self.noteable_type}s" unless %w[Issue MergeRequest].include? self.noteable_type
137
+ data = {
138
+ body: self.body
139
+ }
140
+ if self.noteable_type == 'Issue'
141
+ data[:confidential] = self.confidential
142
+ data[:internal] = self.internal
143
+ url = base_url(self.noteable_type, self.noteable_iid, self.project_id)
144
+ elsif self.noteable_type == 'MergeRequest'
145
+ data[:internal] = self.internal
146
+ data[:merge_request_diff_head_sha] = self.merge_request_diff_head_sha
147
+ url = base_url(self.noteable_type, self.noteable_iid, self.project_id)
148
+ end
149
+ response = self.client.connection.post(url, data.to_json)
150
+ body = Oj.load(response.body)
151
+ raise "Failed to create note => #{body}" if response.status != 201
152
+ body
153
+ end
154
+
155
+ ##
156
+ # @private
157
+ def update_record
158
+ raise "This has not been implemented yet for #{self.noteable_type}s" unless %w[Issue MergeRequest].include? self.noteable_type
159
+ data = {
160
+ body: self.body,
161
+ confidential: self.confidential
162
+ }
163
+ url = base_url(self.noteable_type, self.noteable_iid, self.project_id)
164
+ response = self.client.connection.put(url, data.to_json)
165
+ body = Oj.load(response.body)
166
+ raise "Failed to update note => #{body}" if response.status != 200
167
+ body
168
+ end
169
+
170
+ ##
171
+ # @private
172
+ def delete_record
173
+ raise "This has not been implemented yet for #{self.noteable_type}s" unless %w[Issue MergeRequest].include? self.noteable_type
174
+ url = base_url(self.noteable_type, self.noteable_iid, self.project_id)
175
+ response = self.client.connection.delete(url)
176
+ body = Oj.load(response.body)
177
+ raise "Failed to delete note #{self.id} => #{body}" unless response.status == 204
178
+ true
179
+ end
180
+ end
181
+ end
182
+ end
@@ -0,0 +1,258 @@
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 Pipelines within the module {SupportOps::GitLab}.
9
+ #
10
+ # @author Jason Colyer
11
+ # @since 1.0.0
12
+ # @attr [String] created_at XXX
13
+ # @attr [Integer] id The ID of the pipeline
14
+ # @attr [Integer] iid The integrated ID of the pipeline
15
+ # @attr [Hash] inputs A hash containing the inputs, as key-value pairs, to use when creating the pipeline
16
+ # @attr [String] name The name of the pipeline
17
+ # @attr [Integer] project_id The project the pipeline is on
18
+ # @attr [String] ref The branch or tag to run the pipeline on
19
+ # @attr [String] sha The SHA of the pipeline
20
+ # @attr [String] source The source of the pipeline
21
+ # @attr [String] status The status of the pipeline
22
+ # @attr [String] updated_at The timestamp of when the pipeline was last updated
23
+ # @attr [String] web_url The URL the pipeline is at
24
+ # @attr [Array] variables An array of hashes containing the variables available in the pipeline
25
+ # @todo Document pipeline_variables
26
+ # @todo Get a test report for a pipeline => https://docs.gitlab.com/api/pipelines/#get-a-test-report-for-a-pipeline
27
+ # @todo Get a test report summary for a pipeline => https://docs.gitlab.com/api/pipelines/#get-a-test-report-summary-for-a-pipeline
28
+ # @todo Create a new pipeline => https://docs.gitlab.com/api/pipelines/#create-a-new-pipeline
29
+ # @todo Retry jobs in a pipeline => https://docs.gitlab.com/api/pipelines/#retry-jobs-in-a-pipeline
30
+ # @todo Cancel all jobs for a pipeline => https://docs.gitlab.com/api/pipelines/#cancel-all-jobs-for-a-pipeline
31
+ # @todo Delete a pipeline => https://docs.gitlab.com/api/pipelines/#delete-a-pipeline
32
+ # @todo Update pipeline metadata => https://docs.gitlab.com/api/pipelines/#update-pipeline-metadata
33
+ # @todo Document latest jobs
34
+ class Pipelines < SupportOps::GitLab::Base
35
+ define_attributes :created_at, :id, :iid, :inputs, :name, :project_id,
36
+ :ref, :sha, :source, :status, :updated_at, :web_url,
37
+ :variables
38
+ readonly_attributes :created_at, :id, :iid, :project_id, :sha, :source,
39
+ :status, :updated_at, :web_url
40
+
41
+ ##
42
+ # Lists project pipelines
43
+ #
44
+ # @author Jason Colyer
45
+ # @since 1.0.0
46
+ # @overload list(key: value)
47
+ # @param project_id [Integer required] The project ID to get the
48
+ # pipelines from
49
+ # @param created_after [String optional] Return pipelines created after
50
+ # the specified date; expected in ISO 8601 format
51
+ # (2019-03-15T08:00:00Z)
52
+ # @param created_before [String optional] Return pipelines created
53
+ # before the specified date; expected in ISO 8601 format
54
+ # (2019-03-15T08:00:00Z)
55
+ # @param name [String optional] Return pipelines with the specified name
56
+ # @param order_by [String optional] Order pipelines by id, status, ref,
57
+ # updated_at or user_id
58
+ # @param ref [String optional] The ref of pipelines
59
+ # @param scope [String optional] The scope of pipelines, one of:
60
+ # running, pending, finished, branches, tags
61
+ # @param sha [String optional] The SHA of pipelines
62
+ # @param sort [String optional] Sort pipelines in asc or desc order
63
+ # @param source [String optional] The pipeline source
64
+ # @param status [String optional] The status of pipelines, one of:
65
+ # created, waiting_for_resource, preparing, pending, running, success,
66
+ # failed, canceled, skipped, manual, scheduled
67
+ # @param updated_after [String optional] Return pipelines updated after
68
+ # the specified date; expected in ISO 8601 format
69
+ # (2019-03-15T08:00:00Z)
70
+ # @param updated_before [String optional] Return pipelines updated
71
+ # before the specified date
72
+ # @param username [String optional] The username of the user who
73
+ # triggered pipelines
74
+ # @param yaml_errors [Boolean optional] Returns pipelines with invalid
75
+ # configurations
76
+ # @param limit [Integer optional] The limit to the number of users
77
+ # returned. Default to 0 (i.e. no limit)
78
+ # @return [Array]
79
+ # @see
80
+ # https://docs.gitlab.com/api/pipelines/#list-project-pipelines
81
+ # GitLab API > Pipelines > List project pipelines
82
+ # @see SupportOps::GitLab::Configuration Setting up a client
83
+ # @example
84
+ # require 'support_ops_gitlab'
85
+ #
86
+ # SupportOps::GitLab::Configuration.configure do |config|
87
+ # config.url = 'https://gitlab.example.com/api/v4'
88
+ # config.token = 'abc123'
89
+ # end
90
+ #
91
+ # pipelines = SupportOps::GitLab::Pipelines.list(project_id: 123456)
92
+ # pp pipelines.count
93
+ # # => 30
94
+ # pp pipelines.last.status
95
+ # # => "pending"
96
+ def self.list(**args)
97
+ args[:project_id] = nil unless args[:project_id]
98
+ raise 'You have to provide a project_id' if args[:project_id].nil?
99
+ args[:created_after] = nil unless args[:created_after]
100
+ args[:created_before] = nil unless args[:created_before]
101
+ args[:name] = nil unless args[:name]
102
+ args[:order_by] = nil unless args[:order_by]
103
+ args[:ref] = nil unless args[:ref]
104
+ args[:scope] = nil unless args[:scope]
105
+ args[:sha] = nil unless args[:sha]
106
+ args[:sort] = nil unless args[:sort]
107
+ args[:source] = nil unless args[:source]
108
+ args[:status] = nil unless args[:status]
109
+ args[:updated_after] = nil unless args[:updated_after]
110
+ args[:updated_before] = nil unless args[:updated_before]
111
+ args[:username] = nil unless args[:username]
112
+ args[:yaml_errors] = nil unless args[:yaml_errors]
113
+ args[:limit] = 0 unless args[:limit]
114
+ params = ''
115
+ params += "created_after=#{args[:created_after]}&" unless args[:created_after].nil?
116
+ params += "created_before=#{args[:created_before]}&" unless args[:created_before].nil?
117
+ params += "name=#{args[:name]}&" unless args[:name].nil?
118
+ params += "order_by=#{args[:order_by]}&" unless args[:order_by].nil?
119
+ params += "ref=#{args[:ref]}&" unless args[:ref].nil?
120
+ params += "scope=#{args[:scope]}&" unless args[:scope].nil?
121
+ params += "sha=#{args[:sha]}&" unless args[:sha].nil?
122
+ params += "sort=#{args[:sort]}&" unless args[:sort].nil?
123
+ params += "source=#{args[:source]}&" unless args[:source].nil?
124
+ params += "status=#{args[:status]}&" unless args[:status].nil?
125
+ params += "updated_after=#{args[:updated_after]}&" unless args[:updated_after].nil?
126
+ params += "updated_before=#{args[:updated_before]}&" unless args[:updated_before].nil?
127
+ params += "username=#{args[:username]}&" unless args[:username].nil?
128
+ params += "yaml_errors=#{args[:yaml_errors]}&" unless args[:yaml_errors].nil?
129
+ array = []
130
+ page = 1
131
+ loop do
132
+ response = client.connection.get("projects/#{args[:project_id]}/pipelines?#{params}&page=#{page}&per_page=100")
133
+ body = Oj.load(response.body)
134
+ array += body.map { |p| Pipelines.new(p) }
135
+ break if args[:limit].to_i.positive? && array.count >= args[:limit].to_i
136
+ break if body.count < 100
137
+
138
+ page += 1
139
+ end
140
+ return array if args[:limit].to_i.zero?
141
+
142
+ array.first(args[:limit].to_i)
143
+ end
144
+
145
+ ##
146
+ # Locates a specific pipeline in a project
147
+ #
148
+ # @author Jason Colyer
149
+ # @since 1.0.0
150
+ # @see
151
+ # https://docs.gitlab.com/api/pipelines/#get-a-single-pipeline
152
+ # GitLab API > Pipelines > Get a single pipeline
153
+ # @see SupportOps::GitLab::Configuration Setting up a client
154
+ # @example
155
+ # require 'support_ops_gitlab'
156
+ #
157
+ # SupportOps::GitLab::Configuration.configure do |config|
158
+ # config.url = 'https://gitlab.com/api/v4'
159
+ # config.token = 'abc123'
160
+ # end
161
+ #
162
+ # pipeline = SupportOps::GitLab::Pipelines.get(id: 987654, project_id: 123)
163
+ # pp pipeline.name
164
+ # # => "Awesome pipeline"
165
+ # pp pipeline.id
166
+ # # => 987654
167
+ # pp pipeline.project_id
168
+ # # => 123
169
+ def self.get(object)
170
+ if object.is_a? Pipelines
171
+ Pipelines.new(id: id, project_id: project_id).find
172
+ elsif object.is_a? Hash
173
+ Pipelines.new({ id: object[:id], project_id: object[:project_id] }).find
174
+ else
175
+ raise 'You need an id and a project_id attribute'
176
+ end
177
+ end
178
+
179
+ ##
180
+ # Locates a specific pipeline in a project
181
+ #
182
+ # @author Jason Colyer
183
+ # @since 1.0.0
184
+ # @see
185
+ # https://docs.gitlab.com/api/pipelines/#get-a-single-pipeline
186
+ # GitLab API > Pipelines > Get a single pipeline
187
+ # @see SupportOps::GitLab::Configuration Setting up a client
188
+ # @example
189
+ # require 'support_ops_gitlab'
190
+ #
191
+ # SupportOps::GitLab::Configuration.configure do |config|
192
+ # config.url = 'https://gitlab.com/api/v4'
193
+ # config.token = 'abc123'
194
+ # end
195
+ #
196
+ # pipeline = SupportOps::GitLab::Pipelines.get!(id: 987654, project_id: 123)
197
+ # pp pipeline.name
198
+ # # => "Awesome pipeline"
199
+ # pp pipeline.id
200
+ # # => 987654
201
+ # pp pipeline.project_id
202
+ # # => 123
203
+ def self.get!(object)
204
+ if object.is_a? Pipelines
205
+ Pipelines.new(id: id, project_id: project_id).find!
206
+ elsif object.is_a? Hash
207
+ Pipelines.new({ id: object[:id], project_id: object[:project_id] }).find!
208
+ else
209
+ raise 'You need an id and a project_id attribute'
210
+ end
211
+ end
212
+
213
+ private
214
+
215
+ ##
216
+ # @private
217
+ def get_record
218
+ raise "Cannot locate pipeline based off provided info" if self.id.nil? || self.project_id.nil?
219
+ response = self.client.connection.get("projects/#{self.project_id}/pipelines/#{self.id}")
220
+ return nil if response.status != 200
221
+
222
+ Oj.load(response.body)
223
+ end
224
+
225
+ ##
226
+ # @private
227
+ def pipeline_variables_record
228
+ array = []
229
+ page = 1
230
+ loop do
231
+ response = self.client.connection.get("projects/#{self.project_id}/pipelines/#{self.id}/variables?per_page=100&page=#{page}")
232
+ body = Oj.load(response.body)
233
+ array += body
234
+ break if body.count < 100
235
+
236
+ page += 1
237
+ end
238
+ array
239
+ end
240
+
241
+ ##
242
+ # @private
243
+ def jobs_record
244
+ array = []
245
+ page = 1
246
+ loop do
247
+ response = self.client.connection.get("projects/#{self.project_id}/pipelines/#{self.id}/jobs?per_page=100&page=#{page}")
248
+ body = Oj.load(response.body)
249
+ array += body.map { |j| Jobs.new(j) }
250
+ break if body.count < 100
251
+
252
+ page += 1
253
+ end
254
+ array
255
+ end
256
+ end
257
+ end
258
+ end