Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
7d5a39e
GHRepository.createCheckRun
jglick Mar 25, 2020
36ab2a8
Redesigned using a fluent builder idiom
jglick Mar 25, 2020
b715e0c
Reformatted
jglick Mar 25, 2020
572ff9d
I guess nullability annotations can be omitted from internal members
jglick Mar 25, 2020
c7fb390
Introduced enums
jglick Mar 25, 2020
cd7963b
Acc to https://github.com/github-api/github-api/blob/7a650132c52d40c5…
jglick Mar 25, 2020
e8b4de0
WireMock coverage
jglick Mar 25, 2020
7ae9638
Merge branch 'master' of github.com:github-api/github-api into create…
jglick Mar 25, 2020
6c41f22
Coverage of DraftImage
jglick Mar 25, 2020
03de12c
SpotBugs
jglick Mar 26, 2020
26b8082
Handle >50 annotations
jglick Mar 26, 2020
b5dc3c4
Added some Javadoc.
jglick Mar 26, 2020
d8274ac
Merge branch 'javadoc' into createCheckRun
jglick Mar 26, 2020
fd3c36a
IMHO treating Javadoc warnings as fatal makes sources less legible an…
jglick Mar 26, 2020
b4c4a05
Moving enums inside GHCheckRun
jglick Mar 26, 2020
b2c513e
Merge branch 'master' into createCheckRun
bitwiseman Mar 26, 2020
c01f3f5
NPE when there are no annotations
jglick Mar 26, 2020
c499c73
Merge branch 'master' of github.com:github-api/github-api into create…
jglick Mar 26, 2020
8b51a44
Merge branch 'createCheckRun' of github.com:jglick/github-api into cr…
jglick Mar 26, 2020
30d792d
Remove ‘Draft’ from nested data class names
jglick Mar 27, 2020
89a6664
More links to GH docs from Javadoc
jglick Mar 27, 2020
883c8cc
Merge branch 'master' of github.com:github-api/github-api into create…
jglick Mar 30, 2020
6214b6a
Regenerated WireMock metadata
jglick Mar 30, 2020
7c9397f
Switched from fluent style with .done() to accessible constructors
jglick Mar 30, 2020
82b9c05
Strengthened test a bit
jglick Mar 30, 2020
58f1fe0
createPendingCheckRun
jglick Mar 30, 2020
3ab9381
createCheckRunErrMissingConclusion
jglick Mar 30, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,10 @@
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.22.2</version>
<configuration>
<!-- SUREFIRE-1226 workaround -->
<trimStackTrace>false</trimStackTrace>
</configuration>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
Expand Down
19 changes: 16 additions & 3 deletions src/main/java/org/kohsuke/github/GHCheckRun.java
Original file line number Diff line number Diff line change
Expand Up @@ -51,24 +51,33 @@ GHPullRequest[] wrap() {
}

/**
* Gets status of the check run. It can be one of "queue", "in_progress", or "completed"
* Gets status of the check run.
*
* @return Status of the check run
* @see Status
*/
public String getStatus() {
return status;
}

public static enum Status {
QUEUED, IN_PROGRESS, COMPLETED
}

/**
* Gets conclusion of a completed check run. It can be one of "success", "failure", "neutral", "cancelled",
* "time_out", or "action_required".
* Gets conclusion of a completed check run.
*
* @return Status of the check run
* @see Conclusion
*/
public String getConclusion() {
return conclusion;
}

public static enum Conclusion {
SUCCESS, FAILURE, NEUTRAL, CANCELLED, TIMED_OUT, ACTION_REQUIRED
}

