diff --git a/src/main/java/org/kohsuke/github/GHCheckRunBuilder.java b/src/main/java/org/kohsuke/github/GHCheckRunBuilder.java index 7dfef3fc8..c542fd322 100644 --- a/src/main/java/org/kohsuke/github/GHCheckRunBuilder.java +++ b/src/main/java/org/kohsuke/github/GHCheckRunBuilder.java @@ -24,6 +24,7 @@ package org.kohsuke.github; +import com.fasterxml.jackson.annotation.JsonInclude; import edu.umd.cs.findbugs.annotations.CheckForNull; import edu.umd.cs.findbugs.annotations.NonNull; @@ -121,9 +122,10 @@ public final class GHCheckRunBuilder { .wrap(repo); } + @JsonInclude(JsonInclude.Include.NON_NULL) public static final class DraftOutput { - private final GHCheckRunBuilder builder; + private final transient GHCheckRunBuilder builder; private final String title; private final String summary; private String text; @@ -165,31 +167,12 @@ public final class GHCheckRunBuilder { return builder; } - public String getTitle() { - return title; - } - - public String getSummary() { - return summary; - } - - public String getText() { - return text; - } - - public List getAnnotations() { - return annotations; - } - - public List getImages() { - return images; - } - } + @JsonInclude(JsonInclude.Include.NON_NULL) public static final class DraftAnnotation { - private final DraftOutput output; + private final transient DraftOutput output; private final String path; private final int start_line; private final int end_line; @@ -242,47 +225,12 @@ public final class GHCheckRunBuilder { return output; } - public String getPath() { - return path; - } - - public int getStart_line() { - return start_line; - } - - public int getEnd_line() { - return end_line; - } - - public Integer getStart_column() { - return start_column; - } - - public Integer getEnd_column() { - return end_column; - } - - public String getAnnotation_level() { - return annotation_level; - } - - public String getMessage() { - return message; - } - - public String getTitle() { - return title; - } - - public String getRaw_details() { - return raw_details; - } - } + @JsonInclude(JsonInclude.Include.NON_NULL) public static final class DraftImage { - private final DraftOutput output; + private final transient DraftOutput output; private final String alt; private final String image_url; private String caption; @@ -306,20 +254,9 @@ public final class GHCheckRunBuilder { return output; } - public String getAlt() { - return alt; - } - - public String getImage_url() { - return image_url; - } - - public String getCaption() { - return caption; - } - } + @JsonInclude(JsonInclude.Include.NON_NULL) public static final class DraftAction { private final String label; @@ -332,18 +269,6 @@ public final class GHCheckRunBuilder { this.identifier = identifier; } - public String getLabel() { - return label; - } - - public String getDescription() { - return description; - } - - public String getIdentifier() { - return identifier; - } - } } diff --git a/src/test/java/org/kohsuke/github/GHCheckRunBuilderTest.java b/src/test/java/org/kohsuke/github/GHCheckRunBuilderTest.java new file mode 100644 index 000000000..697e10571 --- /dev/null +++ b/src/test/java/org/kohsuke/github/GHCheckRunBuilderTest.java @@ -0,0 +1,55 @@ +/* + * 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 org.junit.Test; + +import java.util.Date; + +@SuppressWarnings("deprecation") // preview +public class GHCheckRunBuilderTest extends AbstractGitHubWireMockTest { + + @Test + public void createCheckRun() throws Exception { + GHCheckRun checkRun = gitHub.getRepository("jglick/github-api-test") + .createCheckRun("foo", "4a929d464a2fae7ee899ce603250f7dab304bc4b") + .withStatus(GHCheckRunStatus.COMPLETED) + .withConclusion(GHCheckRunConclusion.SUCCESS) + .withDetailsURL("http://nowhere.net/stuff") + .withExternalID("whatever") + .withStartedAt(new Date(999_999_000)) + .withCompletedAt(new Date(999_999_999)) + .withOutput("Some Title", "what happened…") + .withAnnotation("stuff.txt", 1, GHCheckRunAnnotationLevel.NOTICE, "hello to you too") + .withTitle("Look here") + .done() + .done() + .withAction("Help", "what I need help with", "doit") + .create(); + assertEquals("completed", checkRun.getStatus()); + assertEquals(534940634, checkRun.id); + } + +} diff --git a/src/test/resources/org/kohsuke/github/GHCheckRunBuilderTest/wiremock/createCheckRun/__files/repos_jglick_github-api-test-8e08b9b2-ecf5-4a4f-8d06-67ad8dbf7fcd.json b/src/test/resources/org/kohsuke/github/GHCheckRunBuilderTest/wiremock/createCheckRun/__files/repos_jglick_github-api-test-8e08b9b2-ecf5-4a4f-8d06-67ad8dbf7fcd.json new file mode 100644 index 000000000..79eebcc36 --- /dev/null +++ b/src/test/resources/org/kohsuke/github/GHCheckRunBuilderTest/wiremock/createCheckRun/__files/repos_jglick_github-api-test-8e08b9b2-ecf5-4a4f-8d06-67ad8dbf7fcd.json @@ -0,0 +1,102 @@ +{ + "id": 95711947, + "node_id": "MDEwOlJlcG9zaXRvcnk5NTcxMTk0Nw==", + "name": "github-api-test", + "full_name": "jglick/github-api-test", + "private": false, + "owner": { + "login": "jglick", + "id": 154109, + "node_id": "MDQ6VXNlcjE1NDEwOQ==", + "avatar_url": "https://avatars1.githubusercontent.com/u/154109?v=4", + "gravatar_id": "", + "url": "https://api.github.com/users/jglick", + "html_url": "https://github.com/jglick", + "followers_url": "https://api.github.com/users/jglick/followers", + "following_url": "https://api.github.com/users/jglick/following{/other_user}", + "gists_url": "https://api.github.com/users/jglick/gists{/gist_id}", + "starred_url": "https://api.github.com/users/jglick/starred{/owner}{/repo}", + "subscriptions_url": "https://api.github.com/users/jglick/subscriptions", + "organizations_url": "https://api.github.com/users/jglick/orgs", + "repos_url": "https://api.github.com/users/jglick/repos", + "events_url": "https://api.github.com/users/jglick/events{/privacy}", + "received_events_url": "https://api.github.com/users/jglick/received_events", + "type": "User", + "site_admin": false + }, + "html_url": "https://github.com/jglick/github-api-test", + "description": "A test repository for testingthe github-api project", + "fork": false, + "url": "https://api.github.com/repos/jglick/github-api-test", + "forks_url": "https://api.github.com/repos/jglick/github-api-test/forks", + "keys_url": "https://api.github.com/repos/jglick/github-api-test/keys{/key_id}", + "collaborators_url": "https://api.github.com/repos/jglick/github-api-test/collaborators{/collaborator}", + "teams_url": "https://api.github.com/repos/jglick/github-api-test/teams", + "hooks_url": "https://api.github.com/repos/jglick/github-api-test/hooks", + "issue_events_url": "https://api.github.com/repos/jglick/github-api-test/issues/events{/number}", + "events_url": "https://api.github.com/repos/jglick/github-api-test/events", + "assignees_url": "https://api.github.com/repos/jglick/github-api-test/assignees{/user}", + "branches_url": "https://api.github.com/repos/jglick/github-api-test/branches{/branch}", + "tags_url": "https://api.github.com/repos/jglick/github-api-test/tags", + "blobs_url": "https://api.github.com/repos/jglick/github-api-test/git/blobs{/sha}", + "git_tags_url": "https://api.github.com/repos/jglick/github-api-test/git/tags{/sha}", + "git_refs_url": "https://api.github.com/repos/jglick/github-api-test/git/refs{/sha}", + "trees_url": "https://api.github.com/repos/jglick/github-api-test/git/trees{/sha}", + "statuses_url": "https://api.github.com/repos/jglick/github-api-test/statuses/{sha}", + "languages_url": "https://api.github.com/repos/jglick/github-api-test/languages", + "stargazers_url": "https://api.github.com/repos/jglick/github-api-test/stargazers", + "contributors_url": "https://api.github.com/repos/jglick/github-api-test/contributors", + "subscribers_url": "https://api.github.com/repos/jglick/github-api-test/subscribers", + "subscription_url": "https://api.github.com/repos/jglick/github-api-test/subscription", + "commits_url": "https://api.github.com/repos/jglick/github-api-test/commits{/sha}", + "git_commits_url": "https://api.github.com/repos/jglick/github-api-test/git/commits{/sha}", + "comments_url": "https://api.github.com/repos/jglick/github-api-test/comments{/number}", + "issue_comment_url": "https://api.github.com/repos/jglick/github-api-test/issues/comments{/number}", + "contents_url": "https://api.github.com/repos/jglick/github-api-test/contents/{+path}", + "compare_url": "https://api.github.com/repos/jglick/github-api-test/compare/{base}...{head}", + "merges_url": "https://api.github.com/repos/jglick/github-api-test/merges", + "archive_url": "https://api.github.com/repos/jglick/github-api-test/{archive_format}{/ref}", + "downloads_url": "https://api.github.com/repos/jglick/github-api-test/downloads", + "issues_url": "https://api.github.com/repos/jglick/github-api-test/issues{/number}", + "pulls_url": "https://api.github.com/repos/jglick/github-api-test/pulls{/number}", + "milestones_url": "https://api.github.com/repos/jglick/github-api-test/milestones{/number}", + "notifications_url": "https://api.github.com/repos/jglick/github-api-test/notifications{?since,all,participating}", + "labels_url": "https://api.github.com/repos/jglick/github-api-test/labels{/name}", + "releases_url": "https://api.github.com/repos/jglick/github-api-test/releases{/id}", + "deployments_url": "https://api.github.com/repos/jglick/github-api-test/deployments", + "created_at": "2017-06-28T21:10:35Z", + "updated_at": "2020-03-25T22:26:13Z", + "pushed_at": "2020-03-25T22:26:10Z", + "git_url": "git://github.com/jglick/github-api-test.git", + "ssh_url": "git@github.com:jglick/github-api-test.git", + "clone_url": "https://github.com/jglick/github-api-test.git", + "svn_url": "https://github.com/jglick/github-api-test", + "homepage": "http://github-api.kohsuke.org/", + "size": 0, + "stargazers_count": 0, + "watchers_count": 0, + "language": null, + "has_issues": true, + "has_projects": true, + "has_downloads": true, + "has_wiki": true, + "has_pages": false, + "forks_count": 0, + "mirror_url": null, + "archived": false, + "disabled": false, + "open_issues_count": 0, + "license": null, + "forks": 0, + "open_issues": 0, + "watchers": 0, + "default_branch": "master", + "permissions": { + "admin": false, + "push": false, + "pull": false + }, + "temp_clone_token": "", + "network_count": 0, + "subscribers_count": 0 +} \ No newline at end of file diff --git a/src/test/resources/org/kohsuke/github/GHCheckRunBuilderTest/wiremock/createCheckRun/__files/repos_jglick_github-api-test_check-runs-6fa5ca33-f722-4b73-804f-af9281f91d60.json b/src/test/resources/org/kohsuke/github/GHCheckRunBuilderTest/wiremock/createCheckRun/__files/repos_jglick_github-api-test_check-runs-6fa5ca33-f722-4b73-804f-af9281f91d60.json new file mode 100644 index 000000000..72b36d0df --- /dev/null +++ b/src/test/resources/org/kohsuke/github/GHCheckRunBuilderTest/wiremock/createCheckRun/__files/repos_jglick_github-api-test_check-runs-6fa5ca33-f722-4b73-804f-af9281f91d60.json @@ -0,0 +1,61 @@ +{ + "id": 534940634, + "node_id": "MDg6Q2hlY2tSdW41MzQ5NDA2MzQ=", + "head_sha": "4a929d464a2fae7ee899ce603250f7dab304bc4b", + "external_id": "whatever", + "url": "https://api.github.com/repos/jglick/github-api-test/check-runs/534940634", + "html_url": "https://github.com/jglick/github-api-test/runs/534940634", + "details_url": "http://nowhere.net/stuff", + "status": "completed", + "conclusion": "success", + "started_at": "1970-01-12T13:46:39Z", + "completed_at": "1970-01-12T13:46:39Z", + "output": { + "title": "Some Title", + "summary": "what happened…", + "text": null, + "annotations_count": 1, + "annotations_url": "https://api.github.com/repos/jglick/github-api-test/check-runs/534940634/annotations" + }, + "name": "foo", + "check_suite": { + "id": 547824747 + }, + "app": { + "id": 58691, + "slug": "jglick-app-test", + "node_id": "MDM6QXBwNTg2OTE=", + "owner": { + "login": "jglick", + "id": 154109, + "node_id": "MDQ6VXNlcjE1NDEwOQ==", + "avatar_url": "https://avatars1.githubusercontent.com/u/154109?v=4", + "gravatar_id": "", + "url": "https://api.github.com/users/jglick", + "html_url": "https://github.com/jglick", + "followers_url": "https://api.github.com/users/jglick/followers", + "following_url": "https://api.github.com/users/jglick/following{/other_user}", + "gists_url": "https://api.github.com/users/jglick/gists{/gist_id}", + "starred_url": "https://api.github.com/users/jglick/starred{/owner}{/repo}", + "subscriptions_url": "https://api.github.com/users/jglick/subscriptions", + "organizations_url": "https://api.github.com/users/jglick/orgs", + "repos_url": "https://api.github.com/users/jglick/repos", + "events_url": "https://api.github.com/users/jglick/events{/privacy}", + "received_events_url": "https://api.github.com/users/jglick/received_events", + "type": "User", + "site_admin": false + }, + "name": "jglick-app-test", + "description": "", + "external_url": "http://nowhere.net/", + "html_url": "https://github.com/apps/jglick-app-test", + "created_at": "2020-03-25T22:13:14Z", + "updated_at": "2020-03-25T22:13:14Z", + "permissions": { + "checks": "write", + "metadata": "read" + }, + "events": [] + }, + "pull_requests": [] +} \ No newline at end of file diff --git a/src/test/resources/org/kohsuke/github/GHCheckRunBuilderTest/wiremock/createCheckRun/mappings/repos_jglick_github-api-test-1-8e08b9.json b/src/test/resources/org/kohsuke/github/GHCheckRunBuilderTest/wiremock/createCheckRun/mappings/repos_jglick_github-api-test-1-8e08b9.json new file mode 100644 index 000000000..5bd03a5ce --- /dev/null +++ b/src/test/resources/org/kohsuke/github/GHCheckRunBuilderTest/wiremock/createCheckRun/mappings/repos_jglick_github-api-test-1-8e08b9.json @@ -0,0 +1,44 @@ +{ + "id": "8e08b9b2-ecf5-4a4f-8d06-67ad8dbf7fcd", + "name": "repos_jglick_github-api-test", + "request": { + "url": "/repos/jglick/github-api-test", + "method": "GET", + "headers": { + "Accept": { + "equalTo": "text/html, image/gif, image/jpeg, *; q=.2, */*; q=.2" + } + } + }, + "response": { + "status": 200, + "bodyFileName": "repos_jglick_github-api-test-8e08b9b2-ecf5-4a4f-8d06-67ad8dbf7fcd.json", + "headers": { + "Date": "Wed, 25 Mar 2020 22:56:05 GMT", + "Content-Type": "application/json; charset=utf-8", + "Server": "GitHub.com", + "Status": "200 OK", + "X-RateLimit-Limit": "5000", + "X-RateLimit-Remaining": "4986", + "X-RateLimit-Reset": "1585178837", + "Cache-Control": "private, max-age=60, s-maxage=60", + "Vary": [ + "Accept, Authorization, Cookie, X-GitHub-OTP", + "Accept-Encoding, Accept, X-Requested-With" + ], + "ETag": "W/\"749de1373b621a1b42c7900f2487dca8\"", + "Last-Modified": "Wed, 25 Mar 2020 22:26:13 GMT", + "X-GitHub-Media-Type": "unknown, github.v3", + "Strict-Transport-Security": "max-age=31536000; includeSubdomains; preload", + "X-Frame-Options": "deny", + "X-Content-Type-Options": "nosniff", + "X-XSS-Protection": "1; mode=block", + "Referrer-Policy": "origin-when-cross-origin, strict-origin-when-cross-origin", + "Content-Security-Policy": "default-src 'none'", + "X-GitHub-Request-Id": "98FE:2772:B920C:F4ED0:5E7BE185" + } + }, + "uuid": "8e08b9b2-ecf5-4a4f-8d06-67ad8dbf7fcd", + "persistent": true, + "insertionIndex": 1 +} \ No newline at end of file diff --git a/src/test/resources/org/kohsuke/github/GHCheckRunBuilderTest/wiremock/createCheckRun/mappings/repos_jglick_github-api-test_check-runs-2-6fa5ca.json b/src/test/resources/org/kohsuke/github/GHCheckRunBuilderTest/wiremock/createCheckRun/mappings/repos_jglick_github-api-test_check-runs-2-6fa5ca.json new file mode 100644 index 000000000..7b3be2577 --- /dev/null +++ b/src/test/resources/org/kohsuke/github/GHCheckRunBuilderTest/wiremock/createCheckRun/mappings/repos_jglick_github-api-test_check-runs-2-6fa5ca.json @@ -0,0 +1,51 @@ +{ + "id": "6fa5ca33-f722-4b73-804f-af9281f91d60", + "name": "repos_jglick_github-api-test_check-runs", + "request": { + "url": "/repos/jglick/github-api-test/check-runs", + "method": "POST", + "headers": { + "Accept": { + "equalTo": "application/vnd.github.antiope-preview+json" + } + }, + "bodyPatterns": [ + { + "equalToJson": "{\"conclusion\":\"success\",\"output\":{\"title\":\"Some Title\",\"summary\":\"what happened…\",\"annotations\":[{\"path\":\"stuff.txt\",\"start_line\":1,\"end_line\":1,\"annotation_level\":\"notice\",\"message\":\"hello to you too\",\"title\":\"Look here\"}]},\"completed_at\":\"1970-01-12T13:46:39Z\",\"name\":\"foo\",\"started_at\":\"1970-01-12T13:46:39Z\",\"external_id\":\"whatever\",\"details_url\":\"http://nowhere.net/stuff\",\"actions\":[{\"label\":\"Help\",\"description\":\"what I need help with\",\"identifier\":\"doit\"}],\"head_sha\":\"4a929d464a2fae7ee899ce603250f7dab304bc4b\",\"status\":\"completed\"}", + "ignoreArrayOrder": true, + "ignoreExtraElements": true + } + ] + }, + "response": { + "status": 201, + "bodyFileName": "repos_jglick_github-api-test_check-runs-6fa5ca33-f722-4b73-804f-af9281f91d60.json", + "headers": { + "Date": "Wed, 25 Mar 2020 22:56:06 GMT", + "Content-Type": "application/json; charset=utf-8", + "Server": "GitHub.com", + "Status": "201 Created", + "X-RateLimit-Limit": "5000", + "X-RateLimit-Remaining": "4985", + "X-RateLimit-Reset": "1585178838", + "Cache-Control": "private, max-age=60, s-maxage=60", + "Vary": [ + "Accept, Authorization, Cookie, X-GitHub-OTP", + "Accept-Encoding, Accept, X-Requested-With" + ], + "ETag": "\"0ab6bd53b5937bc65bb199f7b3228009\"", + "Location": "https://api.github.com/repos/jglick/github-api-test/check-runs/534940634", + "X-GitHub-Media-Type": "github.antiope-preview; format=json", + "Strict-Transport-Security": "max-age=31536000; includeSubdomains; preload", + "X-Frame-Options": "deny", + "X-Content-Type-Options": "nosniff", + "X-XSS-Protection": "1; mode=block", + "Referrer-Policy": "origin-when-cross-origin, strict-origin-when-cross-origin", + "Content-Security-Policy": "default-src 'none'", + "X-GitHub-Request-Id": "98FE:2772:B9220:F4EDA:5E7BE185" + } + }, + "uuid": "6fa5ca33-f722-4b73-804f-af9281f91d60", + "persistent": true, + "insertionIndex": 2 +} \ No newline at end of file