Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[JENKINS-57430] Added some new GH Event Types #622

Merged
merged 5 commits into from
Dec 17, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
72 changes: 72 additions & 0 deletions src/main/java/org/kohsuke/github/GHCheckRun.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
package org.kohsuke.github;

import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;

import java.io.IOException;
import java.net.URL;

/**
* Represents a deployment
*
* @see <a href="https://developer.github.com/v3/checks/runs/">documentation</a>
*/

@SuppressFBWarnings(value = { "UWF_UNWRITTEN_FIELD", "NP_UNWRITTEN_FIELD", "URF_UNREAD_FIELD" },
justification = "JSON API")
public class GHCheckRun extends GHObject {
GHRepository owner;
GitHub root;

private String status;
private String conclusion;
private String name;
private GHPullRequest[] pullRequests;

GHCheckRun wrap(GHRepository owner) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this.owner = owner;
this.root = owner.root;
return this;
}

GHCheckRun wrap(GitHub root) {
this.root = root;
if (owner != null) {
owner.wrap(root);
}
return this;
}

GHPullRequest[] wrap() {
return pullRequests;
}

public String getStatus() {
return status;
}

public String getConclusion() {
return conclusion;
}

public String getName() {
return name;
}

GHPullRequest[] getPullRequests() throws IOException {
if (pullRequests != null && pullRequests.length != 0) {
for (GHPullRequest singlePull : pullRequests) {
singlePull.refresh();
}
}
return pullRequests;
}

/**
* @deprecated This object has no HTML URL.
*/
@Override
public URL getHtmlUrl() {
return null;
}

}
22 changes: 15 additions & 7 deletions src/main/java/org/kohsuke/github/GHEvent.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,50 +10,58 @@
* @see <a href="https://developer.github.com/v3/activity/events/types/">Event type reference</a>
*/
public enum GHEvent {
CHECK_RUN,
CHECK_SUITE,
COMMIT_COMMENT,
CONTENT_REFERENCE,
CREATE,
DELETE,
DEPLOY_KEY,
DEPLOYMENT,
DEPLOYMENT_STATUS,
DOWNLOAD,
FOLLOW,
FORK,
FORK_APPLY,
GITHUB_APP_AUTHORIZATION,
GIST,
GOLLUM,
INSTALLATION,
INSTALLATION_REPOSITORIES,
INTEGRATION_INSTALLATION_REPOSITORIES,
CHECK_SUITE,
ISSUE_COMMENT,
ISSUES,
LABEL,
MARKETPLACE_PURCHASE,
MEMBER,
MEMBERSHIP,
META,
MILESTONE,
ORGANIZATION,
ORG_BLOCK,
PACKAGE,
PAGE_BUILD,
PROJECT_CARD,
PROJECT_COLUMN,
PROJECT,
PING,
PUBLIC,
PULL_REQUEST,
PULL_REQUEST_REVIEW,
PULL_REQUEST_REVIEW_COMMENT,
PUSH,
RELEASE,
REPOSITORY, // only
// valid
// for
// org
// hooks
REPOSITORY_DISPATCH, // only valid for org hooks
REPOSITORY,
REPOSITORY_IMPORT,
REPOSITORY_VULNERABILITY_ALERT,
SECURITY_ADVISORY,
STAR,
STATUS,
TEAM,
TEAM_ADD,
WATCH,
PING,

/**
* Special event type that means "every possible event"
*/
Expand Down
103 changes: 103 additions & 0 deletions src/main/java/org/kohsuke/github/GHEventPayload.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,109 @@ void wrapUp(GitHub root) {
}
}

// List of events that still need to be added:
// CheckRunEvent CheckSuiteEvent ContentReferenceEvent
// DeployKeyEvent DownloadEvent FollowEvent ForkApplyEvent GitHubAppAuthorizationEvent GistEvent GollumEvent
// InstallationEvent InstallationRepositoriesEvent IssuesEvent LabelEvent MarketplacePurchaseEvent MemberEvent
// MembershipEvent MetaEvent MilestoneEvent OrganizationEvent OrgBlockEvent PackageEvent PageBuildEvent
// ProjectCardEvent ProjectColumnEvent ProjectEvent RepositoryDispatchEvent RepositoryImportEvent
// RepositoryVulnerabilityAlertEvent SecurityAdvisoryEvent StarEvent StatusEvent TeamEvent TeamAddEvent WatchEvent

/**
* A check run event has been created, rerequested, completed, or has a requested_action.
*
* @see <a href="https://developer.github.com/v3/activity/events/types/#checkrunevent">authoritative source</a>
*/
@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.
*
* @return the number
*/
public int getNumber() {
return number;
}

/**
* Sets Check Run object
*
* @param currentCheckRun
* the check run object
*/
public void setCheckRun(GHCheckRun currentCheckRun) {
this.checkRun = currentCheckRun;
}

/**
* Gets Check Run object
*
* @return the current checkRun object
*/
public GHCheckRun getCheckRun() {
return checkRun;
}

/**
* Sets the Requested Action object
*
* @param currentRequestedAction
* the current action
*/
public void setCheckRun(GHRequestedAction currentRequestedAction) {
this.requestedAction = currentRequestedAction;
}

/**
* Gets the Requested Action object
*
* @return the requested action
*/
public GHRequestedAction getRequestedAction() {
return requestedAction;
}

/**
* Gets repository.
*
* @return the repository
*/
public GHRepository getRepository() {
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?");
if (repository != null) {
repository.wrap(root);
checkRun.wrap(repository);
} else {
checkRun.wrap(root);
}
}
}

/**
* A pull request status has changed.
*
Expand Down
49 changes: 49 additions & 0 deletions src/main/java/org/kohsuke/github/GHRequestedAction.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package org.kohsuke.github;

import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;

import java.net.URL;

@SuppressFBWarnings(value = { "UWF_UNWRITTEN_FIELD", "NP_UNWRITTEN_FIELD", "URF_UNREAD_FIELD" },
justification = "JSON API")
public class GHRequestedAction extends GHObject {
private GHRepository owner;
private GitHub root;
private String identifier;
private String label;
private String description;

GHRequestedAction wrap(GHRepository owner) {
this.owner = owner;
wrap(owner.root);
return this;
}
GHRequestedAction wrap(GitHub root) {
this.root = root;
if (owner != null) {
owner.wrap(root);
}
return this;
}

String getIdentifier() {
return identifier;
}

String getLabel() {
return label;
}

String getDescription() {
return description;
}

/**
* @deprecated This object has no HTML URL.
*/
@Override
public URL getHtmlUrl() {
return null;
}

}
10 changes: 10 additions & 0 deletions src/test/java/org/kohsuke/github/GHEventPayloadTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -306,4 +306,14 @@ public void repository() throws Exception {
// @Test
// public void watch() throws Exception {}

@Test
@Payload("check-run")
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.getAction(), is("created"));
assertThat(event.getCheckRun().getName(), is("Octocoders-linter"));
}

}
Loading