gitlab_support_readiness 1.0.11 → 1.0.13
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/support_readiness/calendly/client.rb +64 -0
- data/lib/support_readiness/calendly/configuration.rb +45 -0
- data/lib/support_readiness/calendly/organization_memberships.rb +67 -0
- data/lib/support_readiness/calendly/organizations.rb +123 -0
- data/lib/support_readiness/calendly/users.rb +105 -0
- data/lib/support_readiness/calendly.rb +16 -0
- data/lib/support_readiness/client.rb +88 -1
- data/lib/support_readiness/dates.rb +90 -0
- data/lib/support_readiness/gitlab/configuration.rb +0 -1
- data/lib/support_readiness/gitlab/groups.rb +35 -0
- data/lib/support_readiness/gitlab/jobs.rb +189 -0
- data/lib/support_readiness/gitlab/markdown.rb +37 -0
- data/lib/support_readiness/gitlab/merge_requests.rb +127 -0
- data/lib/support_readiness/gitlab/namespaces.rb +22 -0
- data/lib/support_readiness/gitlab/pipelines.rb +191 -0
- data/lib/support_readiness/gitlab/projects.rb +85 -1
- data/lib/support_readiness/gitlab/repositories.rb +174 -0
- data/lib/support_readiness/gitlab/users.rb +24 -0
- data/lib/support_readiness/gitlab.rb +4 -0
- data/lib/support_readiness/google_calendar/client.rb +59 -0
- data/lib/support_readiness/google_calendar/configuration.rb +39 -0
- data/lib/support_readiness/google_calendar/events.rb +169 -0
- data/lib/support_readiness/google_calendar.rb +14 -0
- data/lib/support_readiness/mailgun/bounces.rb +103 -0
- data/lib/support_readiness/mailgun/client.rb +65 -0
- data/lib/support_readiness/mailgun/configuration.rb +46 -0
- data/lib/support_readiness/mailgun/emails.rb +95 -0
- data/lib/support_readiness/mailgun.rb +15 -0
- data/lib/support_readiness/pagerduty/escalation_policies.rb +1 -1
- data/lib/support_readiness/pagerduty/schedules.rb +27 -3
- data/lib/support_readiness/pagerduty/services.rb +1 -1
- data/lib/support_readiness/pagerduty/users.rb +197 -0
- data/lib/support_readiness/pagerduty.rb +1 -0
- data/lib/support_readiness/repos/articles.rb +335 -0
- data/lib/support_readiness/repos/automations.rb +247 -0
- data/lib/support_readiness/repos/groups.rb +188 -0
- data/lib/support_readiness/repos/macros.rb +224 -0
- data/lib/support_readiness/repos/organization_fields.rb +193 -0
- data/lib/support_readiness/repos/sla_policies.rb +192 -0
- data/lib/support_readiness/repos/ticket_fields.rb +200 -0
- data/lib/support_readiness/repos/ticket_forms.rb +200 -0
- data/lib/support_readiness/repos/triggers.rb +255 -0
- data/lib/support_readiness/repos/user_fields.rb +201 -0
- data/lib/support_readiness/repos/views.rb +362 -0
- data/lib/support_readiness/repos.rb +22 -0
- data/lib/support_readiness/salesforce/accounts.rb +109 -0
- data/lib/support_readiness/salesforce/cases.rb +109 -0
- data/lib/support_readiness/salesforce/client.rb +64 -0
- data/lib/support_readiness/salesforce/configuration.rb +49 -0
- data/lib/support_readiness/salesforce/queries.rb +62 -0
- data/lib/support_readiness/salesforce.rb +16 -0
- data/lib/support_readiness/slack/client.rb +63 -0
- data/lib/support_readiness/slack/configuration.rb +43 -0
- data/lib/support_readiness/slack/messages.rb +37 -0
- data/lib/support_readiness/slack.rb +14 -0
- data/lib/support_readiness/zendesk/app_job_statuses.rb +140 -0
- data/lib/support_readiness/zendesk/apps.rb +209 -0
- data/lib/support_readiness/zendesk/automations.rb +1 -2
- data/lib/support_readiness/zendesk/macros.rb +1 -3
- data/lib/support_readiness/zendesk/organization_fields.rb +1 -1
- data/lib/support_readiness/zendesk/theme_job_statuses.rb +136 -0
- data/lib/support_readiness/zendesk/themes.rb +303 -0
- data/lib/support_readiness/zendesk/ticket_field_options.rb +110 -0
- data/lib/support_readiness/zendesk/ticket_fields.rb +85 -16
- data/lib/support_readiness/zendesk/ticket_forms.rb +65 -2
- data/lib/support_readiness/zendesk/tickets.rb +77 -0
- data/lib/support_readiness/zendesk/triggers.rb +1 -2
- data/lib/support_readiness/zendesk/user_field_options.rb +110 -0
- data/lib/support_readiness/zendesk/user_fields.rb +257 -0
- data/lib/support_readiness/zendesk/views.rb +49 -2
- data/lib/support_readiness/zendesk.rb +7 -0
- data/lib/support_readiness.rb +16 -0
- metadata +122 -2
@@ -0,0 +1,189 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# Defines the module Readiness.
|
4
|
+
module Readiness
|
5
|
+
# Defines the module GitLab
|
6
|
+
module GitLab
|
7
|
+
##
|
8
|
+
# Defines the class Jobs within the module {Readiness::GitLab}.
|
9
|
+
#
|
10
|
+
# @author Jason Colyer
|
11
|
+
# @since 1.0.13
|
12
|
+
# @todo List pipeline trigger jobs
|
13
|
+
# @todo Get job token’s job
|
14
|
+
# @todo Get GitLab agent by CI_JOB_TOKEN
|
15
|
+
# @todo Get a log file
|
16
|
+
# @todo Cancel a job
|
17
|
+
# @todo Retry a job
|
18
|
+
# @todo Erase a job
|
19
|
+
# @todo Run a job
|
20
|
+
class Jobs < Readiness::Client
|
21
|
+
attr_accessor :allow_failure, :archived, :artifacts, :artifacts_expire_at, :commit, :coverage, :created_at, :duration, :erased_at, :failure_reason, :finished_at, :id, :name, :pipeline, :project, :queued_duration, :ref, :runner, :runner_manager, :stage, :started_at, :status, :tag, :tag_list, :user, :web_url
|
22
|
+
|
23
|
+
##
|
24
|
+
# Creates a new {Readiness::GitLab::Jobs} instance
|
25
|
+
#
|
26
|
+
# @author Jason Colyer
|
27
|
+
# @since 1.0.13
|
28
|
+
# @param object [Object] An instance of {Readiness::GitLab::Jobs}
|
29
|
+
# @example
|
30
|
+
# require 'support_readiness'
|
31
|
+
# Readiness::GitLab::Jobs.new
|
32
|
+
def initialize(object = {})
|
33
|
+
@allow_failure = object['allow_failure']
|
34
|
+
@archived = object['archived']
|
35
|
+
@artifacts = object['artifacts']
|
36
|
+
@artifacts_expire_at = object['artifacts_expire_at']
|
37
|
+
@commit = object['commit']
|
38
|
+
@coverage = object['coverage']
|
39
|
+
@created_at = object['created_at']
|
40
|
+
@duration = object['duration']
|
41
|
+
@erased_at = object['erased_at']
|
42
|
+
@failure_reason = object['failure_reason']
|
43
|
+
@finished_at = object['finished_at']
|
44
|
+
@id = object['id']
|
45
|
+
@name = object['name']
|
46
|
+
@pipeline = object['pipeline']
|
47
|
+
@project = object['project']
|
48
|
+
@queued_duration = object['queued_duration']
|
49
|
+
@ref = object['ref']
|
50
|
+
@runner = object['runner']
|
51
|
+
@runner_manager = object['runner_manager']
|
52
|
+
@stage = object['stage']
|
53
|
+
@started_at = object['started_at']
|
54
|
+
@status = object['status']
|
55
|
+
@tag = object['tag']
|
56
|
+
@tag_list = object['tag_list']
|
57
|
+
@user = object['user']
|
58
|
+
@web_url = object['web_url']
|
59
|
+
end
|
60
|
+
|
61
|
+
##
|
62
|
+
# Lists all project jobs. Does not stop until it ends or the page limit is hit.
|
63
|
+
# This method can take a long time to run depending on the parameters used.
|
64
|
+
#
|
65
|
+
# @author Jason Colyer
|
66
|
+
# @since 1.0.13
|
67
|
+
# @param client [Object] An instance of {Readiness::GitLab::Client}
|
68
|
+
# @param project [Object] An instance of {Readiness::GitLab::Projects}
|
69
|
+
# @param limit [Integer] The number of pages to stop at. Using 0 means to list all.
|
70
|
+
# @param filters [Array] An array of filter Strings to use. Should be in the format of key=value
|
71
|
+
# @return [Array]
|
72
|
+
# @see https://docs.gitlab.com/ee/api/jobs.html#list-project-jobs GitLab API > Jobs > List project jobs
|
73
|
+
# @example
|
74
|
+
# require 'support_readiness'
|
75
|
+
# config = Readiness::GitLab::Configuration.new
|
76
|
+
# config.token = 'test123abc'
|
77
|
+
# client = Readiness::GitLab::Client.new(config)
|
78
|
+
# project = Readiness::GitLab::Projects.find!(client, 1083469)
|
79
|
+
# jobs = Readiness::GitLab::Jobs.list_project(client, project, 2)
|
80
|
+
# puts jobs.count
|
81
|
+
# # => 200
|
82
|
+
def list_project(client, project, limit = 0, filters = [])
|
83
|
+
array = []
|
84
|
+
page = 1
|
85
|
+
loop do
|
86
|
+
response = client.connection.get "projects/#{project.id}/jobs?per_page=100&page=#{page}&#{to_param_string(filters)}"
|
87
|
+
handle_request_error(0, 'GitLab', response.status) unless response.status == 200
|
88
|
+
body = Oj.load(response.body)
|
89
|
+
array += body.map { |p| Jobs.new(p) }
|
90
|
+
break if body.count < 100
|
91
|
+
break if limit != 0 && array.count >= (limit * 100)
|
92
|
+
|
93
|
+
page += 1
|
94
|
+
end
|
95
|
+
array
|
96
|
+
end
|
97
|
+
|
98
|
+
##
|
99
|
+
# Lists all pipeline jobs. Does not stop until it ends or the page limit is hit.
|
100
|
+
# This method can take a long time to run depending on the parameters used.
|
101
|
+
#
|
102
|
+
# @author Jason Colyer
|
103
|
+
# @since 1.0.13
|
104
|
+
# @param client [Object] An instance of {Readiness::GitLab::Client}
|
105
|
+
# @param pipeline [Object] An instance of {Readiness::GitLab::Pipelines}
|
106
|
+
# @param limit [Integer] The number of pages to stop at. Using 0 means to list all.
|
107
|
+
# @param filters [Array] An array of filter Strings to use. Should be in the format of key=value
|
108
|
+
# @return [Array]
|
109
|
+
# @see https://docs.gitlab.com/ee/api/jobs.html#list-pipeline-jobs GitLab API > Jobs > List pipeline jobs
|
110
|
+
# @example
|
111
|
+
# require 'support_readiness'
|
112
|
+
# config = Readiness::GitLab::Configuration.new
|
113
|
+
# config.token = 'test123abc'
|
114
|
+
# client = Readiness::GitLab::Client.new(config)
|
115
|
+
# project = Readiness::GitLab::Projects.find!(client, 1083469)
|
116
|
+
# pipelines = Readiness::GitLab::Pipelines.list(client, project, 2, ["name=Check System", "status=failed"])
|
117
|
+
# jobs = Readiness::GitLab::Jobs.list_pipeline(client, pipeline, 1)
|
118
|
+
# puts jobs.count
|
119
|
+
# # => 100
|
120
|
+
def list_pipeline(client, pipeline, limit = 0, filters = [])
|
121
|
+
array = []
|
122
|
+
page = 1
|
123
|
+
loop do
|
124
|
+
response = client.connection.get "projects/#{pipeline.project_id}/pipelines/#{pipeline.iid}/jobs?per_page=100&page=#{page}&#{to_param_string(filters)}"
|
125
|
+
handle_request_error(0, 'GitLab', response.status) unless response.status == 200
|
126
|
+
body = Oj.load(response.body)
|
127
|
+
array += body.map { |p| Jobs.new(p) }
|
128
|
+
break if body.count < 100
|
129
|
+
break if limit != 0 && array.count >= (limit * 100)
|
130
|
+
|
131
|
+
page += 1
|
132
|
+
end
|
133
|
+
array
|
134
|
+
end
|
135
|
+
|
136
|
+
##
|
137
|
+
# Locates a project job within GitLab. This will not exit on error (except Authentication errors)
|
138
|
+
#
|
139
|
+
# @author Jason Colyer
|
140
|
+
# @since 1.0.13
|
141
|
+
# @param client [Object] An instance of {Readiness::GitLab::Client}
|
142
|
+
# @param project [Object] An instance of {Readiness::GitLab::Projects}
|
143
|
+
# @param jid [Integer] The job IID to find
|
144
|
+
# @return [Hash]
|
145
|
+
# @see https://docs.gitlab.com/ee/api/jobs.html#get-a-single-job GitLab API > Jobs > get a sngle job
|
146
|
+
# @example
|
147
|
+
# require 'support_readiness'
|
148
|
+
# config = Readiness::GitLab::Configuration.new
|
149
|
+
# config.token = 'test123abc'
|
150
|
+
# client = Readiness::GitLab::Client.new(config)
|
151
|
+
# project = Readiness::GitLab::Projects.find!(client, 1083469)
|
152
|
+
# job = Readiness::GitLab::Jobs.find(client, project, 5)
|
153
|
+
# puts job.status
|
154
|
+
# # => "failed"
|
155
|
+
def self.find(client, project, jid)
|
156
|
+
response = client.connection.get "projects/#{project.id}/jobs/#{jid}"
|
157
|
+
handle_request_error(0, 'GitLab', response.status, { action: 'get', id: jid }) unless response.status == 200
|
158
|
+
return Jobs.new(Oj.load(response.body)) if response.status == 200
|
159
|
+
|
160
|
+
Oj.load(response.body)
|
161
|
+
end
|
162
|
+
|
163
|
+
##
|
164
|
+
# Locates a project job within GitLab. This will not exit on error (except Authentication errors)
|
165
|
+
#
|
166
|
+
# @author Jason Colyer
|
167
|
+
# @since 1.0.13
|
168
|
+
# @param client [Object] An instance of {Readiness::GitLab::Client}
|
169
|
+
# @param project [Object] An instance of {Readiness::GitLab::Projects}
|
170
|
+
# @param jid [Integer] The job IID to find
|
171
|
+
# @return [Object] An instance of {Readiness::GitLab::Jobs
|
172
|
+
# @see https://docs.gitlab.com/ee/api/jobs.html#get-a-single-job GitLab API > Jobs > get a sngle job
|
173
|
+
# @example
|
174
|
+
# require 'support_readiness'
|
175
|
+
# config = Readiness::GitLab::Configuration.new
|
176
|
+
# config.token = 'test123abc'
|
177
|
+
# client = Readiness::GitLab::Client.new(config)
|
178
|
+
# project = Readiness::GitLab::Projects.find!(client, 1083469)
|
179
|
+
# job = Readiness::GitLab::Jobs.find!(client, project, 5)
|
180
|
+
# puts job.status
|
181
|
+
# # => "failed"
|
182
|
+
def self.find(client, project, jid)
|
183
|
+
response = client.connection.get "projects/#{project.id}/jobs/#{jid}"
|
184
|
+
handle_request_error(1, 'GitLab', response.status, { action: 'Find job', id: jid }) unless response.status == 200
|
185
|
+
Jobs.new(Oj.load(response.body))
|
186
|
+
end
|
187
|
+
end
|
188
|
+
end
|
189
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# Defines the module Readiness.
|
4
|
+
module Readiness
|
5
|
+
# Defines the module GitLab
|
6
|
+
module GitLab
|
7
|
+
##
|
8
|
+
# Defines the class Markdown within the module {Readiness::GitLab}.
|
9
|
+
#
|
10
|
+
# @author Jason Colyer
|
11
|
+
# @since 1.0.12
|
12
|
+
class Markdown < Readiness::Client
|
13
|
+
##
|
14
|
+
# Renders text using Markdown
|
15
|
+
#
|
16
|
+
# @author Jason Colyer
|
17
|
+
# @since 1.0.12
|
18
|
+
# @param client [Object] An instance of {Readiness::GitLab::Client}
|
19
|
+
# @param text [String] The text to render
|
20
|
+
# @param gfm [Boolean] If this should render as GitLab Flavored Markdown or not
|
21
|
+
# @param project [String] The project slug to use as a template
|
22
|
+
# @return [String]
|
23
|
+
# @see https://docs.gitlab.com/ee/api/markdown.html#render-an-arbitrary-markdown-document GitLab API > Markdown > Render an arbitrary Markdown document
|
24
|
+
# @example
|
25
|
+
# require 'support_readiness'
|
26
|
+
# config = Readiness::GitLab::Configuration.new
|
27
|
+
# config.token = ENV.fetch('GL_TOKEN')
|
28
|
+
# client = Readiness::GitLab::Client.new(config)
|
29
|
+
# pp Readiness::GitLab::Markdown.convert(client, 'This is a test')
|
30
|
+
# # => "<p data-sourcepos=\"1:1-1:14\">This is a test</p>"
|
31
|
+
def self.convert(client, text, gfm = false, project = 'gitlab-org/gitlab')
|
32
|
+
response = client.connection.post 'markdown', { text: text, gfm: gfm, project: project }.to_json
|
33
|
+
Oj.load(response.body)['html']
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,127 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# Defines the module Readiness.
|
4
|
+
module Readiness
|
5
|
+
# Defines the module GitLab
|
6
|
+
module GitLab
|
7
|
+
##
|
8
|
+
# Defines the class MergeRequests within the module {Readiness::GitLab}.
|
9
|
+
#
|
10
|
+
# @author Jason Colyer
|
11
|
+
# @since 1.0.12
|
12
|
+
class MergeRequests < Readiness::Client
|
13
|
+
##
|
14
|
+
# Locates a project merge request within GitLab. This will not exit on error (except Authentication errors)
|
15
|
+
#
|
16
|
+
# @author Jason Colyer
|
17
|
+
# @since 1.0.12
|
18
|
+
# @param client [Object] An instance of {Readiness::GitLab::Client}
|
19
|
+
# @param project [Object] An instance of {Readiness::GitLab::Projects}
|
20
|
+
# @param iid [Integer] The issue ID to find
|
21
|
+
# @return [Hash]
|
22
|
+
# @see https://docs.gitlab.com/ee/api/merge_requests.html#get-single-mr GitLab API > Merge requests > Get single MR
|
23
|
+
# @example
|
24
|
+
# require 'support_readiness'
|
25
|
+
# config = Readiness::GitLab::Configuration.new
|
26
|
+
# config.token = 'test123abc'
|
27
|
+
# client = Readiness::GitLab::Client.new(config)
|
28
|
+
# project = Readiness::GitLab::Projects.find!(client, 1083469)
|
29
|
+
# issue = Readiness::GitLab::MergeRequests.find(client, project, 5)
|
30
|
+
# puts issues.web_url
|
31
|
+
# # => "https://gitlab.com/gitlab-com/support/support-team-meta/-/merge_requests/5"
|
32
|
+
def self.find(client, project, iid)
|
33
|
+
response = client.connection.get "projects/#{project.id}/merge_requests/#{iid}"
|
34
|
+
Oj.load(response.body)
|
35
|
+
end
|
36
|
+
|
37
|
+
##
|
38
|
+
# Locates a project merge request within GitLab. This will exit on error
|
39
|
+
#
|
40
|
+
# @author Jason Colyer
|
41
|
+
# @since 1.0.12
|
42
|
+
# @param client [Object] An instance of {Readiness::GitLab::Client}
|
43
|
+
# @param project [Object] An instance of {Readiness::GitLab::Projects}
|
44
|
+
# @param iid [Integer] The issue ID to find
|
45
|
+
# @return [Hash]
|
46
|
+
# @see https://docs.gitlab.com/ee/api/merge_requests.html#get-single-mr GitLab API > Merge requests > Get single MR
|
47
|
+
# @example
|
48
|
+
# require 'support_readiness'
|
49
|
+
# config = Readiness::GitLab::Configuration.new
|
50
|
+
# config.token = 'test123abc'
|
51
|
+
# client = Readiness::GitLab::Client.new(config)
|
52
|
+
# project = Readiness::GitLab::Projects.find!(client, 1083469)
|
53
|
+
# issue = Readiness::GitLab::MergeRequests.find!(client, project, 5)
|
54
|
+
# puts issues.web_url
|
55
|
+
# # => "https://gitlab.com/gitlab-com/support/support-team-meta/-/merge_requests/5"
|
56
|
+
def self.find!(client, project, iid)
|
57
|
+
response = client.connection.get "projects/#{project.id}/merge_requests/#{iid}"
|
58
|
+
handle_request_error(1, 'GitLab', response.status, { action: 'Find MR', id: "projects/#{project.id}/merge_requests/#{iid}" }) unless response.status == 200
|
59
|
+
Oj.load(response.body)
|
60
|
+
end
|
61
|
+
|
62
|
+
##
|
63
|
+
# Get all comments on a project merge request within GitLab.
|
64
|
+
#
|
65
|
+
# @author Jason Colyer
|
66
|
+
# @since 1.0.12
|
67
|
+
# @param client [Object] An instance of {Readiness::GitLab::Client}
|
68
|
+
# @param project [Object] An instance of {Readiness::GitLab::Projects}
|
69
|
+
# @param iid [Integer] The IID of the merge request
|
70
|
+
# @return [Array]
|
71
|
+
# @see https://docs.gitlab.com/ee/api/notes.html#list-all-merge-request-notes GitLab API > Notes (comments) > List all merge request notes
|
72
|
+
# @example
|
73
|
+
# require 'support_readiness'
|
74
|
+
# config = Readiness::GitLab::Configuration.new
|
75
|
+
# config.token = 'test123abc'
|
76
|
+
# client = Readiness::GitLab::Client.new(config)
|
77
|
+
# project = Readiness::GitLab::Projects.find!(client, 5)
|
78
|
+
# comments = Readiness::GitLab::MergeRequests.comments(client, project, 123)
|
79
|
+
# pp comments.first['updated_at']
|
80
|
+
# # => "2013-10-02T09:56:03Z"
|
81
|
+
def self.comments(client, project, iid)
|
82
|
+
array = []
|
83
|
+
page = 0
|
84
|
+
loop do
|
85
|
+
response = client.connection.get "projects/#{project.id}/merge_requests/#{iid}/notes?per_page=100&page=#{page}"
|
86
|
+
handle_request_error(0, 'GitLab', response.status) unless response.status == 200
|
87
|
+
body = Oj.load(response.body)
|
88
|
+
array += body
|
89
|
+
break if body.count < 100
|
90
|
+
|
91
|
+
page += 1
|
92
|
+
end
|
93
|
+
array
|
94
|
+
end
|
95
|
+
|
96
|
+
##
|
97
|
+
# Create a comment on a project merge request within GitLab.
|
98
|
+
#
|
99
|
+
# @author Jason Colyer
|
100
|
+
# @since 1.0.12
|
101
|
+
# @param client [Object] An instance of {Readiness::GitLab::Client}
|
102
|
+
# @param project [Object] An instance of {Readiness::GitLab::Projects}
|
103
|
+
# @param iid [Integer] The IID of the merge request
|
104
|
+
# @param params [Hash] The parameters to use in creating the comment
|
105
|
+
# @return [Hash]
|
106
|
+
# @see https://docs.gitlab.com/ee/api/notes.html#create-new-merge-request-note GitLab API > Notes (comments) > Create new merge request note
|
107
|
+
# @example
|
108
|
+
# require 'support_readiness'
|
109
|
+
# config = Readiness::GitLab::Configuration.new
|
110
|
+
# config.token = 'test123abc'
|
111
|
+
# client = Readiness::GitLab::Client.new(config)
|
112
|
+
# project = Readiness::GitLab::Projects.find!(client, 5)
|
113
|
+
# comment_params = {
|
114
|
+
# body: 'My name is Jason and I approve this comment',
|
115
|
+
# internal: true
|
116
|
+
# }
|
117
|
+
# comment = Readiness::GitLab::MergeRequests.create_comment(client, project, 123, comment_params)
|
118
|
+
# pp comment['updated_at']
|
119
|
+
# # => "2024-09-23T15:42:13Z"
|
120
|
+
def self.create_comment!(client, project, iid, params)
|
121
|
+
response = client.connection.post "projects/#{project.id}/merge_requests/#{iid}/notes", params.to_json
|
122
|
+
handle_request_error(1, 'GitLab', response.status, { action: 'Create MR comment', id: "projects/#{project.id}/merge_requests/#{iid}" }) unless response.status == 200
|
123
|
+
Oj.load(response.body)
|
124
|
+
end
|
125
|
+
end
|
126
|
+
end
|
127
|
+
end
|
@@ -185,6 +185,28 @@ module Readiness
|
|
185
185
|
handle_request_error(0, 'GitLab', response.status, { action: 'get', id: namespace.id }) unless response.status == 200
|
186
186
|
Oj.load(response.body)
|
187
187
|
end
|
188
|
+
|
189
|
+
##
|
190
|
+
# Determines if a given namespace is paid or not
|
191
|
+
#
|
192
|
+
# @author Jason Colyer
|
193
|
+
# @since 1.0.12
|
194
|
+
# @param client [Object] An instance of {Readiness::GitLab::Client}
|
195
|
+
# @param namespace [Object] An instance of {Readiness::GitLab::Namespaces}
|
196
|
+
# @return [Boolean]
|
197
|
+
# @example
|
198
|
+
# require 'support_readiness'
|
199
|
+
# config = Readiness::GitLab::Configuration.new
|
200
|
+
# config.token = 'test123abc'
|
201
|
+
# client = Readiness::GitLab::Client.new(config)
|
202
|
+
# namespace = Readiness::GitLab::Namespaces.find!(client, 123)
|
203
|
+
# pp Readiness::GitLab::Namespaces.is_paid?(client, namespace)
|
204
|
+
# # => true
|
205
|
+
def self.is_paid?(client, namespace)
|
206
|
+
return true if %w[bronze silver gold premium ultimate].include? namespace.plan
|
207
|
+
|
208
|
+
false
|
209
|
+
end
|
188
210
|
end
|
189
211
|
end
|
190
212
|
end
|
@@ -0,0 +1,191 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# Defines the module Readiness.
|
4
|
+
module Readiness
|
5
|
+
# Defines the module GitLab
|
6
|
+
module GitLab
|
7
|
+
##
|
8
|
+
# Defines the class Pipelines within the module {Readiness::GitLab}.
|
9
|
+
#
|
10
|
+
# @author Jason Colyer
|
11
|
+
# @since 1.0.13
|
12
|
+
# @todo Get a pipeline’s test report
|
13
|
+
# @todo Get a pipeline’s test report summary
|
14
|
+
# @todo Create a new pipeline
|
15
|
+
# @todo Retry jobs in a pipeline
|
16
|
+
# @todo Cancel a pipeline's jobs
|
17
|
+
# @todo Delete a pipeline
|
18
|
+
# @todo Update pipeline metadata
|
19
|
+
class Pipelines < Readiness::Client
|
20
|
+
attr_accessor :created_at, :id, :iid, :name, :project_id, :ref, :sha, :source, :status, :updated_at, :web_url
|
21
|
+
|
22
|
+
##
|
23
|
+
# Creates a new {Readiness::GitLab::Pipelines} instance
|
24
|
+
#
|
25
|
+
# @author Jason Colyer
|
26
|
+
# @since 1.0.13
|
27
|
+
# @param object [Object] An instance of {Readiness::GitLab::Pipelines}
|
28
|
+
# @example
|
29
|
+
# require 'support_readiness'
|
30
|
+
# Readiness::GitLab::Pipelines.new
|
31
|
+
def initialize(object = {})
|
32
|
+
@created_at = object['created_at']
|
33
|
+
@id = object['id']
|
34
|
+
@iid = object['iid']
|
35
|
+
@name = object['name']
|
36
|
+
@project_id = object['project_id']
|
37
|
+
@ref = object['ref']
|
38
|
+
@sha = object['sha']
|
39
|
+
@source = object['source']
|
40
|
+
@status = object['status']
|
41
|
+
@updated_at = object['updated_at']
|
42
|
+
@web_url = object['web_url']
|
43
|
+
end
|
44
|
+
|
45
|
+
##
|
46
|
+
# Lists all pipelines for an object. Does not stop until it ends or the page limit is hit.
|
47
|
+
# This method can take a long time to run depending on the parameters used.
|
48
|
+
#
|
49
|
+
# @author Jason Colyer
|
50
|
+
# @since 1.0.13
|
51
|
+
# @param client [Object] An instance of {Readiness::GitLab::Client}
|
52
|
+
# @param project [Object] An instance of {Readiness::GitLab::Projects}
|
53
|
+
# @param limit [Integer] The number of pages to stop at. Using 0 means to list all.
|
54
|
+
# @param filters [Array] An array of filter Strings to use. Should be in the format of key=value
|
55
|
+
# @return [Array]
|
56
|
+
# @see https://docs.gitlab.com/ee/api/pipelines.html#list-project-pipelines GitLab API > Pipelines > List project pipelines
|
57
|
+
# @example
|
58
|
+
# require 'support_readiness'
|
59
|
+
# config = Readiness::GitLab::Configuration.new
|
60
|
+
# config.token = 'test123abc'
|
61
|
+
# client = Readiness::GitLab::Client.new(config)
|
62
|
+
# project = Readiness::GitLab::Projects.find!(client, 1083469)
|
63
|
+
# pipelines = Readiness::GitLab::Pipelines.list(client, project, 2, ["name=Check System", "status=failed"])
|
64
|
+
# puts pipelines.first.web_url
|
65
|
+
# # => "https://gitlab.com/gitlab-com/support/support-team-meta/-/pipelines/2"
|
66
|
+
def self.list(client, project, limit = 0, filters = [])
|
67
|
+
array = []
|
68
|
+
page = 1
|
69
|
+
loop do
|
70
|
+
response = client.connection.get "projects/#{project.id}/pipelines?per_page=100&page=#{page}&#{to_param_string(filters)}"
|
71
|
+
handle_request_error(0, 'GitLab', response.status) unless response.status == 200
|
72
|
+
body = Oj.load(response.body)
|
73
|
+
array += body.map { |p| Pipelines.new(p) }
|
74
|
+
break if body.count < 100
|
75
|
+
break if limit != 0 && array.count >= (limit * 100)
|
76
|
+
|
77
|
+
page += 1
|
78
|
+
end
|
79
|
+
array
|
80
|
+
end
|
81
|
+
|
82
|
+
##
|
83
|
+
# Locates a project pipeline within GitLab. This will not exit on error (except Authentication errors)
|
84
|
+
#
|
85
|
+
# @author Jason Colyer
|
86
|
+
# @since 1.0.13
|
87
|
+
# @param client [Object] An instance of {Readiness::GitLab::Client}
|
88
|
+
# @param project [Object] An instance of {Readiness::GitLab::Projects}
|
89
|
+
# @param pid [Integer] The pipeline IID to find
|
90
|
+
# @return [Hash]
|
91
|
+
# @see https://docs.gitlab.com/ee/api/pipelines.html#get-a-single-pipeline GitLab API > Pipelines > Get a single pipeline
|
92
|
+
# @example
|
93
|
+
# require 'support_readiness'
|
94
|
+
# config = Readiness::GitLab::Configuration.new
|
95
|
+
# config.token = 'test123abc'
|
96
|
+
# client = Readiness::GitLab::Client.new(config)
|
97
|
+
# project = Readiness::GitLab::Projects.find!(client, 1083469)
|
98
|
+
# pipeline = Readiness::GitLab::Pipelines.find(client, project, 5)
|
99
|
+
# puts pipeline.web_url
|
100
|
+
# # => "https://gitlab.com/gitlab-com/support/support-team-meta/-/pipelines/5"
|
101
|
+
def self.find(client, project, pid)
|
102
|
+
response = client.connection.get "projects/#{project.id}/pipelines/#{pid}"
|
103
|
+
handle_request_error(0, 'GitLab', response.status, { action: 'get', id: pid }) unless response.status == 200
|
104
|
+
return Pipelines.new(Oj.load(response.body)) if response.status == 200
|
105
|
+
|
106
|
+
Oj.load(response.body)
|
107
|
+
end
|
108
|
+
|
109
|
+
##
|
110
|
+
# Locates a project pipeline within GitLab. This will exit on error
|
111
|
+
#
|
112
|
+
# @author Jason Colyer
|
113
|
+
# @since 1.0.13
|
114
|
+
# @param client [Object] An instance of {Readiness::GitLab::Client}
|
115
|
+
# @param project [Object] An instance of {Readiness::GitLab::Projects}
|
116
|
+
# @param pid [Integer] The pipeline IID to find
|
117
|
+
# @return [Object] An instance of {Readiness::GitLab::Pipelines}
|
118
|
+
# @see https://docs.gitlab.com/ee/api/pipelines.html#get-a-single-pipeline GitLab API > Pipelines > Get a single pipeline
|
119
|
+
# @example
|
120
|
+
# require 'support_readiness'
|
121
|
+
# config = Readiness::GitLab::Configuration.new
|
122
|
+
# config.token = 'test123abc'
|
123
|
+
# client = Readiness::GitLab::Client.new(config)
|
124
|
+
# project = Readiness::GitLab::Projects.find!(client, 1083469)
|
125
|
+
# pipeline = Readiness::GitLab::Pipelines.find!(client, project, 5)
|
126
|
+
# puts pipeline.web_url
|
127
|
+
# # => "https://gitlab.com/gitlab-com/support/support-team-meta/-/pipelines/5"
|
128
|
+
def self.find!(client, project, pid)
|
129
|
+
response = client.connection.get "projects/#{project.id}/pipelines/#{pid}"
|
130
|
+
handle_request_error(1, 'GitLab', response.status, { action: 'Find pipeline', id: pid }) unless response.status == 200
|
131
|
+
Pipelines.new(Oj.load(response.body))
|
132
|
+
end
|
133
|
+
|
134
|
+
##
|
135
|
+
# Gets the variables for a pipeline.
|
136
|
+
#
|
137
|
+
# @author Jason Colyer
|
138
|
+
# @since 1.0.13
|
139
|
+
# @param client [Object] An instance of {Readiness::GitLab::Client}
|
140
|
+
# @param pipeline [Object] An instance of {Readiness::GitLab::Pipelines}
|
141
|
+
# @return [Hash]
|
142
|
+
# @see https://docs.gitlab.com/ee/api/pipelines.html#get-variables-of-a-pipeline GitLab API > Pipelines > Get variables of a pipeline
|
143
|
+
# @example
|
144
|
+
# require 'support_readiness'
|
145
|
+
# config = Readiness::GitLab::Configuration.new
|
146
|
+
# config.token = 'test123abc'
|
147
|
+
# client = Readiness::GitLab::Client.new(config)
|
148
|
+
# project = Readiness::GitLab::Projects.find!(client, 1083469)
|
149
|
+
# pipeline = Readiness::GitLab::Pipelines.find!(client, project, 5)
|
150
|
+
# variables = Readiness::GitLab::Pipelines.find!(client, pipeline)
|
151
|
+
# pp variables
|
152
|
+
# # => [
|
153
|
+
# {
|
154
|
+
# "key": "NAME",
|
155
|
+
# "variable_type": "env_var",
|
156
|
+
# "value": "Jason"
|
157
|
+
# }
|
158
|
+
# ]
|
159
|
+
def self.variables(client, pipeline)
|
160
|
+
response = client.connection.get "projects/#{pipeline.project_id}/pipleines/#{pipeline.iid}/variables"
|
161
|
+
handle_request_error(0, 'GitLab', response.status, { action: 'get', id: pid }) unless response.status == 200
|
162
|
+
Oj.load(response.body)
|
163
|
+
end
|
164
|
+
|
165
|
+
##
|
166
|
+
# Lists all pipeline jobs. This is a wrapper of {Jobs#list_pipeline}
|
167
|
+
#
|
168
|
+
# @author Jason Colyer
|
169
|
+
# @since 1.0.13
|
170
|
+
# @param client [Object] An instance of {Readiness::GitLab::Client}
|
171
|
+
# @param pipeline [Object] An instance of {Readiness::GitLab::Pieplines}
|
172
|
+
# @param limit [Integer] The number of pages to stop at. Using 0 means to list all.
|
173
|
+
# @param filters [Array] An array of filter Strings to use. Should be in the format of key=value
|
174
|
+
# @return [Array]
|
175
|
+
# @see https://docs.gitlab.com/ee/api/jobs.html#list-pipeline-jobs GitLab API > Jobs > List pipeline jobs
|
176
|
+
# @example
|
177
|
+
# require 'support_readiness'
|
178
|
+
# config = Readiness::GitLab::Configuration.new
|
179
|
+
# config.token = 'test123abc'
|
180
|
+
# client = Readiness::GitLab::Client.new(config)
|
181
|
+
# project = Readiness::GitLab::Projects.find!(client, 1083469)
|
182
|
+
# pipeline = Readiness::GitLab::Pipelines.find!(client, project, 2)
|
183
|
+
# jobs = Readiness::GitLab::Pipelines.jobs(client, pipeline, 2)
|
184
|
+
# puts jobs.count
|
185
|
+
# # => 187
|
186
|
+
def self.jobs(client, pipeline, limit = 0, filters = [])
|
187
|
+
Jobs.list_pipeline(client, pipeline, limit, filters)
|
188
|
+
end
|
189
|
+
end
|
190
|
+
end
|
191
|
+
end
|
@@ -385,7 +385,7 @@ module Readiness
|
|
385
385
|
# # => "alice_one"
|
386
386
|
def self.all_members(client, project, filters = [])
|
387
387
|
array = []
|
388
|
-
page =
|
388
|
+
page = 0
|
389
389
|
loop do
|
390
390
|
response = client.connection.get "projects/#{project.id}/members/all?per_page=100&page=#{page}&#{to_param_string(filters)}"
|
391
391
|
handle_request_error(0, 'GitLab', response.status) unless response.status == 200
|
@@ -505,6 +505,90 @@ module Readiness
|
|
505
505
|
handle_request_error(1, 'GitLab', response.status, { action: 'Delete badge', id: project.id }) unless response.status == 200
|
506
506
|
true
|
507
507
|
end
|
508
|
+
|
509
|
+
##
|
510
|
+
# Lists all milestones in a project.
|
511
|
+
# This method can take a long time to run depending on the parameters used.
|
512
|
+
#
|
513
|
+
# @author Jason Colyer
|
514
|
+
# @since 1.0.12
|
515
|
+
# @param client [Object] An instance of {Readiness::GitLab::Client}
|
516
|
+
# @param project [Object] An instance of {Readiness::GitLab::Projects}
|
517
|
+
# @param filters [Array] An array of filter Strings to use. Should be in the format of key=value
|
518
|
+
# @return [Array]
|
519
|
+
# @see https://docs.gitlab.com/ee/api/milestones.html#list-project-milestones GitLab API > Projects > Milestones > List project milestones
|
520
|
+
# @example
|
521
|
+
# require 'support_readiness'
|
522
|
+
# config = Readiness::GitLab::Configuration.new
|
523
|
+
# config.token = 'test123abc'
|
524
|
+
# client = Readiness::GitLab::Client.new(config)
|
525
|
+
# project = Readiness::GitLab::Projects.find!(client, 1083469)
|
526
|
+
# milestones = Readiness::GitLab::Projects.milestones(client, project)
|
527
|
+
# pp milestones.count
|
528
|
+
# # => 25
|
529
|
+
def self.milestones(client, project, filters = [])
|
530
|
+
array = []
|
531
|
+
page = 0
|
532
|
+
loop do
|
533
|
+
response = client.connection.get "projects/#{project.id}/milestones?per_page=100&page=#{page}&#{to_param_string(filters)}"
|
534
|
+
handle_request_error(0, 'GitLab', response.status) unless response.status == 200
|
535
|
+
body = Oj.load(response.body)
|
536
|
+
array += body
|
537
|
+
break if body.count < 100
|
538
|
+
|
539
|
+
page += 1
|
540
|
+
end
|
541
|
+
array
|
542
|
+
end
|
543
|
+
|
544
|
+
##
|
545
|
+
# Lists all pipelines for an object. This is a wrapper of {Pipelines#list}
|
546
|
+
#
|
547
|
+
# @author Jason Colyer
|
548
|
+
# @since 1.0.13
|
549
|
+
# @param client [Object] An instance of {Readiness::GitLab::Client}
|
550
|
+
# @param project [Object] An instance of {Readiness::GitLab::Projects}
|
551
|
+
# @param limit [Integer] The number of pages to stop at. Using 0 means to list all.
|
552
|
+
# @param filters [Array] An array of filter Strings to use. Should be in the format of key=value
|
553
|
+
# @return [Array]
|
554
|
+
# @see https://docs.gitlab.com/ee/api/pipelines.html#list-project-pipelines GitLab API > Pipelines > List project pipelines
|
555
|
+
# @example
|
556
|
+
# require 'support_readiness'
|
557
|
+
# config = Readiness::GitLab::Configuration.new
|
558
|
+
# config.token = 'test123abc'
|
559
|
+
# client = Readiness::GitLab::Client.new(config)
|
560
|
+
# project = Readiness::GitLab::Projects.find!(client, 1083469)
|
561
|
+
# pipelines = Readiness::GitLab::Projects.pipelines(client, project, 2, ["name=Check System", "status=failed"])
|
562
|
+
# puts pipelines.first.web_url
|
563
|
+
# # => "https://gitlab.com/gitlab-com/support/support-team-meta/-/pipelines/2"
|
564
|
+
def self.pipelines(client, project, limit = 0, filters = [])
|
565
|
+
Pipelines.list(client, project, limit, filters)
|
566
|
+
end
|
567
|
+
|
568
|
+
##
|
569
|
+
# Lists all project jobs. This is a wrapper of {Jobs#list_project}
|
570
|
+
#
|
571
|
+
# @author Jason Colyer
|
572
|
+
# @since 1.0.13
|
573
|
+
# @param client [Object] An instance of {Readiness::GitLab::Client}
|
574
|
+
# @param project [Object] An instance of {Readiness::GitLab::Projects}
|
575
|
+
# @param limit [Integer] The number of pages to stop at. Using 0 means to list all.
|
576
|
+
# @param filters [Array] An array of filter Strings to use. Should be in the format of key=value
|
577
|
+
# @return [Array]
|
578
|
+
# @see https://docs.gitlab.com/ee/api/jobs.html#list-project-jobs GitLab API > Jobs > List project jobs
|
579
|
+
# @example
|
580
|
+
# require 'support_readiness'
|
581
|
+
# config = Readiness::GitLab::Configuration.new
|
582
|
+
# config.token = 'test123abc'
|
583
|
+
# client = Readiness::GitLab::Client.new(config)
|
584
|
+
# project = Readiness::GitLab::Projects.find!(client, 1083469)
|
585
|
+
# pipeline = Readiness::GitLab::Pipelines.find!(client, project, 2)
|
586
|
+
# jobs = Readiness::GitLab::Pipelines.jobs(client, pipeline, 2)
|
587
|
+
# puts jobs.count
|
588
|
+
# # => 187
|
589
|
+
def self.jobs(client, project, limit = 0, filters = [])
|
590
|
+
Jobs.list_project(client, project, limit, filters)
|
591
|
+
end
|
508
592
|
end
|
509
593
|
end
|
510
594
|
end
|