/**
* Gets the custom name of this check run.
*
Expand Down Expand Up @@ -243,4 +252,8 @@ public URL getAnnotationsUrl() {
}
}

public static enum AnnotationLevel {
NOTICE, WARNING, FAILURE
}

}
291 changes: 291 additions & 0 deletions src/main/java/org/kohsuke/github/GHCheckRunBuilder.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,291 @@
/*
* The MIT License
*
* Copyright 2020 CloudBees, Inc.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/

package org.kohsuke.github;

import com.fasterxml.jackson.annotation.JsonInclude;
import edu.umd.cs.findbugs.annotations.CheckForNull;
import edu.umd.cs.findbugs.annotations.NonNull;
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;

import java.io.IOException;
import java.util.Collections;
import java.util.Date;
import java.util.LinkedList;
import java.util.List;
import java.util.Locale;

/**
* Drafts a check run.
*
* @see GHCheckRun
* @see GHRepository#createCheckRun
* @see <a href="https://developer.github.com/v3/checks/runs/#create-a-check-run">documentation</a>
*/
@SuppressFBWarnings(value = "URF_UNREAD_FIELD", justification = "Jackson serializes these even without a getter")
@Preview
@Deprecated
public final class GHCheckRunBuilder {

private final GHRepository repo;
private final Requester requester;
private Output output;
private List<Action> actions;

GHCheckRunBuilder(GHRepository repo, String name, String headSHA) {
this.repo = repo;
requester = repo.root.createRequest()
.withPreview(Previews.ANTIOPE)
.method("POST")
.with("name", name)
.with("head_sha", headSHA)
.withUrlPath(repo.getApiTailUrl("check-runs"));
}

public @NonNull GHCheckRunBuilder withDetailsURL(@CheckForNull String detailsURL) {
requester.with("details_url", detailsURL);
return this;
}

public @NonNull GHCheckRunBuilder withExternalID(@CheckForNull String externalID) {
requester.with("external_id", externalID);
return this;
}

public @NonNull GHCheckRunBuilder withStatus(@CheckForNull GHCheckRun.Status status) {
if (status != null) {
// Do *not* use the overload taking Enum, as that s/_/-/g which would be wrong here.
requester.with("status", status.toString().toLowerCase(Locale.ROOT));
}
return this;
}

public @NonNull GHCheckRunBuilder withConclusion(@CheckForNull GHCheckRun.Conclusion conclusion) {
if (conclusion != null) {
requester.with("conclusion", conclusion.toString().toLowerCase(Locale.ROOT));
}
return this;
}

public @NonNull GHCheckRunBuilder withStartedAt(@CheckForNull Date startedAt) {
if (startedAt != null) {
requester.with("started_at", GitHubClient.printDate(startedAt));
}
return this;
}

public @NonNull GHCheckRunBuilder withCompletedAt(@CheckForNull Date completedAt) {
if (completedAt != null) {
requester.with("completed_at", GitHubClient.printDate(completedAt));
}
return this;
}

public @NonNull GHCheckRunBuilder add(@NonNull Output output) {
if (this.output != null) {
throw new IllegalStateException("cannot add Output twice");
}
this.output = output;
return this;
}

public @NonNull GHCheckRunBuilder add(@NonNull Action action) {
if (actions == null) {
actions = new LinkedList<>();
}
actions.add(action);
return this;
}

private static final int MAX_ANNOTATIONS = 50;
/**
* Actually creates the check run. (If more than fifty annotations were requested, this is done in batches.)
*
* @return the resulting run
* @throws IOException
* for the usual reasons
*/
public @NonNull GHCheckRun create() throws IOException {
List<Annotation> extraAnnotations;
if (output != null && output.annotations != null && output.annotations.size() > MAX_ANNOTATIONS) {
extraAnnotations = output.annotations.subList(MAX_ANNOTATIONS, output.annotations.size());
output.annotations = output.annotations.subList(0, MAX_ANNOTATIONS);
} else {
extraAnnotations = Collections.emptyList();
}
GHCheckRun run = requester.with("output", output).with("actions", actions).fetch(GHCheckRun.class).wrap(repo);
while (!extraAnnotations.isEmpty()) {
Output output2 = new Output(output.title, output.summary);
int i = Math.min(extraAnnotations.size(), MAX_ANNOTATIONS);
output2.annotations = extraAnnotations.subList(0, i);
extraAnnotations = extraAnnotations.subList(i, extraAnnotations.size());
run = repo.root.createRequest()
.withPreview(Previews.ANTIOPE)
.method("PATCH")
.with("output", output2)
.withUrlPath(repo.getApiTailUrl("check-runs/" + run.id))
.fetch(GHCheckRun.class)
.wrap(repo);
}
return run;
}

/**
* @see <a href="https://developer.github.com/v3/checks/runs/#output-object">documentation</a>
*/
@JsonInclude(JsonInclude.Include.NON_NULL)
public static final class Output {

private final String title;
private final String summary;
private String text;
private List<Annotation> annotations;
private List<Image> images;

public Output(@NonNull String title, @NonNull String summary) {
this.title = title;
this.summary = summary;
}

public @NonNull Output withText(@CheckForNull String text) {
this.text = text;
return this;
}

public @NonNull Output add(@NonNull Annotation annotation) {
if (annotations == null) {
annotations = new LinkedList<>();
}
annotations.add(annotation);
return this;
}

public @NonNull Output add(@NonNull Image image) {
if (images == null) {
images = new LinkedList<>();
}
images.add(image);
return this;
}

}

/**
* @see <a href="https://developer.github.com/v3/checks/runs/#annotations-object">documentation</a>
*/
@JsonInclude(JsonInclude.Include.NON_NULL)
public static final class Annotation {

private final String path;
private final int start_line;
private final int end_line;
private final String annotation_level;
private final String message;
private Integer start_column;
private Integer end_column;
private String title;
private String raw_details;

public Annotation(@NonNull String path,
int line,
@NonNull GHCheckRun.AnnotationLevel annotationLevel,
@NonNull String message) {
this(path, line, line, annotationLevel, message);
}

public Annotation(@NonNull String path,
int startLine,
int endLine,
@NonNull GHCheckRun.AnnotationLevel annotationLevel,
@NonNull String message) {
this.path = path;
start_line = startLine;
end_line = endLine;
annotation_level = annotationLevel.toString().toLowerCase(Locale.ROOT);
this.message = message;
}

public @NonNull Annotation withStartColumn(@CheckForNull Integer startColumn) {
start_column = startColumn;
return this;
}

public @NonNull Annotation withEndColumn(@CheckForNull Integer endColumn) {
end_column = endColumn;
return this;
}

public @NonNull Annotation withTitle(@CheckForNull String title) {
this.title = title;
return this;
}

public @NonNull Annotation withRawDetails(@CheckForNull String rawDetails) {
raw_details = rawDetails;
return this;
}

}

/**
* @see <a href="https://developer.github.com/v3/checks/runs/#images-object">documentation</a>
*/
@JsonInclude(JsonInclude.Include.NON_NULL)
public static final class Image {

private final String alt;
private final String image_url;
private String caption;

public Image(@NonNull String alt, @NonNull String imageURL) {
this.alt = alt;
image_url = imageURL;
}

public @NonNull Image withCaption(@CheckForNull String caption) {
this.caption = caption;
return this;
}

}

/**
* @see <a href="https://developer.github.com/v3/checks/runs/#actions-object">documentation</a>
*/
@JsonInclude(JsonInclude.Include.NON_NULL)
public static final class Action {

private final String label;
private final String description;
private final String identifier;

public Action(@NonNull String label, @NonNull String description, @NonNull String identifier) {
this.label = label;
this.description = description;
this.identifier = identifier;
}

}

}
15 changes: 15 additions & 0 deletions src/main/java/org/kohsuke/github/GHRepository.java
Original file line number Diff line number Diff line change
Expand Up @@ -1849,6 +1849,21 @@ public GHCommitStatus createCommitStatus(String sha1, GHCommitState state, Strin
return createCommitStatus(sha1, state, targetUrl, description, null);
}

/**
* Creates a check run for a commit.
*
* @param name
* an identifier for the run
* @param headSHA
* the commit hash
* @return a builder which you should customize, then call {@link GHCheckRunBuilder#create}
*/
@Preview
@Deprecated
public @NonNull GHCheckRunBuilder createCheckRun(@NonNull String name, @NonNull String headSHA) {
return new GHCheckRunBuilder(this, name, headSHA);
}

/**
* Lists repository events.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ protected void requireProxy(String reason) {

protected void verifyAuthenticated(GitHub instance) {
assertThat(
"GitHub connection believes it is anonymous. Make sure you set GITHUB_OAUTH or both GITHUB_USER and GITHUB_PASSWORD environment variables",
"GitHub connection believes it is anonymous. Make sure you set GITHUB_OAUTH or both GITHUB_LOGIN and GITHUB_PASSWORD environment variables",
instance.isAnonymous(),
Matchers.is(false));
}
Expand Down
Loading