diff --git a/pom.xml b/pom.xml index e80f67b68a..fc0bf57de7 100644 --- a/pom.xml +++ b/pom.xml @@ -558,6 +558,12 @@ 2.8.6 test + + org.slf4j + slf4j-simple + 1.7.2 + test + diff --git a/src/main/java/org/kohsuke/github/GHEventPayload.java b/src/main/java/org/kohsuke/github/GHEventPayload.java index ef725210de..80e5a31c60 100644 --- a/src/main/java/org/kohsuke/github/GHEventPayload.java +++ b/src/main/java/org/kohsuke/github/GHEventPayload.java @@ -16,14 +16,31 @@ * and payloads */ @SuppressWarnings("UnusedDeclaration") -public abstract class GHEventPayload { +@SuppressFBWarnings("UWF_UNWRITTEN_FIELD") +public class GHEventPayload { protected GitHub root; + // https://docs.github.com/en/free-pro-team@latest/developers/webhooks-and-events/webhook-events-and-payloads#webhook-payload-object-common-properties + // Webhook payload object common properties: action, sender, repository, organization, installation + private String action; private GHUser sender; + private GHRepository repository; + private GHOrganization organization; + private GHAppInstallation installation; GHEventPayload() { } + /** + * Gets the action for the triggered event. Most but not all webhook payloads contain an action property that + * contains the specific activity that triggered the event. + * + * @return event action + */ + public String getAction() { + return action; + } + /** * Gets the sender or {@code null} if accessed via the events API. * @@ -43,11 +60,67 @@ public void setSender(GHUser sender) { this.sender = sender; } + /** + * Gets repository. + * + * @return the repository + */ + public GHRepository getRepository() { + return repository; + } + + /** + * Sets repository. + * + * @param repository + * the repository + */ + public void setRepository(GHRepository repository) { + this.repository = repository; + } + + /** + * Gets organization. + * + * @return the organization + */ + public GHOrganization getOrganization() { + return organization; + } + + /** + * Sets organization. + * + * @param organization + * the organization + */ + public void setOrganization(GHOrganization organization) { + this.organization = organization; + } + + /** + * Gets installation + * + * @return the installation + */ + public GHAppInstallation getInstallation() { + return installation; + } + void wrapUp(GitHub root) { this.root = root; if (sender != null) { sender.wrapUp(root); } + if (repository != null) { + repository.wrap(root); + } + if (organization != null) { + organization.wrapUp(root); + } + if (installation != null) { + installation.wrapUp(root); + } } // List of events that still need to be added: @@ -65,24 +138,10 @@ void wrapUp(GitHub root) { * check_run event * @see Check Runs */ - @SuppressFBWarnings( - value = { "UWF_UNWRITTEN_PUBLIC_OR_PROTECTED_FIELD", "UWF_UNWRITTEN_FIELD", "NP_UNWRITTEN_FIELD" }, - justification = "JSON API") public static class CheckRun extends GHEventPayload { - private String action; private int number; private GHCheckRun checkRun; private GHRequestedAction requestedAction; - private GHRepository repository; - - /** - * Gets action. - * - * @return the action - */ - public String getAction() { - return action; - } /** * Gets number. @@ -131,24 +190,14 @@ public GHRequestedAction getRequestedAction() { return requestedAction; } - /** - * Gets repository. - * - * @return the repository - */ - public GHRepository getRepository() { - repository.root = root; - return repository; - } - @Override void wrapUp(GitHub root) { super.wrapUp(root); if (checkRun == null) throw new IllegalStateException( "Expected check_run payload, but got something else. Maybe we've got another type of event?"); + GHRepository repository = getRepository(); if (repository != null) { - repository.wrap(root); checkRun.wrap(repository); } else { checkRun.wrap(root); @@ -163,22 +212,8 @@ void wrapUp(GitHub root) { * check_suite event * @see Check Suites */ - @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 @@ -189,24 +224,14 @@ public GHCheckSuite getCheckSuite() { return checkSuite; } - /** - * Gets repository. - * - * @return the repository - */ - public GHRepository getRepository() { - repository.root = root; - return repository; - } - @Override void wrapUp(GitHub root) { super.wrapUp(root); if (checkSuite == null) throw new IllegalStateException( "Expected check_suite payload, but got something else. Maybe we've got another type of event?"); + GHRepository repository = getRepository(); if (repository != null) { - repository.wrap(root); checkSuite.wrap(repository); } else { checkSuite.wrap(root); @@ -222,30 +247,9 @@ void wrapUp(GitHub root) { * installation event * @see GitHub App Installation */ - @SuppressFBWarnings(value = { "UWF_UNWRITTEN_FIELD" }, justification = "JSON API") public static class Installation extends GHEventPayload { - private String action; - private GHAppInstallation installation; private List repositories; - /** - * Gets action - * - * @return the action - */ - public String getAction() { - return action; - } - - /** - * Gets installation - * - * @return the installation - */ - public GHAppInstallation getInstallation() { - return installation; - } - /** * Gets repositories * @@ -258,11 +262,10 @@ public List getRepositories() { @Override void wrapUp(GitHub root) { super.wrapUp(root); - if (installation == null) + if (getInstallation() == null) { throw new IllegalStateException( "Expected check_suite payload, but got something else. Maybe we've got another type of event?"); - else - installation.wrapUp(root); + } if (repositories != null && !repositories.isEmpty()) { try { @@ -285,32 +288,11 @@ void wrapUp(GitHub root) { * installation_repositories event * @see GitHub App installation */ - @SuppressFBWarnings(value = { "UWF_UNWRITTEN_FIELD" }, justification = "JSON API") public static class InstallationRepositories extends GHEventPayload { - private String action; - private GHAppInstallation installation; private String repositorySelection; private List repositoriesAdded; private List repositoriesRemoved; - /** - * Gets action - * - * @return the action - */ - public String getAction() { - return action; - } - - /** - * Gets installation - * - * @return the installation - */ - public GHAppInstallation getInstallation() { - return installation; - } - /** * Gets installation selection * @@ -341,14 +323,13 @@ public List getRepositoriesRemoved() { @Override void wrapUp(GitHub root) { super.wrapUp(root); - if (installation == null) + if (getInstallation() == null) { throw new IllegalStateException( "Expected check_suite payload, but got something else. Maybe we've got another type of event?"); - else - installation.wrapUp(root); + } List repositories; - if ("added".equals(action)) + if ("added".equals(getAction())) repositories = repositoriesAdded; else // action == "removed" repositories = repositoriesRemoved; @@ -374,25 +355,12 @@ void wrapUp(GitHub root) { * pull_request event * @see Pull Requests */ - @SuppressFBWarnings( - value = { "UWF_UNWRITTEN_PUBLIC_OR_PROTECTED_FIELD", "UWF_UNWRITTEN_FIELD", "NP_UNWRITTEN_FIELD" }, - justification = "JSON API") + @SuppressFBWarnings(value = { "NP_UNWRITTEN_FIELD" }, justification = "JSON API") public static class PullRequest extends GHEventPayload { - private String action; private int number; - private GHPullRequest pull_request; - private GHRepository repository; + private GHPullRequest pullRequest; private GHLabel label; - /** - * Gets action. - * - * @return the action - */ - public String getAction() { - return action; - } - /** * Gets number. * @@ -408,17 +376,8 @@ public int getNumber() { * @return the pull request */ public GHPullRequest getPullRequest() { - pull_request.root = root; - return pull_request; - } - - /** - * Gets repository. - * - * @return the repository - */ - public GHRepository getRepository() { - return repository; + pullRequest.root = root; + return pullRequest; } /** @@ -433,14 +392,14 @@ public GHLabel getLabel() { @Override void wrapUp(GitHub root) { super.wrapUp(root); - if (pull_request == null) + if (pullRequest == null) throw new IllegalStateException( "Expected pull_request payload, but got something else. Maybe we've got another type of event?"); + GHRepository repository = getRepository(); if (repository != null) { - repository.wrap(root); - pull_request.wrapUp(repository); + pullRequest.wrapUp(repository); } else { - pull_request.wrapUp(root); + pullRequest.wrapUp(root); } } } @@ -454,19 +413,8 @@ void wrapUp(GitHub root) { * @see Pull Request Reviews */ public static class PullRequestReview extends GHEventPayload { - private String action; private GHPullRequestReview review; - private GHPullRequest pull_request; - private GHRepository repository; - - /** - * Gets action. - * - * @return the action - */ - public String getAction() { - return action; - } + private GHPullRequest pullRequest; /** * Gets review. @@ -483,16 +431,7 @@ public GHPullRequestReview getReview() { * @return the pull request */ public GHPullRequest getPullRequest() { - return pull_request; - } - - /** - * Gets repository. - * - * @return the repository - */ - public GHRepository getRepository() { - return repository; + return pullRequest; } @Override @@ -502,13 +441,13 @@ void wrapUp(GitHub root) { throw new IllegalStateException( "Expected pull_request_review payload, but got something else. Maybe we've got another type of event?"); - review.wrapUp(pull_request); + review.wrapUp(pullRequest); + GHRepository repository = getRepository(); if (repository != null) { - repository.wrap(root); - pull_request.wrapUp(repository); + pullRequest.wrapUp(repository); } else { - pull_request.wrapUp(root); + pullRequest.wrapUp(root); } } } @@ -522,19 +461,8 @@ void wrapUp(GitHub root) { * @see Pull Request Review Comments */ public static class PullRequestReviewComment extends GHEventPayload { - private String action; private GHPullRequestReviewComment comment; - private GHPullRequest pull_request; - private GHRepository repository; - - /** - * Gets action. - * - * @return the action - */ - public String getAction() { - return action; - } + private GHPullRequest pullRequest; /** * Gets comment. @@ -551,16 +479,7 @@ public GHPullRequestReviewComment getComment() { * @return the pull request */ public GHPullRequest getPullRequest() { - return pull_request; - } - - /** - * Gets repository. - * - * @return the repository - */ - public GHRepository getRepository() { - return repository; + return pullRequest; } @Override @@ -570,13 +489,13 @@ void wrapUp(GitHub root) { throw new IllegalStateException( "Expected pull_request_review_comment payload, but got something else. Maybe we've got another type of event?"); - comment.wrapUp(pull_request); + comment.wrapUp(pullRequest); + GHRepository repository = getRepository(); if (repository != null) { - repository.wrap(root); - pull_request.wrapUp(repository); + pullRequest.wrapUp(repository); } else { - pull_request.wrapUp(root); + pullRequest.wrapUp(root); } } } @@ -589,22 +508,8 @@ void wrapUp(GitHub root) { * issues events * @see Issues Comments */ - @SuppressFBWarnings(value = { "UWF_FIELD_NOT_INITIALIZED_IN_CONSTRUCTOR", "NP_UNWRITTEN_FIELD" }, - justification = "Constructed by JSON deserialization") public static class Issue extends GHEventPayload { - private String action; private GHIssue issue; - private GHRepository repository; - - /** - * Gets action. - * - * @return the action - */ - @SuppressFBWarnings(value = "UWF_UNWRITTEN_FIELD", justification = "Comes from JSON deserialization") - public String getAction() { - return action; - } /** * Gets issue. @@ -625,30 +530,11 @@ public void setIssue(GHIssue issue) { this.issue = issue; } - /** - * Gets repository. - * - * @return the repository - */ - public GHRepository getRepository() { - return repository; - } - - /** - * Sets repository. - * - * @param repository - * the repository - */ - public void setRepository(GHRepository repository) { - this.repository = repository; - } - @Override void wrapUp(GitHub root) { super.wrapUp(root); + GHRepository repository = getRepository(); if (repository != null) { - repository.wrap(root); issue.wrap(repository); } else { issue.wrap(root); @@ -664,23 +550,9 @@ void wrapUp(GitHub root) { * issue_comment event * @see Issue Comments */ - @SuppressFBWarnings(value = { "UWF_FIELD_NOT_INITIALIZED_IN_CONSTRUCTOR", "NP_UNWRITTEN_FIELD" }, - justification = "Constructed by JSON deserialization") public static class IssueComment extends GHEventPayload { - private String action; private GHIssueComment comment; private GHIssue issue; - private GHRepository repository; - - /** - * Gets action. - * - * @return the action - */ - @SuppressFBWarnings(value = "UWF_UNWRITTEN_FIELD", justification = "Comes from JSON deserialization") - public String getAction() { - return action; - } /** * Gets comment. @@ -720,30 +592,11 @@ public void setIssue(GHIssue issue) { this.issue = issue; } - /** - * Gets repository. - * - * @return the repository - */ - public GHRepository getRepository() { - return repository; - } - - /** - * Sets repository. - * - * @param repository - * the repository - */ - public void setRepository(GHRepository repository) { - this.repository = repository; - } - @Override void wrapUp(GitHub root) { super.wrapUp(root); + GHRepository repository = getRepository(); if (repository != null) { - repository.wrap(root); issue.wrap(repository); } else { issue.wrap(root); @@ -760,22 +613,8 @@ void wrapUp(GitHub root) { * commit comment * @see Comments */ - @SuppressFBWarnings(value = { "UWF_FIELD_NOT_INITIALIZED_IN_CONSTRUCTOR", "NP_UNWRITTEN_FIELD" }, - justification = "Constructed by JSON deserialization") public static class CommitComment extends GHEventPayload { - private String action; private GHCommitComment comment; - private GHRepository repository; - - /** - * Gets action. - * - * @return the action - */ - @SuppressFBWarnings(value = "UWF_UNWRITTEN_FIELD", justification = "Comes from JSON deserialization") - public String getAction() { - return action; - } /** * Gets comment. @@ -796,30 +635,11 @@ public void setComment(GHCommitComment comment) { this.comment = comment; } - /** - * Gets repository. - * - * @return the repository - */ - public GHRepository getRepository() { - return repository; - } - - /** - * Sets repository. - * - * @param repository - * the repository - */ - public void setRepository(GHRepository repository) { - this.repository = repository; - } - @Override void wrapUp(GitHub root) { super.wrapUp(root); + GHRepository repository = getRepository(); if (repository != null) { - repository.wrap(root); comment.wrap(repository); } } @@ -832,14 +652,11 @@ void wrapUp(GitHub root) { * create event * @see Git data */ - @SuppressFBWarnings(value = { "UWF_FIELD_NOT_INITIALIZED_IN_CONSTRUCTOR", "NP_UNWRITTEN_FIELD" }, - justification = "Constructed by JSON deserialization") public static class Create extends GHEventPayload { private String ref; private String refType; private String masterBranch; private String description; - private GHRepository repository; /** * Gets ref. @@ -880,33 +697,6 @@ public String getMasterBranch() { public String getDescription() { return description; } - - /** - * Gets repository. - * - * @return the repository - */ - public GHRepository getRepository() { - return repository; - } - - /** - * Sets repository. - * - * @param repository - * the repository - */ - public void setRepository(GHRepository repository) { - this.repository = repository; - } - - @Override - void wrapUp(GitHub root) { - super.wrapUp(root); - if (repository != null) { - repository.wrap(root); - } - } } /** @@ -916,12 +706,9 @@ void wrapUp(GitHub root) { * delete event * @see Git data */ - @SuppressFBWarnings(value = { "UWF_FIELD_NOT_INITIALIZED_IN_CONSTRUCTOR", "NP_UNWRITTEN_FIELD" }, - justification = "Constructed by JSON deserialization") public static class Delete extends GHEventPayload { private String ref; private String refType; - private GHRepository repository; /** * Gets ref. @@ -942,33 +729,6 @@ public String getRef() { public String getRefType() { return refType; } - - /** - * Gets repository. - * - * @return the repository - */ - public GHRepository getRepository() { - return repository; - } - - /** - * Sets repository. - * - * @param repository - * the repository - */ - public void setRepository(GHRepository repository) { - this.repository = repository; - } - - @Override - void wrapUp(GitHub root) { - super.wrapUp(root); - if (repository != null) { - repository.wrap(root); - } - } } /** @@ -978,11 +738,8 @@ void wrapUp(GitHub root) { * deployment event * @see Deployments */ - @SuppressFBWarnings(value = { "UWF_FIELD_NOT_INITIALIZED_IN_CONSTRUCTOR", "NP_UNWRITTEN_FIELD" }, - justification = "Constructed by JSON deserialization") public static class Deployment extends GHEventPayload { private GHDeployment deployment; - private GHRepository repository; /** * Gets deployment. @@ -1003,30 +760,11 @@ public void setDeployment(GHDeployment deployment) { this.deployment = deployment; } - /** - * Gets repository. - * - * @return the repository - */ - public GHRepository getRepository() { - return repository; - } - - /** - * Sets repository. - * - * @param repository - * the repository - */ - public void setRepository(GHRepository repository) { - this.repository = repository; - } - @Override void wrapUp(GitHub root) { super.wrapUp(root); + GHRepository repository = getRepository(); if (repository != null) { - repository.wrap(root); deployment.wrap(repository); } } @@ -1040,12 +778,9 @@ void wrapUp(GitHub root) { * deployment_status event * @see Deployments */ - @SuppressFBWarnings(value = { "UWF_FIELD_NOT_INITIALIZED_IN_CONSTRUCTOR", "NP_UNWRITTEN_FIELD" }, - justification = "Constructed by JSON deserialization") public static class DeploymentStatus extends GHEventPayload { private GHDeploymentStatus deploymentStatus; private GHDeployment deployment; - private GHRepository repository; /** * Gets deployment status. @@ -1085,30 +820,11 @@ public void setDeployment(GHDeployment deployment) { this.deployment = deployment; } - /** - * Gets repository. - * - * @return the repository - */ - public GHRepository getRepository() { - return repository; - } - - /** - * Sets repository. - * - * @param repository - * the repository - */ - public void setRepository(GHRepository repository) { - this.repository = repository; - } - @Override void wrapUp(GitHub root) { super.wrapUp(root); + GHRepository repository = getRepository(); if (repository != null) { - repository.wrap(root); deployment.wrap(repository); deploymentStatus.wrap(repository); } @@ -1122,11 +838,8 @@ void wrapUp(GitHub root) { * event * @see Forks */ - @SuppressFBWarnings(value = { "UWF_FIELD_NOT_INITIALIZED_IN_CONSTRUCTOR", "NP_UNWRITTEN_FIELD" }, - justification = "Constructed by JSON deserialization") public static class Fork extends GHEventPayload { private GHRepository forkee; - private GHRepository repository; /** * Gets forkee. @@ -1147,32 +860,10 @@ public void setForkee(GHRepository forkee) { this.forkee = forkee; } - /** - * Gets repository. - * - * @return the repository - */ - public GHRepository getRepository() { - return repository; - } - - /** - * Sets repository. - * - * @param repository - * the repository - */ - public void setRepository(GHRepository repository) { - this.repository = repository; - } - @Override void wrapUp(GitHub root) { super.wrapUp(root); forkee.wrap(root); - if (repository != null) { - repository.wrap(root); - } } } @@ -1183,56 +874,6 @@ void wrapUp(GitHub root) { * event */ public static class Ping extends GHEventPayload { - private GHRepository repository; - private GHOrganization organization; - - /** - * Sets repository. - * - * @param repository - * the repository - */ - public void setRepository(GHRepository repository) { - this.repository = repository; - } - - /** - * Gets repository. - * - * @return the repository - */ - public GHRepository getRepository() { - return repository; - } - - /** - * Gets organization. - * - * @return the organization - */ - public GHOrganization getOrganization() { - return organization; - } - - /** - * Sets organization. - * - * @param organization - * the organization - */ - public void setOrganization(GHOrganization organization) { - this.organization = organization; - } - - @Override - void wrapUp(GitHub root) { - super.wrapUp(root); - if (repository != null) - repository.wrap(root); - if (organization != null) { - organization.wrapUp(root); - } - } } @@ -1243,33 +884,6 @@ void wrapUp(GitHub root) { * public event */ public static class Public extends GHEventPayload { - private GHRepository repository; - - /** - * Sets repository. - * - * @param repository - * the repository - */ - public void setRepository(GHRepository repository) { - this.repository = repository; - } - - /** - * Gets repository. - * - * @return the repository - */ - public GHRepository getRepository() { - return repository; - } - - @Override - void wrapUp(GitHub root) { - super.wrapUp(root); - if (repository != null) - repository.wrap(root); - } } @@ -1279,16 +893,12 @@ void wrapUp(GitHub root) { * @see push * event */ - @SuppressFBWarnings( - value = { "UWF_FIELD_NOT_INITIALIZED_IN_CONSTRUCTOR", "NP_UNWRITTEN_FIELD", "UUF_UNUSED_FIELD" }, - justification = "Constructed by JSON deserialization") public static class Push extends GHEventPayload { private String head, before; private boolean created, deleted, forced; private String ref; private int size; private List commits; - private GHRepository repository; private Pusher pusher; private String compare; @@ -1370,15 +980,6 @@ public List getCommits() { return commits; } - /** - * Gets repository. - * - * @return the repository - */ - public GHRepository getRepository() { - return repository; - } - /** * Gets pusher. * @@ -1407,13 +1008,6 @@ public String getCompare() { return compare; } - @Override - void wrapUp(GitHub root) { - super.wrapUp(root); - if (repository != null) - repository.wrap(root); - } - /** * The type Pusher. */ @@ -1567,19 +1161,7 @@ public List getModified() { @SuppressFBWarnings(value = { "UWF_FIELD_NOT_INITIALIZED_IN_CONSTRUCTOR", "NP_UNWRITTEN_FIELD" }, justification = "Constructed by JSON deserialization") public static class Release extends GHEventPayload { - private String action; private GHRelease release; - private GHRepository repository; - - /** - * Gets action. - * - * @return the action - */ - @SuppressFBWarnings(value = "UWF_UNWRITTEN_FIELD", justification = "Comes from JSON deserialization") - public String getAction() { - return action; - } /** * Gets release. @@ -1599,33 +1181,6 @@ public GHRelease getRelease() { public void setRelease(GHRelease release) { this.release = release; } - - /** - * Gets repository. - * - * @return the repository - */ - public GHRepository getRepository() { - return repository; - } - - /** - * Sets repository. - * - * @param repository - * the repository - */ - public void setRepository(GHRepository repository) { - this.repository = repository; - } - - @Override - void wrapUp(GitHub root) { - super.wrapUp(root); - if (repository != null) { - repository.wrap(root); - } - } } /** @@ -1635,69 +1190,8 @@ void wrapUp(GitHub root) { * repository event * @see Repositories */ - @SuppressFBWarnings( - value = { "UWF_FIELD_NOT_INITIALIZED_IN_CONSTRUCTOR", "NP_UNWRITTEN_FIELD", "UWF_UNWRITTEN_FIELD" }, - justification = "Constructed by JSON deserialization") public static class Repository extends GHEventPayload { - private String action; - private GHRepository repository; - private GHOrganization organization; - - /** - * Gets action. - * - * @return the action - */ - public String getAction() { - return action; - } - - /** - * Sets repository. - * - * @param repository - * the repository - */ - public void setRepository(GHRepository repository) { - this.repository = repository; - } - - /** - * Gets repository. - * - * @return the repository - */ - public GHRepository getRepository() { - return repository; - } - - /** - * Gets organization. - * - * @return the organization - */ - public GHOrganization getOrganization() { - return organization; - } - - /** - * Sets organization. - * - * @param organization - * the organization - */ - public void setOrganization(GHOrganization organization) { - this.organization = organization; - } - @Override - void wrapUp(GitHub root) { - super.wrapUp(root); - repository.wrap(root); - if (organization != null) { - organization.wrapUp(root); - } - } } /** @@ -1707,13 +1201,11 @@ void wrapUp(GitHub root) { * status event * @see Repository Statuses */ - @SuppressFBWarnings(value = { "UWF_UNWRITTEN_FIELD" }, justification = "Constructed by JSON deserialization") public static class Status extends GHEventPayload { private String context; private String description; private GHCommitState state; private GHCommit commit; - private GHRepository repository; /** * Gets the status content. @@ -1771,25 +1263,6 @@ public void setCommit(GHCommit commit) { this.commit = commit; } - /** - * Gets the repository associated with the status event. - * - * @return repository - */ - public GHRepository getRepository() { - return repository; - } - - /** - * Sets the repository associated with the status event. - * - * @param repository - * repository - */ - public void setRepository(GHRepository repository) { - this.repository = repository; - } - @Override void wrapUp(GitHub root) { super.wrapUp(root); @@ -1797,8 +1270,8 @@ void wrapUp(GitHub root) { throw new IllegalStateException( "Expected status payload, but got something else. Maybe we've got another type of event?"); } + GHRepository repository = getRepository(); if (repository != null) { - repository.wrap(root); commit.wrapUp(repository); } } diff --git a/src/test/java/org/kohsuke/github/GHEventPayloadTest.java b/src/test/java/org/kohsuke/github/GHEventPayloadTest.java index 9e572a19bd..1366b79840 100644 --- a/src/test/java/org/kohsuke/github/GHEventPayloadTest.java +++ b/src/test/java/org/kohsuke/github/GHEventPayloadTest.java @@ -161,6 +161,16 @@ public void issues() throws Exception { // @Test // public void page_build() throws Exception {} + @Test + public void ping() throws Exception { + GHEventPayload.Ping event = GitHub.offline().parseEventPayload(payload.asReader(), GHEventPayload.Ping.class); + + assertThat(event.getAction(), nullValue()); + assertThat(event.getSender().getLogin(), is("seregamorph")); + assertThat(event.getRepository().getName(), is("acme-project-project")); + assertThat(event.getOrganization(), nullValue()); + } + @Test @Payload("public") public void public_() throws Exception { @@ -232,6 +242,7 @@ public void pull_request_labeled() throws Exception { assertThat(event.getPullRequest().getAdditions(), is(137)); assertThat(event.getPullRequest().getDeletions(), is(81)); assertThat(event.getPullRequest().getChangedFiles(), is(22)); + assertThat(event.getPullRequest().getLabels().iterator().next().getName(), is("Ready for Review")); assertThat(event.getRepository().getName(), is("trilogy-rest-api-framework")); assertThat(event.getRepository().getOwner().getLogin(), is("trilogy-group")); assertThat(event.getSender().getLogin(), is("schernov-xo")); @@ -240,6 +251,7 @@ public void pull_request_labeled() throws Exception { assertThat(event.getLabel().getName(), is("rest api")); assertThat(event.getLabel().getColor(), is("fef2c0")); assertThat(event.getLabel().getDescription(), is("REST API pull request")); + assertThat(event.getOrganization().getLogin(), is("trilogy-group")); } @Test @@ -395,9 +407,20 @@ public void pushToFork() throws Exception { } - // TODO implement support classes and write test - // @Test - // public void release() throws Exception {} + @Test + public void release_published() throws Exception { + GHEventPayload.Release event = GitHub.offline() + .parseEventPayload(payload.asReader(), GHEventPayload.Release.class); + + assertThat(event.getAction(), is("published")); + assertThat(event.getSender().getLogin(), is("seregamorph")); + assertThat(event.getRepository().getName(), is("company-rest-api-framework")); + assertThat(event.getOrganization().getLogin(), is("company-group")); + assertThat(event.getInstallation(), nullValue()); + assertThat(event.getRelease().getName(), is("4.2")); + assertThat(event.getRelease().getTagName(), is("rest-api-framework-4.2")); + assertThat(event.getRelease().getBody(), is("REST-269 - unique test executions (#86) Sergey Chernov")); + } @Test public void repository() throws Exception { diff --git a/src/test/resources/org/kohsuke/github/GHEventPayloadTest/ping.json b/src/test/resources/org/kohsuke/github/GHEventPayloadTest/ping.json new file mode 100644 index 0000000000..e1644b9a91 --- /dev/null +++ b/src/test/resources/org/kohsuke/github/GHEventPayloadTest/ping.json @@ -0,0 +1,149 @@ +{ + "zen": "Design for failure.", + "hook_id": 252407203, + "hook": { + "type": "Repository", + "id": 252407203, + "name": "web", + "active": true, + "events": [ + "commit_comment", + "delete", + "issue_comment", + "pull_request", + "pull_request_review", + "pull_request_review_comment", + "push" + ], + "config": { + "content_type": "json", + "insecure_ssl": "0", + "secret": "********", + "url": "https://xxx.ngrok.io/github-hook" + }, + "updated_at": "2020-09-30T11:10:00Z", + "created_at": "2020-09-30T11:10:00Z", + "url": "https://api.github.com/repos/company-group/acme-project-project/hooks/252407203", + "test_url": "https://api.github.com/repos/company-group/acme-project-project/hooks/252407203/test", + "ping_url": "https://api.github.com/repos/company-group/acme-project-project/hooks/252407203/pings", + "last_response": { + "code": null, + "status": "unused", + "message": null + } + }, + "repository": { + "id": 163490389, + "node_id": "MDEwOlJlcG9zaXRvcnkxNjM0OTAzODk=", + "name": "acme-project-project", + "full_name": "company-group/acme-project-project", + "private": true, + "owner": { + "login": "company-group", + "id": 22237814, + "node_id": "MDEyOk9yZ2FuaXphdGlvbjIyMjM3ODE0", + "avatar_url": "https://avatars1.githubusercontent.com/u/22237814?v=4", + "gravatar_id": "", + "url": "https://api.github.com/users/company-group", + "html_url": "https://github.com/company-group", + "followers_url": "https://api.github.com/users/company-group/followers", + "following_url": "https://api.github.com/users/company-group/following{/other_user}", + "gists_url": "https://api.github.com/users/company-group/gists{/gist_id}", + "starred_url": "https://api.github.com/users/company-group/starred{/owner}{/repo}", + "subscriptions_url": "https://api.github.com/users/company-group/subscriptions", + "organizations_url": "https://api.github.com/users/company-group/orgs", + "repos_url": "https://api.github.com/users/company-group/repos", + "events_url": "https://api.github.com/users/company-group/events{/privacy}", + "received_events_url": "https://api.github.com/users/company-group/received_events", + "type": "Organization", + "site_admin": false + }, + "html_url": "https://github.com/company-group/acme-project-project", + "description": "acme repository migration", + "fork": false, + "url": "https://api.github.com/repos/company-group/acme-project-project", + "forks_url": "https://api.github.com/repos/company-group/acme-project-project/forks", + "keys_url": "https://api.github.com/repos/company-group/acme-project-project/keys{/key_id}", + "collaborators_url": "https://api.github.com/repos/company-group/acme-project-project/collaborators{/collaborator}", + "teams_url": "https://api.github.com/repos/company-group/acme-project-project/teams", + "hooks_url": "https://api.github.com/repos/company-group/acme-project-project/hooks", + "issue_events_url": "https://api.github.com/repos/company-group/acme-project-project/issues/events{/number}", + "events_url": "https://api.github.com/repos/company-group/acme-project-project/events", + "assignees_url": "https://api.github.com/repos/company-group/acme-project-project/assignees{/user}", + "branches_url": "https://api.github.com/repos/company-group/acme-project-project/branches{/branch}", + "tags_url": "https://api.github.com/repos/company-group/acme-project-project/tags", + "blobs_url": "https://api.github.com/repos/company-group/acme-project-project/git/blobs{/sha}", + "git_tags_url": "https://api.github.com/repos/company-group/acme-project-project/git/tags{/sha}", + "git_refs_url": "https://api.github.com/repos/company-group/acme-project-project/git/refs{/sha}", + "trees_url": "https://api.github.com/repos/company-group/acme-project-project/git/trees{/sha}", + "statuses_url": "https://api.github.com/repos/company-group/acme-project-project/statuses/{sha}", + "languages_url": "https://api.github.com/repos/company-group/acme-project-project/languages", + "stargazers_url": "https://api.github.com/repos/company-group/acme-project-project/stargazers", + "contributors_url": "https://api.github.com/repos/company-group/acme-project-project/contributors", + "subscribers_url": "https://api.github.com/repos/company-group/acme-project-project/subscribers", + "subscription_url": "https://api.github.com/repos/company-group/acme-project-project/subscription", + "commits_url": "https://api.github.com/repos/company-group/acme-project-project/commits{/sha}", + "git_commits_url": "https://api.github.com/repos/company-group/acme-project-project/git/commits{/sha}", + "comments_url": "https://api.github.com/repos/company-group/acme-project-project/comments{/number}", + "issue_comment_url": "https://api.github.com/repos/company-group/acme-project-project/issues/comments{/number}", + "contents_url": "https://api.github.com/repos/company-group/acme-project-project/contents/{+path}", + "compare_url": "https://api.github.com/repos/company-group/acme-project-project/compare/{base}...{head}", + "merges_url": "https://api.github.com/repos/company-group/acme-project-project/merges", + "archive_url": "https://api.github.com/repos/company-group/acme-project-project/{archive_format}{/ref}", + "downloads_url": "https://api.github.com/repos/company-group/acme-project-project/downloads", + "issues_url": "https://api.github.com/repos/company-group/acme-project-project/issues{/number}", + "pulls_url": "https://api.github.com/repos/company-group/acme-project-project/pulls{/number}", + "milestones_url": "https://api.github.com/repos/company-group/acme-project-project/milestones{/number}", + "notifications_url": "https://api.github.com/repos/company-group/acme-project-project/notifications{?since,all,participating}", + "labels_url": "https://api.github.com/repos/company-group/acme-project-project/labels{/name}", + "releases_url": "https://api.github.com/repos/company-group/acme-project-project/releases{/id}", + "deployments_url": "https://api.github.com/repos/company-group/acme-project-project/deployments", + "created_at": "2018-12-29T07:58:19Z", + "updated_at": "2020-09-30T11:00:24Z", + "pushed_at": "2020-09-30T11:02:42Z", + "git_url": "git://github.com/company-group/acme-project-project.git", + "ssh_url": "git@github.com:company-group/acme-project-project.git", + "clone_url": "https://github.com/company-group/acme-project-project.git", + "svn_url": "https://github.com/company-group/acme-project-project", + "homepage": null, + "size": 929299, + "stargazers_count": 0, + "watchers_count": 0, + "language": "Java", + "has_issues": true, + "has_projects": true, + "has_downloads": true, + "has_wiki": true, + "has_pages": false, + "forks_count": 1, + "mirror_url": null, + "archived": false, + "disabled": false, + "open_issues_count": 221, + "license": null, + "forks": 1, + "open_issues": 221, + "watchers": 0, + "default_branch": "develop" + }, + "sender": { + "login": "seregamorph", + "id": 2844909, + "node_id": "MDQ6VXNlcjI2ODU3NjU2", + "avatar_url": "https://avatars3.githubusercontent.com/u/2844909?v=4", + "gravatar_id": "", + "url": "https://api.github.com/users/seregamorph", + "html_url": "https://github.com/seregamorph", + "followers_url": "https://api.github.com/users/seregamorph/followers", + "following_url": "https://api.github.com/users/seregamorph/following{/other_user}", + "gists_url": "https://api.github.com/users/seregamorph/gists{/gist_id}", + "starred_url": "https://api.github.com/users/seregamorph/starred{/owner}{/repo}", + "subscriptions_url": "https://api.github.com/users/seregamorph/subscriptions", + "organizations_url": "https://api.github.com/users/seregamorph/orgs", + "repos_url": "https://api.github.com/users/seregamorph/repos", + "events_url": "https://api.github.com/users/seregamorph/events{/privacy}", + "received_events_url": "https://api.github.com/users/seregamorph/received_events", + "type": "User", + "site_admin": false + } +} \ No newline at end of file diff --git a/src/test/resources/org/kohsuke/github/GHEventPayloadTest/release_published.json b/src/test/resources/org/kohsuke/github/GHEventPayloadTest/release_published.json new file mode 100644 index 0000000000..27272b3517 --- /dev/null +++ b/src/test/resources/org/kohsuke/github/GHEventPayloadTest/release_published.json @@ -0,0 +1,170 @@ +{ + "action": "published", + "release": { + "url": "https://api.github.com/repos/company-group/company-rest-api-framework/releases/33406054", + "assets_url": "https://api.github.com/repos/company-group/company-rest-api-framework/releases/33406054/assets", + "upload_url": "https://uploads.github.com/repos/company-group/company-rest-api-framework/releases/33406054/assets{?name,label}", + "html_url": "https://github.com/company-group/company-rest-api-framework/releases/tag/rest-api-framework-4.2", + "id": 33406054, + "node_id": "MDc6UmVsZWFzZTMzNDA2MDU0", + "tag_name": "rest-api-framework-4.2", + "target_commitish": "develop", + "name": "4.2", + "draft": false, + "author": { + "login": "seregamorph", + "id": 2844909, + "node_id": "MDQ6VXNlcjE2NjAxNjgz", + "avatar_url": "https://avatars2.githubusercontent.com/u/2844909?v=4", + "gravatar_id": "", + "url": "https://api.github.com/users/seregamorph", + "html_url": "https://github.com/seregamorph", + "followers_url": "https://api.github.com/users/seregamorph/followers", + "following_url": "https://api.github.com/users/seregamorph/following{/other_user}", + "gists_url": "https://api.github.com/users/seregamorph/gists{/gist_id}", + "starred_url": "https://api.github.com/users/seregamorph/starred{/owner}{/repo}", + "subscriptions_url": "https://api.github.com/users/seregamorph/subscriptions", + "organizations_url": "https://api.github.com/users/seregamorph/orgs", + "repos_url": "https://api.github.com/users/seregamorph/repos", + "events_url": "https://api.github.com/users/seregamorph/events{/privacy}", + "received_events_url": "https://api.github.com/users/seregamorph/received_events", + "type": "User", + "site_admin": false + }, + "prerelease": false, + "created_at": "2020-11-03T10:08:12Z", + "published_at": "2020-11-03T14:33:30Z", + "assets": [], + "tarball_url": "https://api.github.com/repos/company-group/company-rest-api-framework/tarball/rest-api-framework-4.2", + "zipball_url": "https://api.github.com/repos/company-group/company-rest-api-framework/zipball/rest-api-framework-4.2", + "body": "REST-269 - unique test executions (#86) Sergey Chernov" + }, + "repository": { + "id": 217940615, + "node_id": "MDEwOlJlcG9zaXRvcnkyMTc5NDA2MTU=", + "name": "company-rest-api-framework", + "full_name": "company-group/company-rest-api-framework", + "private": true, + "owner": { + "login": "company-group", + "id": 22237814, + "node_id": "MDEyOk9yZ2FuaXphdGlvbjIyMjM3ODE0", + "avatar_url": "https://avatars1.githubusercontent.com/u/22237814?v=4", + "gravatar_id": "", + "url": "https://api.github.com/users/company-group", + "html_url": "https://github.com/company-group", + "followers_url": "https://api.github.com/users/company-group/followers", + "following_url": "https://api.github.com/users/company-group/following{/other_user}", + "gists_url": "https://api.github.com/users/company-group/gists{/gist_id}", + "starred_url": "https://api.github.com/users/company-group/starred{/owner}{/repo}", + "subscriptions_url": "https://api.github.com/users/company-group/subscriptions", + "organizations_url": "https://api.github.com/users/company-group/orgs", + "repos_url": "https://api.github.com/users/company-group/repos", + "events_url": "https://api.github.com/users/company-group/events{/privacy}", + "received_events_url": "https://api.github.com/users/company-group/received_events", + "type": "Organization", + "site_admin": false + }, + "html_url": "https://github.com/company-group/company-rest-api-framework", + "description": "https://confluence.example.com/display/REST/Framework", + "fork": false, + "url": "https://api.github.com/repos/company-group/company-rest-api-framework", + "forks_url": "https://api.github.com/repos/company-group/company-rest-api-framework/forks", + "keys_url": "https://api.github.com/repos/company-group/company-rest-api-framework/keys{/key_id}", + "collaborators_url": "https://api.github.com/repos/company-group/company-rest-api-framework/collaborators{/collaborator}", + "teams_url": "https://api.github.com/repos/company-group/company-rest-api-framework/teams", + "hooks_url": "https://api.github.com/repos/company-group/company-rest-api-framework/hooks", + "issue_events_url": "https://api.github.com/repos/company-group/company-rest-api-framework/issues/events{/number}", + "events_url": "https://api.github.com/repos/company-group/company-rest-api-framework/events", + "assignees_url": "https://api.github.com/repos/company-group/company-rest-api-framework/assignees{/user}", + "branches_url": "https://api.github.com/repos/company-group/company-rest-api-framework/branches{/branch}", + "tags_url": "https://api.github.com/repos/company-group/company-rest-api-framework/tags", + "blobs_url": "https://api.github.com/repos/company-group/company-rest-api-framework/git/blobs{/sha}", + "git_tags_url": "https://api.github.com/repos/company-group/company-rest-api-framework/git/tags{/sha}", + "git_refs_url": "https://api.github.com/repos/company-group/company-rest-api-framework/git/refs{/sha}", + "trees_url": "https://api.github.com/repos/company-group/company-rest-api-framework/git/trees{/sha}", + "statuses_url": "https://api.github.com/repos/company-group/company-rest-api-framework/statuses/{sha}", + "languages_url": "https://api.github.com/repos/company-group/company-rest-api-framework/languages", + "stargazers_url": "https://api.github.com/repos/company-group/company-rest-api-framework/stargazers", + "contributors_url": "https://api.github.com/repos/company-group/company-rest-api-framework/contributors", + "subscribers_url": "https://api.github.com/repos/company-group/company-rest-api-framework/subscribers", + "subscription_url": "https://api.github.com/repos/company-group/company-rest-api-framework/subscription", + "commits_url": "https://api.github.com/repos/company-group/company-rest-api-framework/commits{/sha}", + "git_commits_url": "https://api.github.com/repos/company-group/company-rest-api-framework/git/commits{/sha}", + "comments_url": "https://api.github.com/repos/company-group/company-rest-api-framework/comments{/number}", + "issue_comment_url": "https://api.github.com/repos/company-group/company-rest-api-framework/issues/comments{/number}", + "contents_url": "https://api.github.com/repos/company-group/company-rest-api-framework/contents/{+path}", + "compare_url": "https://api.github.com/repos/company-group/company-rest-api-framework/compare/{base}...{head}", + "merges_url": "https://api.github.com/repos/company-group/company-rest-api-framework/merges", + "archive_url": "https://api.github.com/repos/company-group/company-rest-api-framework/{archive_format}{/ref}", + "downloads_url": "https://api.github.com/repos/company-group/company-rest-api-framework/downloads", + "issues_url": "https://api.github.com/repos/company-group/company-rest-api-framework/issues{/number}", + "pulls_url": "https://api.github.com/repos/company-group/company-rest-api-framework/pulls{/number}", + "milestones_url": "https://api.github.com/repos/company-group/company-rest-api-framework/milestones{/number}", + "notifications_url": "https://api.github.com/repos/company-group/company-rest-api-framework/notifications{?since,all,participating}", + "labels_url": "https://api.github.com/repos/company-group/company-rest-api-framework/labels{/name}", + "releases_url": "https://api.github.com/repos/company-group/company-rest-api-framework/releases{/id}", + "deployments_url": "https://api.github.com/repos/company-group/company-rest-api-framework/deployments", + "created_at": "2019-10-28T01:12:50Z", + "updated_at": "2020-11-03T10:08:22Z", + "pushed_at": "2020-11-03T10:09:54Z", + "git_url": "git://github.com/company-group/company-rest-api-framework.git", + "ssh_url": "git@github.com:company-group/company-rest-api-framework.git", + "clone_url": "https://github.com/company-group/company-rest-api-framework.git", + "svn_url": "https://github.com/company-group/company-rest-api-framework", + "homepage": "", + "size": 916, + "stargazers_count": 2, + "watchers_count": 2, + "language": "Java", + "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": 2, + "default_branch": "develop" + }, + "organization": { + "login": "company-group", + "id": 22237814, + "node_id": "MDEyOk9yZ2FuaXphdGlvbjIyMjM3ODE0", + "url": "https://api.github.com/orgs/company-group", + "repos_url": "https://api.github.com/orgs/company-group/repos", + "events_url": "https://api.github.com/orgs/company-group/events", + "hooks_url": "https://api.github.com/orgs/company-group/hooks", + "issues_url": "https://api.github.com/orgs/company-group/issues", + "members_url": "https://api.github.com/orgs/company-group/members{/member}", + "public_members_url": "https://api.github.com/orgs/company-group/public_members{/member}", + "avatar_url": "https://avatars1.githubusercontent.com/u/22237814?v=4", + "description": "" + }, + "sender": { + "login": "seregamorph", + "id": 2844909, + "node_id": "MDQ6VXNlcjE2NjAxNjgz", + "avatar_url": "https://avatars2.githubusercontent.com/u/2844909?v=4", + "gravatar_id": "", + "url": "https://api.github.com/users/seregamorph", + "html_url": "https://github.com/seregamorph", + "followers_url": "https://api.github.com/users/seregamorph/followers", + "following_url": "https://api.github.com/users/seregamorph/following{/other_user}", + "gists_url": "https://api.github.com/users/seregamorph/gists{/gist_id}", + "starred_url": "https://api.github.com/users/seregamorph/starred{/owner}{/repo}", + "subscriptions_url": "https://api.github.com/users/seregamorph/subscriptions", + "organizations_url": "https://api.github.com/users/seregamorph/orgs", + "repos_url": "https://api.github.com/users/seregamorph/repos", + "events_url": "https://api.github.com/users/seregamorph/events{/privacy}", + "received_events_url": "https://api.github.com/users/seregamorph/received_events", + "type": "User", + "site_admin": false + } +} \ No newline at end of file