From 10cc79f737bb7f0495a2bdb51ebbdb412798ad22 Mon Sep 17 00:00:00 2001 From: XiongKezhi <398682946@qq.com> Date: Fri, 28 Feb 2020 15:40:51 +0800 Subject: [PATCH 01/12] add more properties to GHCheckRun --- .../java/org/kohsuke/github/GHCheckRun.java | 103 +++++++++++++++++- .../kohsuke/github/GHEventPayloadTest.java | 24 +++- .../github/GHEventPayloadTest/check-run.json | 6 +- 3 files changed, 126 insertions(+), 7 deletions(-) diff --git a/src/main/java/org/kohsuke/github/GHCheckRun.java b/src/main/java/org/kohsuke/github/GHCheckRun.java index 72cd268652..dd90c1bdea 100644 --- a/src/main/java/org/kohsuke/github/GHCheckRun.java +++ b/src/main/java/org/kohsuke/github/GHCheckRun.java @@ -21,8 +21,18 @@ public class GHCheckRun extends GHObject { private String conclusion; private String name; private String headSha; + private String nodeId; + private String externalId; + private String startedAt; + private String completedAt; + private URL url; + private URL htmlUrl; + private URL detailsUrl; + private GHApp app; private GHPullRequest[] pullRequests; + // TODO: Add Output object, Check Suite object + GHCheckRun wrap(GHRepository owner) { this.owner = owner; this.root = owner.root; @@ -41,14 +51,30 @@ GHPullRequest[] wrap() { return pullRequests; } + /** + * Gets status of the check run. It can be one of "queue", "in_progress", or "completed" + * + * @return Status of the check run + */ public String getStatus() { return status; } + /** + * Gets conclusion of a completed check run. It can be one of "success", "failure", "neutral", "cancelled", + * "time_out", or "action_required". + * + * @return Status of the check run + */ public String getConclusion() { return conclusion; } + /** + * Gets the custom name of this check run. + * + * @return Name of the check run + */ public String getName() { return name; } @@ -62,6 +88,12 @@ public String getHeadSha() { return headSha; } + /** + * Gets the pull requests participated in this check run. + * + * @return Pull requests of this check run + */ + GHPullRequest[] getPullRequests() throws IOException { if (pullRequests != null && pullRequests.length != 0) { for (GHPullRequest singlePull : pullRequests) { @@ -72,11 +104,78 @@ GHPullRequest[] getPullRequests() throws IOException { } /** - * @deprecated This object has no HTML URL. + * 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 */ @Override public URL getHtmlUrl() { - return null; + return htmlUrl; + } + + /** + * Gets the global node id to access most objects in GitHub. + * + * @see documentation + * @return Global node id + */ + 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 api URL: https://api.github.com/[owner]/[repo-name]/check-runs/[check-run-id]. + * + * @return Api URL + **/ + @Override + public URL getUrl() { + return url; + } + + /** + * 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 detailsUrl; + } + + /** + * Gets the start time of the check run in ISO 8601 format: YYYY-MM-DDTHH:MM:SSZ. + * + * @return Timestamp of the start time + */ + public String getStartedAt() { + return startedAt; + } + + /** + * Gets the completed time of the check run in ISO 8601 format: YYYY-MM-DDTHH:MM:SSZ. + * + * @return Timestamp of the completed time + */ + public String getCompletedAt() { + return completedAt; + } + + /** + * Gets the GitHub app this check run belongs to, included in response. + * + * @retrurn GitHub App + */ + public GHApp getApp() { + return app; + } } diff --git a/src/test/java/org/kohsuke/github/GHEventPayloadTest.java b/src/test/java/org/kohsuke/github/GHEventPayloadTest.java index 80e2774f5c..e8dd75a31c 100644 --- a/src/test/java/org/kohsuke/github/GHEventPayloadTest.java +++ b/src/test/java/org/kohsuke/github/GHEventPayloadTest.java @@ -320,8 +320,28 @@ public void checkRunEvent() throws Exception { .parseEventPayload(payload.asReader(), GHEventPayload.CheckRun.class); assertThat(event.getRepository().getName(), is("Hello-World")); assertThat(event.getAction(), is("created")); - assertThat(event.getCheckRun().getName(), is("Octocoders-linter")); - assertThat(event.getCheckRun().getHeadSha(), is("ec26c3e57ca3a959ca5aad62de7213c562f8c821")); + + // Checks the deserialization of check_run + GHCheckRun checkRun = event.getCheckRun(); + assertThat(checkRun.getName(), is("Octocoders-linter")); + assertThat(checkRun.getHeadSha(), is("ec26c3e57ca3a959ca5aad62de7213c562f8c821")); + assertThat(checkRun.getStatus(), is("completed")); + assertThat(checkRun.getNodeId(), is("MDg6Q2hlY2tSdW4xMjg2MjAyMjg=")); + assertThat(checkRun.getExternalId(), is("")); + assertThat(checkRun.getStartedAt(), is("2019-05-15T15:21:12Z")); + assertThat(checkRun.getCompletedAt(), is("2019-05-15T20:22:22Z")); + assertThat(checkRun.getConclusion(), is("success")); + assertThat(checkRun.getUrl().toString(), + is("https://api.github.com/repos/Codertocat/Hello-World/check-runs/128620228")); + assertThat(checkRun.getUrl().toString(), + is("https://api.github.com/repos/Codertocat/Hello-World/check-runs/128620228")); + assertThat(checkRun.getHtmlUrl().toString(), + is("https://github.com/Codertocat/Hello-World/runs/128620228")); + assertThat(checkRun.getDetailsUrl().toString(), is("https://octocoders.io")); + assertThat(checkRun.getApp().getId(), is(29310L)); + + // Checks the deserialization of sender + assertThat(event.getSender().getId(), is(21031067L)); } } diff --git a/src/test/resources/org/kohsuke/github/GHEventPayloadTest/check-run.json b/src/test/resources/org/kohsuke/github/GHEventPayloadTest/check-run.json index 94a27da15a..960ebddc45 100644 --- a/src/test/resources/org/kohsuke/github/GHEventPayloadTest/check-run.json +++ b/src/test/resources/org/kohsuke/github/GHEventPayloadTest/check-run.json @@ -8,10 +8,10 @@ "url": "https://api.github.com/repos/Codertocat/Hello-World/check-runs/128620228", "html_url": "https://github.com/Codertocat/Hello-World/runs/128620228", "details_url": "https://octocoders.io", - "status": "queued", - "conclusion": null, + "status": "completed", + "conclusion": "success", "started_at": "2019-05-15T15:21:12Z", - "completed_at": null, + "completed_at": "2019-05-15T20:22:22Z", "output": { "title": null, "summary": null, From 05e81484f143312dbdc37fbc360573c4fe09c865 Mon Sep 17 00:00:00 2001 From: XiongKezhi <398682946@qq.com> Date: Fri, 28 Feb 2020 16:57:19 +0800 Subject: [PATCH 02/12] format code --- src/test/java/org/kohsuke/github/GHEventPayloadTest.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/test/java/org/kohsuke/github/GHEventPayloadTest.java b/src/test/java/org/kohsuke/github/GHEventPayloadTest.java index e8dd75a31c..f4b6c48489 100644 --- a/src/test/java/org/kohsuke/github/GHEventPayloadTest.java +++ b/src/test/java/org/kohsuke/github/GHEventPayloadTest.java @@ -335,8 +335,7 @@ public void checkRunEvent() throws Exception { is("https://api.github.com/repos/Codertocat/Hello-World/check-runs/128620228")); assertThat(checkRun.getUrl().toString(), is("https://api.github.com/repos/Codertocat/Hello-World/check-runs/128620228")); - assertThat(checkRun.getHtmlUrl().toString(), - is("https://github.com/Codertocat/Hello-World/runs/128620228")); + assertThat(checkRun.getHtmlUrl().toString(), is("https://github.com/Codertocat/Hello-World/runs/128620228")); assertThat(checkRun.getDetailsUrl().toString(), is("https://octocoders.io")); assertThat(checkRun.getApp().getId(), is(29310L)); From 73179c118b9a3555ec344eac085a8a1a1beeea6a Mon Sep 17 00:00:00 2001 From: Kezhi Xiong Date: Sat, 29 Feb 2020 13:19:14 +0800 Subject: [PATCH 03/12] Fixed typo in JavaDoc of getApp --- src/main/java/org/kohsuke/github/GHCheckRun.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/org/kohsuke/github/GHCheckRun.java b/src/main/java/org/kohsuke/github/GHCheckRun.java index dd90c1bdea..4276244804 100644 --- a/src/main/java/org/kohsuke/github/GHCheckRun.java +++ b/src/main/java/org/kohsuke/github/GHCheckRun.java @@ -173,7 +173,7 @@ public String getCompletedAt() { /** * Gets the GitHub app this check run belongs to, included in response. * - * @retrurn GitHub App + * @return GitHub App */ public GHApp getApp() { return app; From 2242174515548a2ac50c0bb3f7cb56f09dde2dd6 Mon Sep 17 00:00:00 2001 From: XiongKezhi <398682946@qq.com> Date: Sat, 29 Feb 2020 13:26:59 +0800 Subject: [PATCH 04/12] add Output in GHCheckRun --- .../java/org/kohsuke/github/GHCheckRun.java | 43 ++++++++++++++++++- .../kohsuke/github/GHEventPayloadTest.java | 1 + .../github/GHEventPayloadTest/check-run.json | 2 +- 3 files changed, 43 insertions(+), 3 deletions(-) diff --git a/src/main/java/org/kohsuke/github/GHCheckRun.java b/src/main/java/org/kohsuke/github/GHCheckRun.java index dd90c1bdea..997dbb24b6 100644 --- a/src/main/java/org/kohsuke/github/GHCheckRun.java +++ b/src/main/java/org/kohsuke/github/GHCheckRun.java @@ -28,10 +28,11 @@ public class GHCheckRun extends GHObject { private URL url; private URL htmlUrl; private URL detailsUrl; + private Output output; private GHApp app; private GHPullRequest[] pullRequests; - // TODO: Add Output object, Check Suite object + // TODO: Add Check Suite object GHCheckRun wrap(GHRepository owner) { this.owner = owner; @@ -173,9 +174,47 @@ public String getCompletedAt() { /** * Gets the GitHub app this check run belongs to, included in response. * - * @retrurn GitHub App + * @return GitHub App */ public GHApp getApp() { return app; } + + public Output getOutput() { + return output; + } + + /** + * Represents an output in a check run to include summary and other results. + * + * @see documentation + */ + public static class Output { + private String title; + private String summary; + private String text; + private int annotationsCount; + private URL annotationsUrl; + + public String getTitle() { + return title; + } + + public String getSummary() { + return summary; + } + + public String getText() { + return text; + } + + public int getAnnotationsCount() { + return annotationsCount; + } + + public URL getAnnotationsUrl() { + return annotationsUrl; + } + } + } diff --git a/src/test/java/org/kohsuke/github/GHEventPayloadTest.java b/src/test/java/org/kohsuke/github/GHEventPayloadTest.java index f4b6c48489..b10dbf5e2f 100644 --- a/src/test/java/org/kohsuke/github/GHEventPayloadTest.java +++ b/src/test/java/org/kohsuke/github/GHEventPayloadTest.java @@ -338,6 +338,7 @@ public void checkRunEvent() throws Exception { assertThat(checkRun.getHtmlUrl().toString(), is("https://github.com/Codertocat/Hello-World/runs/128620228")); assertThat(checkRun.getDetailsUrl().toString(), is("https://octocoders.io")); assertThat(checkRun.getApp().getId(), is(29310L)); + assertThat(checkRun.getOutput().getTitle(), is("check-run output")); // Checks the deserialization of sender assertThat(event.getSender().getId(), is(21031067L)); diff --git a/src/test/resources/org/kohsuke/github/GHEventPayloadTest/check-run.json b/src/test/resources/org/kohsuke/github/GHEventPayloadTest/check-run.json index 960ebddc45..849ef4808e 100644 --- a/src/test/resources/org/kohsuke/github/GHEventPayloadTest/check-run.json +++ b/src/test/resources/org/kohsuke/github/GHEventPayloadTest/check-run.json @@ -13,7 +13,7 @@ "started_at": "2019-05-15T15:21:12Z", "completed_at": "2019-05-15T20:22:22Z", "output": { - "title": null, + "title": "check-run output", "summary": null, "text": null, "annotations_count": 0, From 5a8f8c345bc4892331172fcacd4ccb87082e9bb7 Mon Sep 17 00:00:00 2001 From: XiongKezhi <398682946@qq.com> Date: Sat, 29 Feb 2020 18:09:25 +0800 Subject: [PATCH 05/12] parse completedAt and startedAt into Date in getters --- .../java/org/kohsuke/github/GHCheckRun.java | 21 +++++-------------- .../kohsuke/github/GHEventPayloadTest.java | 11 ++++++++-- 2 files changed, 14 insertions(+), 18 deletions(-) diff --git a/src/main/java/org/kohsuke/github/GHCheckRun.java b/src/main/java/org/kohsuke/github/GHCheckRun.java index 997dbb24b6..0d2879d62d 100644 --- a/src/main/java/org/kohsuke/github/GHCheckRun.java +++ b/src/main/java/org/kohsuke/github/GHCheckRun.java @@ -4,13 +4,13 @@ import java.io.IOException; import java.net.URL; +import java.util.Date; /** * Represents a check run. * * @see documentation */ - @SuppressFBWarnings(value = { "UWF_UNWRITTEN_FIELD", "NP_UNWRITTEN_FIELD", "URF_UNREAD_FIELD" }, justification = "JSON API") public class GHCheckRun extends GHObject { @@ -25,7 +25,6 @@ public class GHCheckRun extends GHObject { private String externalId; private String startedAt; private String completedAt; - private URL url; private URL htmlUrl; private URL detailsUrl; private Output output; @@ -134,16 +133,6 @@ public String getExternalId() { return externalId; } - /** - * Gets the api URL: https://api.github.com/[owner]/[repo-name]/check-runs/[check-run-id]. - * - * @return Api URL - **/ - @Override - public URL getUrl() { - return url; - } - /** * Gets the details URL from which to find full details of the check run on the integrator's site. * @@ -158,8 +147,8 @@ public URL getDetailsUrl() { * * @return Timestamp of the start time */ - public String getStartedAt() { - return startedAt; + public Date getStartedAt() { + return GitHubClient.parseDate(startedAt); } /** @@ -167,8 +156,8 @@ public String getStartedAt() { * * @return Timestamp of the completed time */ - public String getCompletedAt() { - return completedAt; + public Date getCompletedAt() { + return GitHubClient.parseDate(completedAt); } /** diff --git a/src/test/java/org/kohsuke/github/GHEventPayloadTest.java b/src/test/java/org/kohsuke/github/GHEventPayloadTest.java index b10dbf5e2f..83ab7a3a54 100644 --- a/src/test/java/org/kohsuke/github/GHEventPayloadTest.java +++ b/src/test/java/org/kohsuke/github/GHEventPayloadTest.java @@ -3,6 +3,9 @@ import org.junit.Rule; import org.junit.Test; +import java.text.SimpleDateFormat; +import java.util.TimeZone; + import static org.hamcrest.CoreMatchers.is; import static org.hamcrest.CoreMatchers.nullValue; import static org.hamcrest.MatcherAssert.assertThat; @@ -328,8 +331,12 @@ public void checkRunEvent() throws Exception { assertThat(checkRun.getStatus(), is("completed")); assertThat(checkRun.getNodeId(), is("MDg6Q2hlY2tSdW4xMjg2MjAyMjg=")); assertThat(checkRun.getExternalId(), is("")); - assertThat(checkRun.getStartedAt(), is("2019-05-15T15:21:12Z")); - assertThat(checkRun.getCompletedAt(), is("2019-05-15T20:22:22Z")); + + SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'"); + formatter.setTimeZone(TimeZone.getTimeZone("UTC")); + assertThat(formatter.format(checkRun.getStartedAt()), is("2019-05-15T15:21:12Z")); + assertThat(formatter.format(checkRun.getCompletedAt()), is("2019-05-15T20:22:22Z")); + assertThat(checkRun.getConclusion(), is("success")); assertThat(checkRun.getUrl().toString(), is("https://api.github.com/repos/Codertocat/Hello-World/check-runs/128620228")); From 57f947576e9b114cf60213ee7de1877509383bde Mon Sep 17 00:00:00 2001 From: Kezhi Xiong Date: Sat, 29 Feb 2020 20:15:32 +0800 Subject: [PATCH 06/12] Delete empty line in JavaDoc --- src/main/java/org/kohsuke/github/GHCheckRun.java | 1 - 1 file changed, 1 deletion(-) diff --git a/src/main/java/org/kohsuke/github/GHCheckRun.java b/src/main/java/org/kohsuke/github/GHCheckRun.java index 0d2879d62d..8491f24242 100644 --- a/src/main/java/org/kohsuke/github/GHCheckRun.java +++ b/src/main/java/org/kohsuke/github/GHCheckRun.java @@ -93,7 +93,6 @@ public String getHeadSha() { * * @return Pull requests of this check run */ - GHPullRequest[] getPullRequests() throws IOException { if (pullRequests != null && pullRequests.length != 0) { for (GHPullRequest singlePull : pullRequests) { From 10b01ca6b334b8fbbea2173d211f53bdea432fb3 Mon Sep 17 00:00:00 2001 From: XiongKezhi <398682946@qq.com> Date: Sun, 1 Mar 2020 14:01:59 +0800 Subject: [PATCH 07/12] using Date for timestamps and add more JavaDoc --- .../java/org/kohsuke/github/GHCheckRun.java | 38 +++++++++++++++++-- 1 file changed, 34 insertions(+), 4 deletions(-) diff --git a/src/main/java/org/kohsuke/github/GHCheckRun.java b/src/main/java/org/kohsuke/github/GHCheckRun.java index 8491f24242..2c95d8f9c2 100644 --- a/src/main/java/org/kohsuke/github/GHCheckRun.java +++ b/src/main/java/org/kohsuke/github/GHCheckRun.java @@ -23,8 +23,8 @@ public class GHCheckRun extends GHObject { private String headSha; private String nodeId; private String externalId; - private String startedAt; - private String completedAt; + private Date startedAt; + private Date completedAt; private URL htmlUrl; private URL detailsUrl; private Output output; @@ -147,7 +147,7 @@ public URL getDetailsUrl() { * @return Timestamp of the start time */ public Date getStartedAt() { - return GitHubClient.parseDate(startedAt); + return startedAt; } /** @@ -156,7 +156,7 @@ public Date getStartedAt() { * @return Timestamp of the completed time */ public Date getCompletedAt() { - return GitHubClient.parseDate(completedAt); + return completedAt; } /** @@ -168,6 +168,11 @@ public GHApp getApp() { return app; } + /** + * Gets an output for a check run. + * + * @return Output of a check run + */ public Output getOutput() { return output; } @@ -184,22 +189,47 @@ public static class Output { private int annotationsCount; private URL 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 annotationsUrl; } From 375417527be2134e72ce18bec0a6ff433090ac51 Mon Sep 17 00:00:00 2001 From: XiongKezhi <398682946@qq.com> Date: Sun, 1 Mar 2020 15:17:24 +0800 Subject: [PATCH 08/12] Change timestamps property back to String --- src/main/java/org/kohsuke/github/GHCheckRun.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/main/java/org/kohsuke/github/GHCheckRun.java b/src/main/java/org/kohsuke/github/GHCheckRun.java index 2c95d8f9c2..37d67d997a 100644 --- a/src/main/java/org/kohsuke/github/GHCheckRun.java +++ b/src/main/java/org/kohsuke/github/GHCheckRun.java @@ -23,8 +23,8 @@ public class GHCheckRun extends GHObject { private String headSha; private String nodeId; private String externalId; - private Date startedAt; - private Date completedAt; + private String startedAt; + private String completedAt; private URL htmlUrl; private URL detailsUrl; private Output output; @@ -147,7 +147,7 @@ public URL getDetailsUrl() { * @return Timestamp of the start time */ public Date getStartedAt() { - return startedAt; + return GitHubClient.parseDate(startedAt); } /** @@ -156,7 +156,7 @@ public Date getStartedAt() { * @return Timestamp of the completed time */ public Date getCompletedAt() { - return completedAt; + return GitHubClient.parseDate(completedAt); } /** From 16faaae19987261bcfdde2ee5eae4ee148512366 Mon Sep 17 00:00:00 2001 From: XiongKezhi <398682946@qq.com> Date: Sun, 1 Mar 2020 21:59:16 +0800 Subject: [PATCH 09/12] Add GHCheckSuite --- .../java/org/kohsuke/github/GHCheckRun.java | 12 +- .../java/org/kohsuke/github/GHCheckSuite.java | 176 ++++++++++++++ .../java/org/kohsuke/github/GHCommit.java | 37 ++- .../org/kohsuke/github/GHEventPayload.java | 41 ++++ .../kohsuke/github/GHEventPayloadTest.java | 31 +++ .../GHEventPayloadTest/check-suite.json | 225 ++++++++++++++++++ 6 files changed, 515 insertions(+), 7 deletions(-) create mode 100644 src/main/java/org/kohsuke/github/GHCheckSuite.java create mode 100644 src/test/resources/org/kohsuke/github/GHEventPayloadTest/check-suite.json diff --git a/src/main/java/org/kohsuke/github/GHCheckRun.java b/src/main/java/org/kohsuke/github/GHCheckRun.java index 37d67d997a..e32ff2e8fb 100644 --- a/src/main/java/org/kohsuke/github/GHCheckRun.java +++ b/src/main/java/org/kohsuke/github/GHCheckRun.java @@ -30,8 +30,7 @@ public class GHCheckRun extends GHObject { private Output output; private GHApp app; private GHPullRequest[] pullRequests; - - // TODO: Add Check Suite object + private GHCheckSuite checkSuite; GHCheckRun wrap(GHRepository owner) { this.owner = owner; @@ -168,6 +167,15 @@ public GHApp getApp() { return app; } + /** + * Gets the check suite this check run belongs to + * + * @return Check suite + */ + public GHCheckSuite getCheckSuite() { + return checkSuite; + } + /** * Gets an output for a check run. * diff --git a/src/main/java/org/kohsuke/github/GHCheckSuite.java b/src/main/java/org/kohsuke/github/GHCheckSuite.java new file mode 100644 index 0000000000..a96f40abde --- /dev/null +++ b/src/main/java/org/kohsuke/github/GHCheckSuite.java @@ -0,0 +1,176 @@ +package org.kohsuke.github; + +import java.io.IOException; +import java.net.URL; +import java.util.Date; + +import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; + +/** + * Represents a check suite. + * + * @see documentation + * @return global node id + */ + public String getNodeId() { + return nodeId; + } + + /** + * The head branch name the changes are on. + * + * @return head branch name + */ + public String getHeadBranch() { + return headBranch; + } + + /** + * Gets the HEAD SHA. + * + * @return sha for the HEAD commit + */ + public String getHeadSha() { + return headSha; + } + + /** + * Gets status of the check suite. It can be one of request, in_progress, or completed. + * + * @return status of the check suite + */ + public String getStatus() { + return status; + } + + /** + * Gets conclusion of a completed check suite. It can be one of success, failure, neutral, cancelled, time_out, + * action_required, or stale. The check suite will report the highest priority check run conclusion in the check + * suite's conclusion. + * + * @return conclusion of the check suite + */ + public String getConclusion() { + return conclusion; + } + + /** + * The SHA of the most recent commit on ref before the push. + * + * @return sha of a commit + */ + public Date getBefore() { + return GitHubClient.parseDate(before); + } + + /** + * The SHA of the most recent commit on ref after the push. + * + * @return sha of a commit + */ + public Date getAfter() { + return GitHubClient.parseDate(after); + } + + /** + * The quantity of check runs that had run as part of the latest push. + * + * @return sha of the most recent commit + */ + public int getLatestCheckRunsCount() { + return latestCheckRunsCount; + } + + /** + * The url used to list all the check runs belonged to this suite. + * + * @return url containing all check runs + */ + public URL getCheckRunsUrl() { + return checkRunsUrl; + } + + /** + * The commit of current head. + * + * @return head commit + */ + public GHCommit.ShortInfo getHeadCommit() { + return headCommit; + } + + /** + * Gets the GitHub app this check suite belongs to, included in response. + * + * @return GitHub App + */ + public GHApp getApp() { + return app; + } + + /** + * Gets the pull requests participated in this check suite. + * + * @return Pull requests + */ + GHPullRequest[] getPullRequests() throws IOException { + if (pullRequests != null && pullRequests.length != 0) { + for (GHPullRequest singlePull : pullRequests) { + singlePull.refresh(); + } + } + return pullRequests; + } + + /** + * Check suite doesn't have a HTML URL. + * + * @return null + */ + @Override + public URL getHtmlUrl() { + return null; + } +} \ No newline at end of file diff --git a/src/main/java/org/kohsuke/github/GHCommit.java b/src/main/java/org/kohsuke/github/GHCommit.java index 8909a9df3a..3a39a4f54f 100644 --- a/src/main/java/org/kohsuke/github/GHCommit.java +++ b/src/main/java/org/kohsuke/github/GHCommit.java @@ -5,11 +5,7 @@ import java.io.IOException; import java.net.URL; -import java.util.AbstractList; -import java.util.ArrayList; -import java.util.Collections; -import java.util.Date; -import java.util.List; +import java.util.*; /** * A commit in a repository. @@ -38,12 +34,43 @@ public static class ShortInfo { private int comment_count; + private String id; + private String timestamp; + private String treeId; + static class Tree { String sha; } private Tree tree; + /** + * Gets id of the commit, used by {@link GHCheckSuite} when a {@link GHEvent#CHECK_SUITE} comes + * + * @return id of the commit + */ + public String getId() { + return id; + } + + /** + * Gets timestamp of the commit, used by {@link GHCheckSuite} when a {@link GHEvent#CHECK_SUITE} comes + * + * @return timestamp of the commit + */ + public Date getTimestamp() { + return GitHubClient.parseDate(timestamp); + } + + /** + * Gets id of the tree, used by {@link GHCheckSuite} when a {@link GHEvent#CHECK_SUITE} comes + * + * @return id of the tree + */ + public String getTreeId() { + return treeId; + } + /** * Gets author. * diff --git a/src/main/java/org/kohsuke/github/GHEventPayload.java b/src/main/java/org/kohsuke/github/GHEventPayload.java index f3607eea39..ce9836a3e8 100644 --- a/src/main/java/org/kohsuke/github/GHEventPayload.java +++ b/src/main/java/org/kohsuke/github/GHEventPayload.java @@ -150,6 +150,47 @@ void wrapUp(GitHub root) { } } + /** + * A check suite event has been requested, rerequested or completed. + * + * @see authoritative source + */ + @SuppressFBWarnings( + value = { "UWF_UNWRITTEN_PUBLIC_OR_PROTECTED_FIELD", "UWF_UNWRITTEN_FIELD", "NP_UNWRITTEN_FIELD" }, + justification = "JSON API") + public static class CheckSuite extends GHEventPayload { + private String action; + private GHCheckSuite checkSuite; + private GHRepository repository; + + /** + * Gets action. + * + * @return the action + */ + public String getAction() { + return action; + } + + /** + * Gets the Check Suite object + * + * @return the Check Suite object + */ + public GHCheckSuite getCheckSuite() { + return checkSuite; + } + + /** + * Gets repository. + * + * @return the repository + */ + public GHRepository getRepository() { + return repository; + } + } + /** * A pull request status has changed. * diff --git a/src/test/java/org/kohsuke/github/GHEventPayloadTest.java b/src/test/java/org/kohsuke/github/GHEventPayloadTest.java index 83ab7a3a54..9184873637 100644 --- a/src/test/java/org/kohsuke/github/GHEventPayloadTest.java +++ b/src/test/java/org/kohsuke/github/GHEventPayloadTest.java @@ -345,10 +345,41 @@ public void checkRunEvent() throws Exception { assertThat(checkRun.getHtmlUrl().toString(), is("https://github.com/Codertocat/Hello-World/runs/128620228")); assertThat(checkRun.getDetailsUrl().toString(), is("https://octocoders.io")); assertThat(checkRun.getApp().getId(), is(29310L)); + assertThat(checkRun.getCheckSuite().getId(), is(118578147L)); assertThat(checkRun.getOutput().getTitle(), is("check-run output")); // Checks the deserialization of sender assertThat(event.getSender().getId(), is(21031067L)); } + @Test + @Payload("check-suite") + public void checkSuiteEvent() throws Exception { + GHEventPayload.CheckSuite event = GitHub.offline() + .parseEventPayload(payload.asReader(), GHEventPayload.CheckSuite.class); + + assertThat(event.getRepository().getName(), is("Hello-World")); + assertThat(event.getAction(), is("completed")); + assertThat(event.getSender().getId(), is(21031067L)); + + // Checks the deserialization of check_suite + GHCheckSuite checkSuite = event.getCheckSuite(); + assertThat(checkSuite.getNodeId(), is("MDEwOkNoZWNrU3VpdGUxMTg1NzgxNDc=")); + assertThat(checkSuite.getHeadBranch(), is("changes")); + assertThat(checkSuite.getHeadSha(), is("ec26c3e57ca3a959ca5aad62de7213c562f8c821")); + assertThat(checkSuite.getStatus(), is("completed")); + assertThat(checkSuite.getConclusion(), is("success")); + assertThat(checkSuite.getBefore(), is("6113728f27ae82c7b1a177c8d03f9e96e0adf246")); + assertThat(checkSuite.getAfter(), is("ec26c3e57ca3a959ca5aad62de7213c562f8c821")); + assertThat(checkSuite.getLatestCheckRunsCount(), is(1)); + assertThat(checkSuite.getCheckRunsUrl().toString(), + is("https://api.github.com/repos/Codertocat/Hello-World/check-suites/118578147/check-runs")); + assertThat(checkSuite.getHeadCommit().getMessage(), is("Update README.md")); + assertThat(checkSuite.getHeadCommit().getId(), is("ec26c3e57ca3a959ca5aad62de7213c562f8c821")); + assertThat(checkSuite.getHeadCommit().getTreeId(), is("31b122c26a97cf9af023e9ddab94a82c6e77b0ea")); + assertThat(checkSuite.getHeadCommit().getAuthor().getName(), is("Codertocat")); + assertThat(checkSuite.getHeadCommit().getCommitter().getName(), is("Codertocat")); + assertThat(checkSuite.getApp().getId(), is(29310L)); + } + } diff --git a/src/test/resources/org/kohsuke/github/GHEventPayloadTest/check-suite.json b/src/test/resources/org/kohsuke/github/GHEventPayloadTest/check-suite.json new file mode 100644 index 0000000000..4f3dfdcfe7 --- /dev/null +++ b/src/test/resources/org/kohsuke/github/GHEventPayloadTest/check-suite.json @@ -0,0 +1,225 @@ +{ + "action": "completed", + "check_suite": { + "id": 118578147, + "node_id": "MDEwOkNoZWNrU3VpdGUxMTg1NzgxNDc=", + "head_branch": "changes", + "head_sha": "ec26c3e57ca3a959ca5aad62de7213c562f8c821", + "status": "completed", + "conclusion": "success", + "url": "https://api.github.com/repos/Codertocat/Hello-World/check-suites/118578147", + "before": "6113728f27ae82c7b1a177c8d03f9e96e0adf246", + "after": "ec26c3e57ca3a959ca5aad62de7213c562f8c821", + "pull_requests": [ + { + "url": "https://api.github.com/repos/Codertocat/Hello-World/pulls/2", + "id": 279147437, + "number": 2, + "head": { + "ref": "changes", + "sha": "ec26c3e57ca3a959ca5aad62de7213c562f8c821", + "repo": { + "id": 186853002, + "url": "https://api.github.com/repos/Codertocat/Hello-World", + "name": "Hello-World" + } + }, + "base": { + "ref": "master", + "sha": "f95f852bd8fca8fcc58a9a2d6c842781e32a215e", + "repo": { + "id": 186853002, + "url": "https://api.github.com/repos/Codertocat/Hello-World", + "name": "Hello-World" + } + } + } + ], + "app": { + "id": 29310, + "node_id": "MDM6QXBwMjkzMTA=", + "owner": { + "login": "Octocoders", + "id": 38302899, + "node_id": "MDEyOk9yZ2FuaXphdGlvbjM4MzAyODk5", + "avatar_url": "https://avatars1.githubusercontent.com/u/38302899?v=4", + "gravatar_id": "", + "url": "https://api.github.com/users/Octocoders", + "html_url": "https://github.com/Octocoders", + "followers_url": "https://api.github.com/users/Octocoders/followers", + "following_url": "https://api.github.com/users/Octocoders/following{/other_user}", + "gists_url": "https://api.github.com/users/Octocoders/gists{/gist_id}", + "starred_url": "https://api.github.com/users/Octocoders/starred{/owner}{/repo}", + "subscriptions_url": "https://api.github.com/users/Octocoders/subscriptions", + "organizations_url": "https://api.github.com/users/Octocoders/orgs", + "repos_url": "https://api.github.com/users/Octocoders/repos", + "events_url": "https://api.github.com/users/Octocoders/events{/privacy}", + "received_events_url": "https://api.github.com/users/Octocoders/received_events", + "type": "Organization", + "site_admin": false + }, + "name": "octocoders-linter", + "description": "", + "external_url": "https://octocoders.io", + "html_url": "https://github.com/apps/octocoders-linter", + "created_at": "2019-04-19T19:36:24Z", + "updated_at": "2019-04-19T19:36:56Z", + "permissions": { + "administration": "write", + "checks": "write", + "contents": "write", + "deployments": "write", + "issues": "write", + "members": "write", + "metadata": "read", + "organization_administration": "write", + "organization_hooks": "write", + "organization_plan": "read", + "organization_projects": "write", + "organization_user_blocking": "write", + "pages": "write", + "pull_requests": "write", + "repository_hooks": "write", + "repository_projects": "write", + "statuses": "write", + "team_discussions": "write", + "vulnerability_alerts": "read" + }, + "events": [ + + ] + }, + "created_at": "2019-05-15T15:20:31Z", + "updated_at": "2019-05-15T15:21:14Z", + "latest_check_runs_count": 1, + "check_runs_url": "https://api.github.com/repos/Codertocat/Hello-World/check-suites/118578147/check-runs", + "head_commit": { + "id": "ec26c3e57ca3a959ca5aad62de7213c562f8c821", + "tree_id": "31b122c26a97cf9af023e9ddab94a82c6e77b0ea", + "message": "Update README.md", + "timestamp": "2019-05-15T15:20:30Z", + "author": { + "name": "Codertocat", + "email": "21031067+Codertocat@users.noreply.github.com" + }, + "committer": { + "name": "Codertocat", + "email": "21031067+Codertocat@users.noreply.github.com" + } + } + }, + "repository": { + "id": 186853002, + "node_id": "MDEwOlJlcG9zaXRvcnkxODY4NTMwMDI=", + "name": "Hello-World", + "full_name": "Codertocat/Hello-World", + "private": false, + "owner": { + "login": "Codertocat", + "id": 21031067, + "node_id": "MDQ6VXNlcjIxMDMxMDY3", + "avatar_url": "https://avatars1.githubusercontent.com/u/21031067?v=4", + "gravatar_id": "", + "url": "https://api.github.com/users/Codertocat", + "html_url": "https://github.com/Codertocat", + "followers_url": "https://api.github.com/users/Codertocat/followers", + "following_url": "https://api.github.com/users/Codertocat/following{/other_user}", + "gists_url": "https://api.github.com/users/Codertocat/gists{/gist_id}", + "starred_url": "https://api.github.com/users/Codertocat/starred{/owner}{/repo}", + "subscriptions_url": "https://api.github.com/users/Codertocat/subscriptions", + "organizations_url": "https://api.github.com/users/Codertocat/orgs", + "repos_url": "https://api.github.com/users/Codertocat/repos", + "events_url": "https://api.github.com/users/Codertocat/events{/privacy}", + "received_events_url": "https://api.github.com/users/Codertocat/received_events", + "type": "User", + "site_admin": false + }, + "html_url": "https://github.com/Codertocat/Hello-World", + "description": null, + "fork": false, + "url": "https://api.github.com/repos/Codertocat/Hello-World", + "forks_url": "https://api.github.com/repos/Codertocat/Hello-World/forks", + "keys_url": "https://api.github.com/repos/Codertocat/Hello-World/keys{/key_id}", + "collaborators_url": "https://api.github.com/repos/Codertocat/Hello-World/collaborators{/collaborator}", + "teams_url": "https://api.github.com/repos/Codertocat/Hello-World/teams", + "hooks_url": "https://api.github.com/repos/Codertocat/Hello-World/hooks", + "issue_events_url": "https://api.github.com/repos/Codertocat/Hello-World/issues/events{/number}", + "events_url": "https://api.github.com/repos/Codertocat/Hello-World/events", + "assignees_url": "https://api.github.com/repos/Codertocat/Hello-World/assignees{/user}", + "branches_url": "https://api.github.com/repos/Codertocat/Hello-World/branches{/branch}", + "tags_url": "https://api.github.com/repos/Codertocat/Hello-World/tags", + "blobs_url": "https://api.github.com/repos/Codertocat/Hello-World/git/blobs{/sha}", + "git_tags_url": "https://api.github.com/repos/Codertocat/Hello-World/git/tags{/sha}", + "git_refs_url": "https://api.github.com/repos/Codertocat/Hello-World/git/refs{/sha}", + "trees_url": "https://api.github.com/repos/Codertocat/Hello-World/git/trees{/sha}", + "statuses_url": "https://api.github.com/repos/Codertocat/Hello-World/statuses/{sha}", + "languages_url": "https://api.github.com/repos/Codertocat/Hello-World/languages", + "stargazers_url": "https://api.github.com/repos/Codertocat/Hello-World/stargazers", + "contributors_url": "https://api.github.com/repos/Codertocat/Hello-World/contributors", + "subscribers_url": "https://api.github.com/repos/Codertocat/Hello-World/subscribers", + "subscription_url": "https://api.github.com/repos/Codertocat/Hello-World/subscription", + "commits_url": "https://api.github.com/repos/Codertocat/Hello-World/commits{/sha}", + "git_commits_url": "https://api.github.com/repos/Codertocat/Hello-World/git/commits{/sha}", + "comments_url": "https://api.github.com/repos/Codertocat/Hello-World/comments{/number}", + "issue_comment_url": "https://api.github.com/repos/Codertocat/Hello-World/issues/comments{/number}", + "contents_url": "https://api.github.com/repos/Codertocat/Hello-World/contents/{+path}", + "compare_url": "https://api.github.com/repos/Codertocat/Hello-World/compare/{base}...{head}", + "merges_url": "https://api.github.com/repos/Codertocat/Hello-World/merges", + "archive_url": "https://api.github.com/repos/Codertocat/Hello-World/{archive_format}{/ref}", + "downloads_url": "https://api.github.com/repos/Codertocat/Hello-World/downloads", + "issues_url": "https://api.github.com/repos/Codertocat/Hello-World/issues{/number}", + "pulls_url": "https://api.github.com/repos/Codertocat/Hello-World/pulls{/number}", + "milestones_url": "https://api.github.com/repos/Codertocat/Hello-World/milestones{/number}", + "notifications_url": "https://api.github.com/repos/Codertocat/Hello-World/notifications{?since,all,participating}", + "labels_url": "https://api.github.com/repos/Codertocat/Hello-World/labels{/name}", + "releases_url": "https://api.github.com/repos/Codertocat/Hello-World/releases{/id}", + "deployments_url": "https://api.github.com/repos/Codertocat/Hello-World/deployments", + "created_at": "2019-05-15T15:19:25Z", + "updated_at": "2019-05-15T15:21:14Z", + "pushed_at": "2019-05-15T15:20:57Z", + "git_url": "git://github.com/Codertocat/Hello-World.git", + "ssh_url": "git@github.com:Codertocat/Hello-World.git", + "clone_url": "https://github.com/Codertocat/Hello-World.git", + "svn_url": "https://github.com/Codertocat/Hello-World", + "homepage": null, + "size": 0, + "stargazers_count": 0, + "watchers_count": 0, + "language": "Ruby", + "has_issues": true, + "has_projects": true, + "has_downloads": true, + "has_wiki": true, + "has_pages": true, + "forks_count": 0, + "mirror_url": null, + "archived": false, + "disabled": false, + "open_issues_count": 2, + "license": null, + "forks": 0, + "open_issues": 2, + "watchers": 0, + "default_branch": "master" + }, + "sender": { + "login": "Codertocat", + "id": 21031067, + "node_id": "MDQ6VXNlcjIxMDMxMDY3", + "avatar_url": "https://avatars1.githubusercontent.com/u/21031067?v=4", + "gravatar_id": "", + "url": "https://api.github.com/users/Codertocat", + "html_url": "https://github.com/Codertocat", + "followers_url": "https://api.github.com/users/Codertocat/followers", + "following_url": "https://api.github.com/users/Codertocat/following{/other_user}", + "gists_url": "https://api.github.com/users/Codertocat/gists{/gist_id}", + "starred_url": "https://api.github.com/users/Codertocat/starred{/owner}{/repo}", + "subscriptions_url": "https://api.github.com/users/Codertocat/subscriptions", + "organizations_url": "https://api.github.com/users/Codertocat/orgs", + "repos_url": "https://api.github.com/users/Codertocat/repos", + "events_url": "https://api.github.com/users/Codertocat/events{/privacy}", + "received_events_url": "https://api.github.com/users/Codertocat/received_events", + "type": "User", + "site_admin": false + } +} \ No newline at end of file From f8a8ee9b9d00f565881eda051d63b12dd22c197a Mon Sep 17 00:00:00 2001 From: XiongKezhi <398682946@qq.com> Date: Sun, 1 Mar 2020 22:14:53 +0800 Subject: [PATCH 10/12] Format code --- .../java/org/kohsuke/github/GHCheckSuite.java | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/src/main/java/org/kohsuke/github/GHCheckSuite.java b/src/main/java/org/kohsuke/github/GHCheckSuite.java index a96f40abde..a3adea9cba 100644 --- a/src/main/java/org/kohsuke/github/GHCheckSuite.java +++ b/src/main/java/org/kohsuke/github/GHCheckSuite.java @@ -1,18 +1,17 @@ package org.kohsuke.github; +import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; + import java.io.IOException; import java.net.URL; -import java.util.Date; - -import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; /** * Represents a check suite. * * @see Date: Sun, 1 Mar 2020 22:18:36 +0800 Subject: [PATCH 11/12] Fixed JavaDoc warning reported by maven site --- src/main/java/org/kohsuke/github/GHCheckSuite.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/org/kohsuke/github/GHCheckSuite.java b/src/main/java/org/kohsuke/github/GHCheckSuite.java index a3adea9cba..1b9d453879 100644 --- a/src/main/java/org/kohsuke/github/GHCheckSuite.java +++ b/src/main/java/org/kohsuke/github/GHCheckSuite.java @@ -8,7 +8,7 @@ /** * Represents a check suite. * - * @see documentation */ @SuppressFBWarnings(value = { "UWF_UNWRITTEN_FIELD", "NP_UNWRITTEN_FIELD", "URF_UNREAD_FIELD" }, justification = "JSON API") From 768f60709ffd0054b1f34c6ae94f3fb0d85e68cb Mon Sep 17 00:00:00 2001 From: XiongKezhi <398682946@qq.com> Date: Tue, 3 Mar 2020 23:45:01 +0800 Subject: [PATCH 12/12] Add Output and more tests --- .../java/org/kohsuke/github/GHCheckSuite.java | 68 ++++++++++++++++++- .../java/org/kohsuke/github/GHCommit.java | 37 ++-------- .../org/kohsuke/github/GHEventPayload.java | 2 + .../kohsuke/github/GHEventPayloadTest.java | 14 +++- 4 files changed, 85 insertions(+), 36 deletions(-) diff --git a/src/main/java/org/kohsuke/github/GHCheckSuite.java b/src/main/java/org/kohsuke/github/GHCheckSuite.java index 1b9d453879..3a0a4bb98b 100644 --- a/src/main/java/org/kohsuke/github/GHCheckSuite.java +++ b/src/main/java/org/kohsuke/github/GHCheckSuite.java @@ -4,6 +4,7 @@ import java.io.IOException; import java.net.URL; +import java.util.Date; /** * Represents a check suite. @@ -25,7 +26,7 @@ public class GHCheckSuite extends GHObject { private String after; private int latestCheckRunsCount; private URL checkRunsUrl; - private GHCommit.ShortInfo headCommit; + private HeadCommit headCommit; private GHApp app; private GHPullRequest[] pullRequests; @@ -136,7 +137,7 @@ public URL getCheckRunsUrl() { * * @return head commit */ - public GHCommit.ShortInfo getHeadCommit() { + public HeadCommit getHeadCommit() { return headCommit; } @@ -172,4 +173,67 @@ GHPullRequest[] getPullRequests() throws IOException { public URL getHtmlUrl() { return null; } + + public static class HeadCommit { + private String id; + private String treeId; + private String message; + private String timestamp; + private GitUser author; + private GitUser committer; + + /** + * Gets id of the commit, used by {@link GHCheckSuite} when a {@link GHEvent#CHECK_SUITE} comes + * + * @return id of the commit + */ + public String getId() { + return id; + } + + /** + * Gets id of the tree. + * + * @return id of the tree + */ + public String getTreeId() { + return treeId; + } + + /** + * Gets message. + * + * @return commit message. + */ + public String getMessage() { + return message; + } + + /** + * Gets timestamp of the commit. + * + * @return timestamp of the commit + */ + public Date getTimestamp() { + return GitHubClient.parseDate(timestamp); + } + + /** + * Gets author. + * + * @return the author + */ + public GitUser getAuthor() { + return author; + } + + /** + * Gets committer. + * + * @return the committer + */ + public GitUser getCommitter() { + return committer; + } + } } diff --git a/src/main/java/org/kohsuke/github/GHCommit.java b/src/main/java/org/kohsuke/github/GHCommit.java index 3a39a4f54f..8909a9df3a 100644 --- a/src/main/java/org/kohsuke/github/GHCommit.java +++ b/src/main/java/org/kohsuke/github/GHCommit.java @@ -5,7 +5,11 @@ import java.io.IOException; import java.net.URL; -import java.util.*; +import java.util.AbstractList; +import java.util.ArrayList; +import java.util.Collections; +import java.util.Date; +import java.util.List; /** * A commit in a repository. @@ -34,43 +38,12 @@ public static class ShortInfo { private int comment_count; - private String id; - private String timestamp; - private String treeId; - static class Tree { String sha; } private Tree tree; - /** - * Gets id of the commit, used by {@link GHCheckSuite} when a {@link GHEvent#CHECK_SUITE} comes - * - * @return id of the commit - */ - public String getId() { - return id; - } - - /** - * Gets timestamp of the commit, used by {@link GHCheckSuite} when a {@link GHEvent#CHECK_SUITE} comes - * - * @return timestamp of the commit - */ - public Date getTimestamp() { - return GitHubClient.parseDate(timestamp); - } - - /** - * Gets id of the tree, used by {@link GHCheckSuite} when a {@link GHEvent#CHECK_SUITE} comes - * - * @return id of the tree - */ - public String getTreeId() { - return treeId; - } - /** * Gets author. * diff --git a/src/main/java/org/kohsuke/github/GHEventPayload.java b/src/main/java/org/kohsuke/github/GHEventPayload.java index ce9836a3e8..f34eb6fc8a 100644 --- a/src/main/java/org/kohsuke/github/GHEventPayload.java +++ b/src/main/java/org/kohsuke/github/GHEventPayload.java @@ -132,6 +132,7 @@ public GHRequestedAction getRequestedAction() { * @return the repository */ public GHRepository getRepository() { + repository.root = root; return repository; } @@ -187,6 +188,7 @@ public GHCheckSuite getCheckSuite() { * @return the repository */ public GHRepository getRepository() { + repository.root = root; return repository; } } diff --git a/src/test/java/org/kohsuke/github/GHEventPayloadTest.java b/src/test/java/org/kohsuke/github/GHEventPayloadTest.java index 9184873637..a57251560e 100644 --- a/src/test/java/org/kohsuke/github/GHEventPayloadTest.java +++ b/src/test/java/org/kohsuke/github/GHEventPayloadTest.java @@ -322,6 +322,7 @@ public void checkRunEvent() throws Exception { GHEventPayload.CheckRun event = GitHub.offline() .parseEventPayload(payload.asReader(), GHEventPayload.CheckRun.class); assertThat(event.getRepository().getName(), is("Hello-World")); + assertThat(event.getRepository().getOwner().getLogin(), is("Codertocat")); assertThat(event.getAction(), is("created")); // Checks the deserialization of check_run @@ -338,8 +339,6 @@ public void checkRunEvent() throws Exception { assertThat(formatter.format(checkRun.getCompletedAt()), is("2019-05-15T20:22:22Z")); assertThat(checkRun.getConclusion(), is("success")); - assertThat(checkRun.getUrl().toString(), - is("https://api.github.com/repos/Codertocat/Hello-World/check-runs/128620228")); assertThat(checkRun.getUrl().toString(), is("https://api.github.com/repos/Codertocat/Hello-World/check-runs/128620228")); assertThat(checkRun.getHtmlUrl().toString(), is("https://github.com/Codertocat/Hello-World/runs/128620228")); @@ -347,6 +346,11 @@ public void checkRunEvent() throws Exception { assertThat(checkRun.getApp().getId(), is(29310L)); assertThat(checkRun.getCheckSuite().getId(), is(118578147L)); assertThat(checkRun.getOutput().getTitle(), is("check-run output")); + assertThat(checkRun.getOutput().getSummary(), nullValue()); + assertThat(checkRun.getOutput().getText(), nullValue()); + assertThat(checkRun.getOutput().getAnnotationsCount(), is(0)); + assertThat(checkRun.getOutput().getAnnotationsUrl().toString(), + is("https://api.github.com/repos/Codertocat/Hello-World/check-runs/128620228/annotations")); // Checks the deserialization of sender assertThat(event.getSender().getId(), is(21031067L)); @@ -359,6 +363,7 @@ public void checkSuiteEvent() throws Exception { .parseEventPayload(payload.asReader(), GHEventPayload.CheckSuite.class); assertThat(event.getRepository().getName(), is("Hello-World")); + assertThat(event.getRepository().getOwner().getLogin(), is("Codertocat")); assertThat(event.getAction(), is("completed")); assertThat(event.getSender().getId(), is(21031067L)); @@ -379,6 +384,11 @@ public void checkSuiteEvent() throws Exception { assertThat(checkSuite.getHeadCommit().getTreeId(), is("31b122c26a97cf9af023e9ddab94a82c6e77b0ea")); assertThat(checkSuite.getHeadCommit().getAuthor().getName(), is("Codertocat")); assertThat(checkSuite.getHeadCommit().getCommitter().getName(), is("Codertocat")); + + SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'"); + formatter.setTimeZone(TimeZone.getTimeZone("UTC")); + assertThat(formatter.format(checkSuite.getHeadCommit().getTimestamp()), is("2019-05-15T15:20:30Z")); + assertThat(checkSuite.getApp().getId(), is(29310L)); }