Skip to content
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
26 changes: 24 additions & 2 deletions src/main/java/org/kohsuke/github/GHEventPayload.java
Original file line number Diff line number Diff line change
Expand Up @@ -381,9 +381,9 @@ public GHPullRequest getPullRequest() {
}

/**
* Gets label.
* Gets the added or removed label for labeled/unlabeled events.
*
* @return the label
* @return label the added or removed label
*/
public GHLabel getLabel() {
return label;
Expand Down Expand Up @@ -520,6 +520,10 @@ void wrapUp(GitHub root) {
public static class Issue extends GHEventPayload {
private GHIssue issue;

private GHLabel label;

private GHIssueChanges changes;

/**
* Gets issue.
*
Expand All @@ -539,6 +543,24 @@ public void setIssue(GHIssue issue) {
this.issue = issue;
}

/**
* Gets the added or removed label for labeled/unlabeled events.
*
* @return label the added or removed label
*/
public GHLabel getLabel() {
return label;
}

/**
* Get changes (for action="edited")
*
* @return changes
*/
public GHIssueChanges getChanges() {
return changes;
}

@Override
void wrapUp(GitHub root) {
super.wrapUp(root);
Expand Down
49 changes: 49 additions & 0 deletions src/main/java/org/kohsuke/github/GHIssueChanges.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;

/**
* Wrapper to define changed fields on issues action="edited"
*
* @see GHEventPayload.Issue
*/
@SuppressFBWarnings("UWF_UNWRITTEN_FIELD")
public class GHIssueChanges {

private GHFrom title;
private GHFrom body;

/**
* Old issue title.
*
* @return old issue title (or null if not changed)
*/
public GHFrom getTitle() {
return title;
}

/**
* Old issue body.
*
* @return old issue body (or null if not changed)
*/
public GHFrom getBody() {
return body;
}

/**
* Wrapper for changed values.
*/
public static class GHFrom {
private String from;

/**
* Previous value that was changed.
*
* @return previous value
*/
public String getFrom() {
return from;
}
}
}
39 changes: 39 additions & 0 deletions src/test/java/org/kohsuke/github/GHEventPayloadTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,45 @@ public void issues() throws Exception {
assertThat(event.getSender().getLogin(), is("baxterthehacker"));
}

@Test
public void issue_labeled() throws Exception {
GHEventPayload.Issue event = GitHub.offline().parseEventPayload(payload.asReader(), GHEventPayload.Issue.class);
assertThat(event.getAction(), is("labeled"));
assertThat(event.getIssue().getNumber(), is(42));
assertThat(event.getIssue().getTitle(), is("Test GHEventPayload.Issue label/unlabel"));
assertThat(event.getIssue().getLabels().size(), is(1));
assertThat(event.getIssue().getLabels().iterator().next().getName(), is("enhancement"));
assertThat(event.getLabel().getName(), is("enhancement"));
}

@Test
public void issue_unlabeled() throws Exception {
GHEventPayload.Issue event = GitHub.offline().parseEventPayload(payload.asReader(), GHEventPayload.Issue.class);
assertThat(event.getAction(), is("unlabeled"));
assertThat(event.getIssue().getNumber(), is(42));
assertThat(event.getIssue().getTitle(), is("Test GHEventPayload.Issue label/unlabel"));
assertThat(event.getIssue().getLabels().size(), is(0));
assertThat(event.getLabel().getName(), is("enhancement"));
}

@Test
public void issue_title_edited() throws Exception {
GHEventPayload.Issue event = GitHub.offline().parseEventPayload(payload.asReader(), GHEventPayload.Issue.class);
assertThat(event.getAction(), is("edited"));
assertThat(event.getIssue().getNumber(), is(43));
assertThat(event.getIssue().getTitle(), is("Test GHEventPayload.Issue changes [updated]"));
assertThat(event.getChanges().getTitle().getFrom(), is("Test GHEventPayload.Issue changes"));
}

@Test
public void issue_body_edited() throws Exception {
GHEventPayload.Issue event = GitHub.offline().parseEventPayload(payload.asReader(), GHEventPayload.Issue.class);
assertThat(event.getAction(), is("edited"));
assertThat(event.getIssue().getNumber(), is(43));
assertThat(event.getIssue().getBody(), is("Description [updated]."));
assertThat(event.getChanges().getBody().getFrom(), is("Description."));
}

// TODO implement support classes and write test
// @Test
// public void label() throws Exception {}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,172 @@
{
"action": "edited",
"issue": {
"url": "https://api.github.com/repos/gsmet/quarkus-bot-java-playground/issues/43",
"repository_url": "https://api.github.com/repos/gsmet/quarkus-bot-java-playground",
"labels_url": "https://api.github.com/repos/gsmet/quarkus-bot-java-playground/issues/43/labels{/name}",
"comments_url": "https://api.github.com/repos/gsmet/quarkus-bot-java-playground/issues/43/comments",
"events_url": "https://api.github.com/repos/gsmet/quarkus-bot-java-playground/issues/43/events",
"html_url": "https://github.com/gsmet/quarkus-bot-java-playground/issues/43",
"id": 835926945,
"node_id": "MDU6SXNzdWU4MzU5MjY5NDU=",
"number": 43,
"title": "Test GHEventPayload.Issue changes [updated]",
"user": {
"login": "gsmet",
"id": 1279749,
"node_id": "MDQ6VXNlcjEyNzk3NDk=",
"avatar_url": "https://avatars.githubusercontent.com/u/1279749?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/gsmet",
"html_url": "https://github.com/gsmet",
"followers_url": "https://api.github.com/users/gsmet/followers",
"following_url": "https://api.github.com/users/gsmet/following{/other_user}",
"gists_url": "https://api.github.com/users/gsmet/gists{/gist_id}",
"starred_url": "https://api.github.com/users/gsmet/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/gsmet/subscriptions",
"organizations_url": "https://api.github.com/users/gsmet/orgs",
"repos_url": "https://api.github.com/users/gsmet/repos",
"events_url": "https://api.github.com/users/gsmet/events{/privacy}",
"received_events_url": "https://api.github.com/users/gsmet/received_events",
"type": "User",
"site_admin": false
},
"labels": [],
"state": "open",
"locked": false,
"assignee": null,
"assignees": [],
"milestone": null,
"comments": 0,
"created_at": "2021-03-19T12:19:58Z",
"updated_at": "2021-03-19T12:20:36Z",
"closed_at": null,
"author_association": "OWNER",
"active_lock_reason": null,
"body": "Description [updated].",
"performed_via_github_app": null
},
"changes": {
"body": {
"from": "Description."
}
},
"repository": {
"id": 313384129,
"node_id": "MDEwOlJlcG9zaXRvcnkzMTMzODQxMjk=",
"name": "quarkus-bot-java-playground",
"full_name": "gsmet/quarkus-bot-java-playground",
"private": true,
"owner": {
"login": "gsmet",
"id": 1279749,
"node_id": "MDQ6VXNlcjEyNzk3NDk=",
"avatar_url": "https://avatars.githubusercontent.com/u/1279749?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/gsmet",
"html_url": "https://github.com/gsmet",
"followers_url": "https://api.github.com/users/gsmet/followers",
"following_url": "https://api.github.com/users/gsmet/following{/other_user}",
"gists_url": "https://api.github.com/users/gsmet/gists{/gist_id}",
"starred_url": "https://api.github.com/users/gsmet/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/gsmet/subscriptions",
"organizations_url": "https://api.github.com/users/gsmet/orgs",
"repos_url": "https://api.github.com/users/gsmet/repos",
"events_url": "https://api.github.com/users/gsmet/events{/privacy}",
"received_events_url": "https://api.github.com/users/gsmet/received_events",
"type": "User",
"site_admin": false
},
"html_url": "https://github.com/gsmet/quarkus-bot-java-playground",
"description": null,
"fork": false,
"url": "https://api.github.com/repos/gsmet/quarkus-bot-java-playground",
"forks_url": "https://api.github.com/repos/gsmet/quarkus-bot-java-playground/forks",
"keys_url": "https://api.github.com/repos/gsmet/quarkus-bot-java-playground/keys{/key_id}",
"collaborators_url": "https://api.github.com/repos/gsmet/quarkus-bot-java-playground/collaborators{/collaborator}",
"teams_url": "https://api.github.com/repos/gsmet/quarkus-bot-java-playground/teams",
"hooks_url": "https://api.github.com/repos/gsmet/quarkus-bot-java-playground/hooks",
"issue_events_url": "https://api.github.com/repos/gsmet/quarkus-bot-java-playground/issues/events{/number}",
"events_url": "https://api.github.com/repos/gsmet/quarkus-bot-java-playground/events",
"assignees_url": "https://api.github.com/repos/gsmet/quarkus-bot-java-playground/assignees{/user}",
"branches_url": "https://api.github.com/repos/gsmet/quarkus-bot-java-playground/branches{/branch}",
"tags_url": "https://api.github.com/repos/gsmet/quarkus-bot-java-playground/tags",
"blobs_url": "https://api.github.com/repos/gsmet/quarkus-bot-java-playground/git/blobs{/sha}",
"git_tags_url": "https://api.github.com/repos/gsmet/quarkus-bot-java-playground/git/tags{/sha}",
"git_refs_url": "https://api.github.com/repos/gsmet/quarkus-bot-java-playground/git/refs{/sha}",
"trees_url": "https://api.github.com/repos/gsmet/quarkus-bot-java-playground/git/trees{/sha}",
"statuses_url": "https://api.github.com/repos/gsmet/quarkus-bot-java-playground/statuses/{sha}",
"languages_url": "https://api.github.com/repos/gsmet/quarkus-bot-java-playground/languages",
"stargazers_url": "https://api.github.com/repos/gsmet/quarkus-bot-java-playground/stargazers",
"contributors_url": "https://api.github.com/repos/gsmet/quarkus-bot-java-playground/contributors",
"subscribers_url": "https://api.github.com/repos/gsmet/quarkus-bot-java-playground/subscribers",
"subscription_url": "https://api.github.com/repos/gsmet/quarkus-bot-java-playground/subscription",
"commits_url": "https://api.github.com/repos/gsmet/quarkus-bot-java-playground/commits{/sha}",
"git_commits_url": "https://api.github.com/repos/gsmet/quarkus-bot-java-playground/git/commits{/sha}",
"comments_url": "https://api.github.com/repos/gsmet/quarkus-bot-java-playground/comments{/number}",
"issue_comment_url": "https://api.github.com/repos/gsmet/quarkus-bot-java-playground/issues/comments{/number}",
"contents_url": "https://api.github.com/repos/gsmet/quarkus-bot-java-playground/contents/{+path}",
"compare_url": "https://api.github.com/repos/gsmet/quarkus-bot-java-playground/compare/{base}...{head}",
"merges_url": "https://api.github.com/repos/gsmet/quarkus-bot-java-playground/merges",
"archive_url": "https://api.github.com/repos/gsmet/quarkus-bot-java-playground/{archive_format}{/ref}",
"downloads_url": "https://api.github.com/repos/gsmet/quarkus-bot-java-playground/downloads",
"issues_url": "https://api.github.com/repos/gsmet/quarkus-bot-java-playground/issues{/number}",
"pulls_url": "https://api.github.com/repos/gsmet/quarkus-bot-java-playground/pulls{/number}",
"milestones_url": "https://api.github.com/repos/gsmet/quarkus-bot-java-playground/milestones{/number}",
"notifications_url": "https://api.github.com/repos/gsmet/quarkus-bot-java-playground/notifications{?since,all,participating}",
"labels_url": "https://api.github.com/repos/gsmet/quarkus-bot-java-playground/labels{/name}",
"releases_url": "https://api.github.com/repos/gsmet/quarkus-bot-java-playground/releases{/id}",
"deployments_url": "https://api.github.com/repos/gsmet/quarkus-bot-java-playground/deployments",
"created_at": "2020-11-16T17:55:53Z",
"updated_at": "2020-12-01T08:39:07Z",
"pushed_at": "2020-12-01T08:39:05Z",
"git_url": "git://github.com/gsmet/quarkus-bot-java-playground.git",
"ssh_url": "git@github.com:gsmet/quarkus-bot-java-playground.git",
"clone_url": "https://github.com/gsmet/quarkus-bot-java-playground.git",
"svn_url": "https://github.com/gsmet/quarkus-bot-java-playground",
"homepage": null,
"size": 13,
"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": 1,
"mirror_url": null,
"archived": false,
"disabled": false,
"open_issues_count": 15,
"license": null,
"forks": 1,
"open_issues": 15,
"watchers": 0,
"default_branch": "main"
},
"sender": {
"login": "gsmet",
"id": 1279749,
"node_id": "MDQ6VXNlcjEyNzk3NDk=",
"avatar_url": "https://avatars.githubusercontent.com/u/1279749?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/gsmet",
"html_url": "https://github.com/gsmet",
"followers_url": "https://api.github.com/users/gsmet/followers",
"following_url": "https://api.github.com/users/gsmet/following{/other_user}",
"gists_url": "https://api.github.com/users/gsmet/gists{/gist_id}",
"starred_url": "https://api.github.com/users/gsmet/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/gsmet/subscriptions",
"organizations_url": "https://api.github.com/users/gsmet/orgs",
"repos_url": "https://api.github.com/users/gsmet/repos",
"events_url": "https://api.github.com/users/gsmet/events{/privacy}",
"received_events_url": "https://api.github.com/users/gsmet/received_events",
"type": "User",
"site_admin": false
},
"installation": {
"id": 13005535,
"node_id": "MDIzOkludGVncmF0aW9uSW5zdGFsbGF0aW9uMTMwMDU1MzU="
}
}
Loading