Skip to content
Draft
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
9 changes: 7 additions & 2 deletions src/main/java/org/kohsuke/github/GHAppInstallation.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package org.kohsuke.github;

import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonSubTypes;
import com.fasterxml.jackson.annotation.JsonTypeInfo;
import com.infradna.tool.bridge_method_injector.WithBridgeMethods;
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
import org.kohsuke.github.internal.EnumUtils;
Expand Down Expand Up @@ -39,7 +41,10 @@ GHRepository[] getItems(GitHub root) {
@JsonProperty("access_tokens_url")
private String accessTokenUrl;

private GHUser account;
@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, property = "type")
@JsonSubTypes({ @JsonSubTypes.Type(value = GHUser.class, name = "User"),
@JsonSubTypes.Type(value = GHOrganization.class, name = "Organization") })
private GHPerson account;
@JsonProperty("app_id")
private long appId;
private List<String> events;
Expand Down Expand Up @@ -122,7 +127,7 @@ public String getAccessTokenUrl() {
* @return the account
*/
@SuppressFBWarnings(value = { "EI_EXPOSE_REP" }, justification = "Expected behavior")
public GHUser getAccount() {
public GHPerson getAccount() {
return account;
}

Expand Down
1 change: 1 addition & 0 deletions src/test/java/org/kohsuke/github/AppTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -737,6 +737,7 @@ public void testGetAppInstallations() throws Exception {
final GHAppInstallation ghAppInstallation = appInstallation.toList().get(0);
assertThat(ghAppInstallation.getAppId(), is(122478L));
assertThat(ghAppInstallation.getAccount().getLogin(), is("t0m4uk1991"));
assertThat(ghAppInstallation.getAccount(), instanceOf(GHUser.class));
}

/**
Expand Down
3 changes: 2 additions & 1 deletion src/test/java/org/kohsuke/github/GHAppTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -264,11 +264,12 @@ public void listInstallationsSince() throws IOException, ParseException {

private void testAppInstallation(GHAppInstallation appInstallation) throws IOException {
Map<String, GHPermissionType> appPermissions = appInstallation.getPermissions();
GHUser appAccount = appInstallation.getAccount();
GHPerson appAccount = appInstallation.getAccount();

assertThat(appInstallation.getId(), is((long) 11111111));
assertThat(appAccount.getId(), is((long) 111111111));
assertThat(appAccount.login, is("bogus"));
assertThat(appAccount, instanceOf(GHOrganization.class));
assertThat(appAccount.getType(), is("Organization"));
assertThat(appInstallation.getRepositorySelection(), is(GHRepositorySelection.SELECTED));
assertThat(appInstallation.getAccessTokenUrl(), endsWith("/app/installations/11111111/access_tokens"));
Expand Down
5 changes: 5 additions & 0 deletions src/test/java/org/kohsuke/github/GHEventPayloadTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.hasProperty;
import static org.hamcrest.Matchers.hasToString;
import static org.hamcrest.Matchers.instanceOf;
import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.lessThanOrEqualTo;
import static org.hamcrest.Matchers.notNullValue;
Expand Down Expand Up @@ -59,6 +60,8 @@ public void InstallationCreatedEvent() throws Exception {
assertThat(event.getAction(), is("created"));
assertThat(event.getInstallation().getId(), is(43898337L));
assertThat(event.getInstallation().getAccount().getLogin(), is("CronFire"));
assertThat(event.getInstallation().getAccount(), instanceOf(GHOrganization.class));
assertThat(event.getInstallation().getAccount().getType(), is("Organization"));

assertThat(event.getRepositories().isEmpty(), is(false));
assertThat(event.getRepositories().get(0).getId(), is(1296269L));
Expand All @@ -84,6 +87,8 @@ public void InstallationDeletedEvent() throws Exception {
assertThat(event.getAction(), is("deleted"));
assertThat(event.getInstallation().getId(), is(2L));
assertThat(event.getInstallation().getAccount().getLogin(), is("octocat"));
assertThat(event.getInstallation().getAccount(), instanceOf(GHUser.class));
assertThat(event.getInstallation().getAccount().getType(), is("User"));

assertThrows(IllegalStateException.class, () -> event.getRepositories().isEmpty());
assertThat(event.getRawRepositories().isEmpty(), is(false));
Expand Down
Loading