forked from hub4j/github-api
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGHCheckRun.java
More file actions
406 lines (363 loc) · 9.9 KB
/
GHCheckRun.java
File metadata and controls
406 lines (363 loc) · 9.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
package org.kohsuke.github;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.infradna.tool.bridge_method_injector.WithBridgeMethods;
import edu.umd.cs.findbugs.annotations.NonNull;
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
import org.kohsuke.github.internal.EnumUtils;
import java.io.IOException;
import java.net.URL;
import java.time.Instant;
import java.util.Arrays;
import java.util.Collections;
import java.util.Date;
import java.util.List;
import java.util.Locale;
// TODO: Auto-generated Javadoc
/**
* Represents a check run.
*
* @see <a href="https://developer.github.com/v3/checks/runs/">documentation</a>
*/
@SuppressFBWarnings(value = { "UWF_UNWRITTEN_FIELD", "NP_UNWRITTEN_FIELD", "URF_UNREAD_FIELD" },
justification = "JSON API")
public class GHCheckRun extends GHObject {
/**
* Create default GHCheckRun instance
*/
public GHCheckRun() {
}
/** The owner. */
@JsonProperty("repository")
GHRepository owner;
private String status;
private String conclusion;
private String name;
private String headSha;
private String nodeId;
private String externalId;
private String startedAt;
private String completedAt;
private String htmlUrl;
private String detailsUrl;
private Output output;
private GHApp app;
private GHPullRequest[] pullRequests = new GHPullRequest[0];
private GHCheckSuite checkSuite;
/**
* Wrap.
*
* @param owner
* the owner
* @return the GH check run
*/
GHCheckRun wrap(GHRepository owner) {
this.owner = owner;
wrap(owner.root());
return this;
}
/**
* Wrap.
*
* @param root
* the root
* @return the GH check run
*/
GHCheckRun wrap(GitHub root) {
if (owner != null) {
for (GHPullRequest singlePull : pullRequests) {
singlePull.wrap(owner);
}
}
if (checkSuite != null) {
if (owner != null) {
checkSuite.wrap(owner);
} else {
checkSuite.wrap(root);
}
}
return this;
}
/**
* Gets status of the check run.
*
* @return Status of the check run
* @see Status
*/
public Status getStatus() {
return Status.from(status);
}
/**
* The Enum Status.
*/
public static enum Status {
/** The queued. */
QUEUED,
/** The in progress. */
IN_PROGRESS,
/** The completed. */
COMPLETED,
/** The unknown. */
UNKNOWN;
/**
* From.
*
* @param value
* the value
* @return the status
*/
public static Status from(String value) {
return EnumUtils.getNullableEnumOrDefault(Status.class, value, Status.UNKNOWN);
}
/**
* To string.
*
* @return the string
*/
@Override
public String toString() {
return name().toLowerCase(Locale.ROOT);
}
}
/**
* Gets conclusion of a completed check run.
*
* @return Status of the check run
* @see Conclusion
*/
public Conclusion getConclusion() {
return Conclusion.from(conclusion);
}
/**
* Final conclusion of the check.
*
* From <a href="https://docs.github.com/en/rest/reference/checks#create-a-check-run--parameters">Check Run
* Parameters - <code>conclusion</code></a>.
*/
public static enum Conclusion {
/** The action required. */
ACTION_REQUIRED,
/** The cancelled. */
CANCELLED,
/** The failure. */
FAILURE,
/** The neutral. */
NEUTRAL,
/** The success. */
SUCCESS,
/** The skipped. */
SKIPPED,
/** The stale. */
STALE,
/** The timed out. */
TIMED_OUT,
/** The unknown. */
UNKNOWN;
/**
* From.
*
* @param value
* the value
* @return the conclusion
*/
public static Conclusion from(String value) {
return EnumUtils.getNullableEnumOrDefault(Conclusion.class, value, Conclusion.UNKNOWN);
}
/**
* To string.
*
* @return the string
*/
@Override
public String toString() {
return name().toLowerCase(Locale.ROOT);
}
}
/**
* Gets the custom name of this check run.
*
* @return Name of the check run
*/
public String getName() {
return name;
}
/**
* Gets the HEAD SHA.
*
* @return sha for the HEAD commit
*/
public String getHeadSha() {
return headSha;
}
/**
* Gets the pull requests participated in this check run.
*
* Note this field is only populated for events. When getting a {@link GHCheckRun} outside of an event, this is
* always empty.
*
* @return the list of {@link GHPullRequest}s for this check run. Only populated for events.
* @throws IOException
* the io exception
*/
public List<GHPullRequest> getPullRequests() throws IOException {
for (GHPullRequest singlePull : pullRequests) {
// Only refresh if we haven't do so before
singlePull.refresh(singlePull.getTitle());
}
return Collections.unmodifiableList(Arrays.asList(pullRequests));
}
/**
* Gets the HTML URL: https://github.com/[owner]/[repo-name]/runs/[check-run-id], usually an GitHub Action page of
* the check run.
*
* @return HTML URL
*/
public URL getHtmlUrl() {
return GitHubClient.parseURL(htmlUrl);
}
/**
* Gets the global node id to access most objects in GitHub.
*
* @return Global node id
* @see <a href="https://developer.github.com/v4/guides/using-global-node-ids/">documentation</a>
*/
public String getNodeId() {
return nodeId;
}
/**
* Gets a reference for the check run on the integrator's system.
*
* @return Reference id
*/
public String getExternalId() {
return externalId;
}
/**
* Gets the details URL from which to find full details of the check run on the integrator's site.
*
* @return Details URL
*/
public URL getDetailsUrl() {
return GitHubClient.parseURL(detailsUrl);
}
/**
* Gets the start time of the check run in ISO 8601 format: YYYY-MM-DDTHH:MM:SSZ.
*
* @return Timestamp of the start time
*/
@WithBridgeMethods(value = Date.class, adapterMethod = "instantToDate")
public Instant getStartedAt() {
return GitHubClient.parseInstant(startedAt);
}
/**
* Gets the completed time of the check run in ISO 8601 format: YYYY-MM-DDTHH:MM:SSZ.
*
* @return Timestamp of the completed time
*/
@WithBridgeMethods(value = Date.class, adapterMethod = "instantToDate")
public Instant getCompletedAt() {
return GitHubClient.parseInstant(completedAt);
}
/**
* Gets the GitHub app this check run belongs to, included in response.
*
* @return GitHub App
*/
@SuppressFBWarnings(value = { "EI_EXPOSE_REP" }, justification = "Expected")
public GHApp getApp() {
return app;
}
/**
* Gets the check suite this check run belongs to.
*
* @return Check suite
*/
@SuppressFBWarnings(value = { "EI_EXPOSE_REP" }, justification = "Expected")
public GHCheckSuite getCheckSuite() {
return checkSuite;
}
/**
* Gets an output for a check run.
*
* @return Output of a check run
*/
@SuppressFBWarnings(value = { "EI_EXPOSE_REP" }, justification = "Expected")
public Output getOutput() {
return output;
}
/**
* Represents an output in a check run to include summary and other results.
*
* @see <a href="https://developer.github.com/v3/checks/runs/#output-object">documentation</a>
*/
public static class Output {
/**
* Create default Output instance
*/
public Output() {
}
private String title;
private String summary;
private String text;
private int annotationsCount;
private String annotationsUrl;
/**
* Gets the title of check run.
*
* @return title of check run
*/
public String getTitle() {
return title;
}
/**
* Gets the summary of the check run, note that it supports Markdown.
*
* @return summary of check run
*/
public String getSummary() {
return summary;
}
/**
* Gets the details of the check run, note that it supports Markdown.
*
* @return Details of the check run
*/
public String getText() {
return text;
}
/**
* Gets the annotation count of a check run.
*
* @return annotation count of a check run
*/
public int getAnnotationsCount() {
return annotationsCount;
}
/**
* Gets the URL of annotations.
*
* @return URL of annotations
*/
public URL getAnnotationsUrl() {
return GitHubClient.parseURL(annotationsUrl);
}
}
/**
* The Enum AnnotationLevel.
*/
public static enum AnnotationLevel {
/** The notice. */
NOTICE,
/** The warning. */
WARNING,
/** The failure. */
FAILURE
}
/**
* Updates this check run.
*
* @return a builder which you should customize, then call {@link GHCheckRunBuilder#create}
*/
public @NonNull GHCheckRunBuilder update() {
return new GHCheckRunBuilder(owner, getId());
}
}