-
Notifications
You must be signed in to change notification settings - Fork 29
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
[WIP] fix: Uptake additional GH Repository webhook actions #1153
base: main
Are you sure you want to change the base?
Conversation
🔍 Existing Issues For ReviewYour pull request is modifying functions with the following pre-existing issues: 📄 File: webhook_handlers/views/github.py
Did you find this useful? React with a 👍 or 👎 |
if action == "created": | ||
repo_data = self.request.data.get("repository", {}) | ||
repo_service_id = repo_data.get("id") | ||
owner_service_id = repo_data.get("owner", {}).get("id") | ||
owner, _ = Owner.objects.get_or_create( | ||
service=self.service_name, service_id=owner_service_id | ||
) | ||
repo, _ = Repository.objects.get_or_create( | ||
author__ownerid=owner.ownerid, service_id=repo_service_id | ||
) | ||
return Response() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
does the webhook give us its public/private status? if we can't know whether the repo is meant to be private, i don't think we can create it here
for public repos this would make them show up without having to trigger a sync, but for private repos you still have to sync to populate owner.permission
elif action == "archived": | ||
repo.activated = False | ||
repo.save(update_fields=["activated"]) | ||
log.info( | ||
"Repository archived", | ||
extra=dict(repoid=repo.repoid, github_webhook_event=self.event), | ||
) | ||
elif action == "unarchived": | ||
repo.activated = True | ||
repo.save(update_fields=["activated"]) | ||
log.info( | ||
"Repository unarchived", | ||
extra=dict(repoid=repo.repoid, github_webhook_event=self.event), | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is this actually what "activated" means in our system? i figured it had plan implications or something
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think so, at least it seemed to make sense according to https://www.notion.so/sentry/Database-Field-Terminology-2c501a0844bc410aa35f1ecfd3c3eb61
repo.author = Owner.objects.get( | ||
service=self.service_name, | ||
service_id=self.request.data.get("repository", {}) | ||
.get("owner", {}) | ||
.get("id"), | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
probably get_or_create here too
Codecov ReportAttention: Patch coverage is
Changes have been made to critical files, which contain lines commonly executed in production. Learn more ✅ All tests successful. No failed tests found.
Additional details and impacted files@@ Coverage Diff @@
## main #1153 +/- ##
==========================================
- Coverage 96.03% 95.90% -0.14%
==========================================
Files 838 838
Lines 19818 19846 +28
==========================================
Hits 19033 19033
- Misses 785 813 +28
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. |
✅ All tests successful. No failed tests were found. 📣 Thoughts on this report? Let Codecov know! | Powered by Codecov |
Codecov ReportAttention: Patch coverage is ✅ All tests successful. No failed tests found.
📢 Thoughts on this report? Let us know! |
Purpose/Motivation
This PR aims to uptake additional GH webhook actions for the repository webhook, specifically the following:
According to https://console.cloud.google.com/logs/query;query=%22Unknown%20repository%20action:%22;summaryFields=jsonPayload%252Fgithub_webhook_event:false:32:beginning;lfeCustomFields=jsonPayload%252Fgithub_webhook_event,jsonPayload%252Fmessage;cursorTimestamp=2025-02-12T17:03:57.668527951Z;duration=P1D?project=genuine-polymer-165712&authuser=1&rapt=AEjHL4PD4ouhhOp5AhDcztMI1qB_NYCOer76Ai9CN49BTAs-Fw4c9_D6WEGzs31euTGsCazldjgAGyD6cLTKNvlQhWl3KZEc_TwPi1zqmfO_2FiqwOZee2U, we drop ~2000+ of these events per day
I think if we uptake these there's a possibility some load can be removed from sync_repos to find and update stale repos, and I think in the case of archived/unarchived, those are not handled even within sync_repos.
Plus there's some "quality of life" adjustment here with the "created" action, no longer needing to rely on sync_repos to pull it in and create the repo. Generally, it seems like sync_repos has been "bandaged" together to handle all these edge cases when if we solve the problem upstream (in the webhook handler), we might be able to get rid of a lot of that stuff if we can get confidence that these webhooks keep things in sync on their own.
Links to relevant tickets
Closes codecov/engineering-team#2938
Notes to Reviewer
Anything to note to the team? Any tips on how to review, or where to start?
Legal Boilerplate
Look, I get it. The entity doing business as "Sentry" was incorporated in the State of Delaware in 2015 as Functional Software, Inc. In 2022 this entity acquired Codecov and as result Sentry is going to need some rights from me in order to utilize my contributions in this PR. So here's the deal: I retain all rights, title and interest in and to my contributions, and by keeping this boilerplate intact I confirm that Sentry can use, modify, copy, and redistribute my contributions, under Sentry's choice of terms.