sentry icon indicating copy to clipboard operation
sentry copied to clipboard

feat(codegen): increment org contributors and assign seat in PR webhook handler

Open srest2021 opened this issue 1 month ago • 2 comments

fixes ENG-5942

depends on https://github.com/getsentry/sentry/pull/104371

Track an active contributor on a PR event webhook, if the repo has Seer and AI features enabled.

  • Always increment the contributor's num actions.
  • Only assign a seat to the contributor if it is not a bot or an external contributor.
  • Assign a seat to a contributor on the second PR event (not the first).
  • Seat assignment occurs in a task for robustness. We log a warning if it fails.

Extra notes

Info about the user's type (ie, bot or not) and association (ie, external contributor or not) can be obtained from the webhook payload, per the gh docs and gh enterprise docs.

  • payload["pull_request"]["author_association"] is a required field for all pull_request, pull_request_review, and pull_request_review_comment action types, and also in gh enterprise. ✅ -> Added to all gh and gh enterprise fixtures.
  • payload["pull_request"]["user"]["type"] is required for the pull_request.opened and pull_request.closed action types. ✅
  • payload["pull_request"]["user"]["type"] is not required for pull_request.edited, or any pull_request_review or pull_request_review_comment action types. But I set up a gh app and triggered pull_request.edited and pull_request_review.submitted webhooks and the field was indeed present. It's also already present in the fixtures used in the tests. I'm assuming we can expect it for the majority of webhooks, unless the user somehow hasn't been "classified" already (?). If we can't find the user type we just assume the user isn't a bot (feedback welcome on this behavior).

srest2021 avatar Dec 04 '25 21:12 srest2021

:x: 1 Tests Failed:

Tests completed Failed Passed Skipped
29283 1 29282 234
View the top 1 failed test(s) by shortest run time
tests.sentry.integrations.github.test_utils.ShouldCreateOrIncrementContributorSeatTest::test_returns_false_when_seat_based_seer_disabled
Stack Traces | 2.5s run time
#x1B[1m#x1B[.../hostedtoolcache/Python/3.13.1........./x64/lib/python3.13/unittest/case.py#x1B[0m:58: in testPartExecutor
    yield
#x1B[1m#x1B[.../hostedtoolcache/Python/3.13.1........./x64/lib/python3.13/unittest/case.py#x1B[0m:651: in run
    self._callTestMethod(testMethod)
#x1B[1m#x1B[.../hostedtoolcache/Python/3.13.1........./x64/lib/python3.13/unittest/case.py#x1B[0m:606: in _callTestMethod
    if method() is not None:
#x1B[1m#x1B[31mE   TypeError: ShouldCreateOrIncrementContributorSeatTest.test_returns_false_when_seat_based_seer_disabled() missing 1 required positional argument: 'mock_quota'#x1B[0m

To view more test analytics, go to the Test Analytics Dashboard 📋 Got 3 mins? Take this short survey to help us improve Test Analytics.

codecov[bot] avatar Dec 04 '25 21:12 codecov[bot]