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

[WIP] fix: Uptake additional GH Repository webhook actions #1153

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

ajay-sentry
Copy link
Contributor

@ajay-sentry ajay-sentry commented Feb 12, 2025

Purpose/Motivation

This PR aims to uptake additional GH webhook actions for the repository webhook, specifically the following:

  • Created
  • Edited (for default branch updates)
  • Transferred
  • Archived
  • Unarchived
  • Renamed

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.

Copy link

sentry-io bot commented Feb 12, 2025

🔍 Existing Issues For Review

Your pull request is modifying functions with the following pre-existing issues:

📄 File: webhook_handlers/views/github.py

Function Unhandled Issue
validate_signature TypeError: '>' not supported between instances of 'int' and 'str' /webhooks/...
Event Count: 84

Did you find this useful? React with a 👍 or 👎

@ajay-sentry ajay-sentry changed the title update other repo actions [WIP] fix: Uptake additional GH Repository webhook actions Feb 12, 2025
Comment on lines +167 to +177
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()
Copy link
Contributor

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

Comment on lines +237 to +250
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),
)
Copy link
Contributor

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

Copy link
Contributor Author

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

Comment on lines +226 to +231
repo.author = Owner.objects.get(
service=self.service_name,
service_id=self.request.data.get("repository", {})
.get("owner", {})
.get("id"),
)
Copy link
Contributor

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

Copy link

codecov bot commented Feb 12, 2025

Codecov Report

Attention: Patch coverage is 34.88372% with 28 lines in your changes missing coverage. Please review.

Project coverage is 95.90%. Comparing base (06167fb) to head (16d8889).

Changes have been made to critical files, which contain lines commonly executed in production. Learn more

✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
webhook_handlers/views/github.py Critical 34.88% 28 Missing ⚠️
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     
Flag Coverage Δ
unit 95.76% <34.88%> (-0.16%) ⬇️
unit-latest-uploader 95.76% <34.88%> (-0.16%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@codecov-qa
Copy link

codecov-qa bot commented Feb 12, 2025

Codecov Report

Attention: Patch coverage is 34.88372% with 28 lines in your changes missing coverage. Please review.

Project coverage is 95.76%. Comparing base (06167fb) to head (16d8889).

✅ All tests successful. No failed tests found.

Copy link
Contributor

✅ All tests successful. No failed tests were found.

📣 Thoughts on this report? Let Codecov know! | Powered by Codecov

@codecov-notifications
Copy link

Codecov Report

Attention: Patch coverage is 34.88372% with 28 lines in your changes missing coverage. Please review.

✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
webhook_handlers/views/github.py 34.88% 28 Missing ⚠️

📢 Thoughts on this report? Let us know!

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

Successfully merging this pull request may close these issues.

Uptake GH webhook Repository Actions that are currently dropped
2 participants