github-education-resources / classroom

GitHub Classroom automates repository creation and access control, making it easy for teachers to distribute starter code and collect assignments on GitHub.
https://classroom.github.com
1.34k stars 565 forks source link

Organizations Are Missing Webhooks #1647

Open BenEmdon opened 5 years ago

BenEmdon commented 5 years ago

From running the following query on production, it is evident that there are still a significant amount of Organizations that are missing webhooks:

pry(main)> Organization.where(webhook_id: nil).count
DEBUG -- :    (7.0ms)  SELECT COUNT(*) FROM "organizations" WHERE "organizations"."deleted_at" IS NULL AND "organizations"."webhook_id" IS NULL
=> 3838

This number excludes Organizations that have a webhook_id but who's webhooks are deleted or inactive.

The source of this problem

The problem occurred when we introduced webhooks back in https://github.com/education/classroom/pull/797, we forgot to backfill organizations created before the change with web hooks.

Why this is important

All Organizations require webhooks to perform starter code imports as we rely on the repository_import event.

Steps to ensure all Organizations have webhooks that are active

~Steps to ensure an org is in good health~

~Switch all webhooks to app created webhooks~

Do what we can with what we have

BenEmdon commented 5 years ago

Just ran the organization_webhook_health_migration I had been working on and got the following results:

Next

We should notify classrooms that don’t have webhooks to authorize the right token.

BenEmdon commented 5 years ago

Possible Solution:

Right now, webhooks are dependant on users OAuth tokens. This isn't great because users can revoke their tokens, or leave the organization, leaving the tokens on record as invalid.

It turns out we can use the classroom OAuth app token to create webhooks:

from the docs

If we use the classroom client OAuth token to create webhooks then we can ensure that every organization has webhooks enabled.

srinjoym commented 5 years ago

@BenEmdon What do you think about renaming this issue to include "Importing starter code taking a long time" or something like that so people know that it's related to this problem? That could help redirect people here as they run into issues

BenEmdon commented 5 years ago

I'd like to keep the development track and incident reports separate so we can filter out the noise 😕 Maybe I should start a master issue for all the incidents?

srinjoym commented 5 years ago

That totally makes sense! I think we can open up another pinned issue just for the incidents and include some instructions on what to do if people hit this issue. Hopefully that makes it a bit easier to sort through

BenEmdon commented 5 years ago

Pinned #1778

stale[bot] commented 5 years ago

This issue has been automatically marked as stale because it has not had recent activity. Thank you for your contributions.

BenEmdon commented 5 years ago

Screen Shot 2019-05-28 at 5 51 30 PM From the docs

Interesting; hooks created by the OAuth app cannot be seen by users. And hooks created by users cannot be seen by the Oauth app.

BenEmdon commented 5 years ago

Update

So after investigating the API, it turns out that OAuth apps can't use their own token to register web hooks. 😔 This means that we will have to continue to use user tokens to register webhooks.

Steps forward

BenEmdon commented 5 years ago

Update

Ran the organization_webhook_health_migration and now the number of classrooms missing webhooks is:

PRODUCTION [1] pry(main)> OrganizationWebhook.where(github_id: nil).count
=> 3674

The 3674 Organizations without Webhooks

These organizations are missing webhooks for one of two reasons:

  1. The organization no longer has a user token with the admin:org_hook scope (as in the user left the organization).
  2. The organization was deleted.

We can't do anything about case 2, but we can let each classroom know that they are missing a user with the the admin:org_hook scope.

BenEmdon commented 5 years ago

This issue could be resolved if Classroom became a GitHub app #2049

stale[bot] commented 5 years ago

This issue has been automatically marked as stale because it has not had recent activity. Thank you for your contributions.