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

GHUser even when event comes from Organization type #1497

Open
Jalmeida1994 opened this issue Aug 2, 2022 · 3 comments · May be fixed by #1522
Open

GHUser even when event comes from Organization type #1497

Jalmeida1994 opened this issue Aug 2, 2022 · 3 comments · May be fixed by #1522
Labels

Comments

@Jalmeida1994
Copy link

Describe the bug
A GHUser type is returned even when in the payload the account type is Organization.

More precisely in the event installation.created when the installation.account.type is set to Organization (app installed in organization) the installation.account in the @Installation.Created payload returns a GHUser.

{
  "action": "created",
  "installation": {
    "id": 12345,
    "account": {
      "login": "org-name",
      <...>
      "type": "Organization",
      "site_admin": false
    },
<...>
fun onInstall(@Installation.Created installationPayload: GHEventPayload.Installation) {
  val tenantGHOrganization = installationPayload.installation.account // <-- GHUser instance
}

Also tried to use the installationPayload.organization object but it always returned null (probably it's used in other events):

fun onInstall(@Installation.Created installationPayload: GHEventPayload.Installation) {
  LOG.info("org: " + installationPayload.organization.name) // <--  Cannot invoke "org.kohsuke.github.GHOrganization.getName()" because the return value of "org.kohsuke.github.GHEventPayload$Installation.getOrganization()" is null
}

To Reproduce
Steps to reproduce the behavior:

  1. Create an event with installation.created in an organization (install app in an organization)
  2. Catch the event
  3. Retrieve the installationPayload.installation.account object
  4. Or retrieve the installationPayload.organization object

Expected behavior
If the payload has the installation.account.type set to Organization the installationPayload.installation.accountshould return a GHOrganization object or the installationPayload.organization should not return null.

Desktop (please complete the following information):

  • OS: macOS Monterey v12.4 (Apple M1)

Additional context
Using Kotlin and Quarkus GitHub App

@Jalmeida1994
Copy link
Author

I checked the GHAppInstallation.java file and checked that the field is indeed a GHUser:

public class GHAppInstallation extends GHObject {
    private GHUser account;

<...>

    /**
     * Gets account.
     *
     * @return the account
     */
    @SuppressFBWarnings(value = { "EI_EXPOSE_REP" }, justification = "Expected behavior")
    public GHUser getAccount() {
        return account;
    }

As this is Jackson binding, I don't think we can do a simple if statement. Probably change the account to GHPerson and add the code to change to GHUser or GHOrganization later?

@bitwiseman bitwiseman added the bug label Aug 8, 2022
@bitwiseman
Copy link
Member

bitwiseman commented Aug 8, 2022

Probably a similar problem to #126 .

As this is Jackson binding, I don't think we can do a simple if statement.

We don't want to deserialize aa GHPerson because we'd end up losing data - GHUser and GHIOrganization have fields not present on GHPerson.

Jackson has functionality to allow you to switch types based on a field, but I've never used it. The SO answer below has an example of how to do this.

https://stackoverflow.com/questions/30362446/deserialize-json-with-jackson-into-polymorphic-types-a-complete-example-is-giv

@Jalmeida1994
Copy link
Author

You're completely right. Hmm I may have a look at it. Thanks @bitwiseman!

@bloslo bloslo linked a pull request Sep 18, 2022 that will close this issue
10 tasks
bloslo added a commit to bloslo/github-api that referenced this issue Sep 27, 2022
bloslo added a commit to bloslo/github-api that referenced this issue Oct 8, 2022
bloslo added a commit to bloslo/github-api that referenced this issue Oct 8, 2022
bitwiseman added a commit to bloslo/github-api that referenced this issue Feb 25, 2023
bitwiseman added a commit to bloslo/github-api that referenced this issue Apr 22, 2023
bitwiseman added a commit to bloslo/github-api that referenced this issue May 22, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants