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

Fix bug in github-app.ts #5039

Merged
merged 2 commits into from
Aug 3, 2021
Merged

Fix bug in github-app.ts #5039

merged 2 commits into from
Aug 3, 2021

Conversation

AlexTugarev
Copy link
Member

First changes towards #4661

@roboquat roboquat requested a review from csweichel August 2, 2021 10:16
@roboquat roboquat added the size/S label Aug 2, 2021
@AlexTugarev AlexTugarev changed the title at/github-app Fix bug in github-app.ts Aug 2, 2021
const installationId = `${ctx.payload.installation.id}`;
const senderId = `${ctx.payload.sender.id}`;
const user = await this.userDB.findUserByIdentity({ authProviderId: this.env.githubAppAuthProviderId, authId: accountId });
Copy link
Member Author

Choose a reason for hiding this comment

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

accountId is the target account id, e.g. from github.com/gitpod-io. this are not valid coordinates for user accounts.

Copy link
Contributor

Choose a reason for hiding this comment

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

Interesting. I'd love to learn more about the differences between ctx.payload.installation.account.id and ctx.payload.sender.id.

  • From the docs you linked, I gather that ctx.payload.installation.account.id is the "account" on which the app is installed (e.g. can be an org, as you mentioned)
  • Who is ctx.payload.sender.id then? Is it the user that installed the app (e.g. a team member), or the user that triggered/caused the event? (e.g. a community contributor opening a new PR)

Copy link
Member Author

Choose a reason for hiding this comment

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

See the documentation URL at L.90.

@jankeromnes
Copy link
Contributor

jankeromnes commented Aug 2, 2021

Taking a look! Many thanks. 👍

/werft run

👍 started the job as gitpod-build-at-github-app.1

Copy link
Contributor

@jankeromnes jankeromnes left a comment

Choose a reason for hiding this comment

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

Changes look good to me, thanks!

However, I tried the following test:

  1. Connect my GitHub App to this PR
  2. Add a Project for https://github.com/jankeromnes/oops.git
  3. Rename repository to "oops2"
  4. ... the cloneUrl in the DB never got updated:
mysql> select name, cloneUrl from d_b_project;
+------+-----------------------------------------+
| name | cloneUrl                                |
+------+-----------------------------------------+
| oops | https://github.com/jankeromnes/oops.git |
+------+-----------------------------------------+
1 row in set (0.01 sec)

Did the rename listener work for you?

const installationId = `${ctx.payload.installation.id}`;
const senderId = `${ctx.payload.sender.id}`;
const user = await this.userDB.findUserByIdentity({ authProviderId: this.env.githubAppAuthProviderId, authId: accountId });
Copy link
Contributor

Choose a reason for hiding this comment

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

Interesting. I'd love to learn more about the differences between ctx.payload.installation.account.id and ctx.payload.sender.id.

  • From the docs you linked, I gather that ctx.payload.installation.account.id is the "account" on which the app is installed (e.g. can be an org, as you mentioned)
  • Who is ctx.payload.sender.id then? Is it the user that installed the app (e.g. a team member), or the user that triggered/caused the event? (e.g. a community contributor opening a new PR)

});
app.on('installation.deleted', async ctx => {
const installationId = `${ctx.payload.installation.id}`;
await this.appInstallationDB.recordUninstallation("github", 'platform', installationId);
});

app.on('repository.renamed', async ctx => {
Copy link
Contributor

Choose a reason for hiding this comment

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

Interesting, where is this event type documented? I couldn't find it anywhere.

Copy link
Member Author

Choose a reason for hiding this comment

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

Also, that's the repository event with renamed action. See the documentation URL above.

Comment on lines +105 to +107
if (!installation) {
return;
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Q: Can this actually happen?

Copy link
Member Author

Choose a reason for hiding this comment

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

@jankeromnes
Copy link
Contributor

Hmm, maybe something is wrong with my GitHub App setup:

mysql> select appInstallationId from d_b_project;
+-------------------+
| appInstallationId |
+-------------------+
| 18634854          |
| 18639799          |
+-------------------+
2 rows in set (0.00 sec)

mysql> select * from d_b_app_installation;
Empty set (0.00 sec)

@AlexTugarev
Copy link
Member Author

@jankeromnes, I just double-checked with the webhook events and they look good. Did you set the webhook URL properly? You can check the settings of the GH App for the event delivery status, maybe they are not 200 OK?

This is a short version of what's received, and it was effective:

{
    "action": "renamed",
    "changes": { "repository": { "name": { "from": "test-repo" } } },
    "repository": {
        "name": "test-repo-1",
        "full_name": "cool-test-org/test-repo-1",
        "owner": {
            "login": "cool-test-org", ...
        }, ...
    },
    "organization": {
        "login": "cool-test-org", ...
    },
    "sender": {
        "login": "AlexTugarev", ...
    },
    "installation": {
        "id": 18635259, ...
    }
}

Copy link
Member

@svenefftinge svenefftinge left a comment

Choose a reason for hiding this comment

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

lgtm

@roboquat
Copy link
Contributor

roboquat commented Aug 3, 2021

LGTM label has been added.

Git tree hash: e1c13db6df568b815cc6524306a8dc680353f2aa

@roboquat
Copy link
Contributor

roboquat commented Aug 3, 2021

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: svenefftinge

Associated issue: #4661

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@roboquat roboquat merged commit 7f0908b into main Aug 3, 2021
@roboquat roboquat deleted the at/github-app branch August 3, 2021 07:36
@jankeromnes
Copy link
Contributor

jankeromnes commented Aug 3, 2021

I just double-checked with the webhook events and they look good. Did you set the webhook URL properly?

Hmm, I thought I did. I had set it to https://at-github-app.staging.gitpod-dev.com/api/apps/github:

Screenshot 2021-08-03 at 09 44 38

You can check the settings of the GH App for the event delivery status, maybe they are not 200 OK?

Ah, very cool, I didn't know about that.

Screenshot 2021-08-03 at 09 49 41

Checking the event log, it seems that:

  1. The first event ("repository added") failed. This is surprising to me, because the project was successfully added.
  2. The second event ("pushed to repository") succeeded.

There was no event about the rename, apparently. Maybe that's an additional option that needs to be enabled in the GitHub App somewhere? 🤔

Anyway, glad this is now merged! 🚀

@AlexTugarev
Copy link
Member Author

AlexTugarev commented Aug 3, 2021

@jankeromnes, you've created the GH App after the gitpod-staging-com App? Just realized it's not using this event, see the event and permissions page where you'll find the Repository event. That's like missing. Also, I'm checking with the production app.

Screen Shot 2021-08-03 at 09 54 58

@jankeromnes
Copy link
Contributor

jankeromnes commented Aug 3, 2021

@AlexTugarev Ah yes, I've duplicated permissions from https://github.com/organizations/gitpod-io/settings/apps/gitpod-staging-com/permissions. That would explain it!

EDIT: Which additional permissions do I need to add? Also, we should probably add them to the staging app too, right? Maybe to the production app as well?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants