feat(seer): Detect GitLab bots in contributor seat tracking#117762
Draft
billyvg wants to merge 1 commit into
Draft
feat(seer): Detect GitLab bots in contributor seat tracking#117762billyvg wants to merge 1 commit into
billyvg wants to merge 1 commit into
Conversation
Seer code-review seat billing tracks merge-request authors via
OrganizationContributors, and bot authors are filtered out by the
is_bot property. That property only recognized GitHub's convention
(alias ending in [bot], plus Copilot), so GitLab bots and service
accounts were counted as human contributors and could trigger code
reviews on bot-authored MRs.
GitLab's merge_request webhook exposes no bot flag, so detect bots
from the username persisted in alias using GitLab's reserved naming:
project access token bots (project_{id}_bot_), group access token
bots (group_{id}_bot_), and service accounts (service_account_).
GitHub usernames cannot contain underscores, so these patterns never
collide with a real GitHub login and the change stays additive.
Co-Authored-By: Claude <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Seer code-review seat billing tracks merge-request authors via
OrganizationContributors, and bot authors are filtered out by theis_botproperty. That property only recognized GitHub's convention (aliasending in[bot], plus theCopilotspecial case), so GitLab bots and service accounts were counted as human contributors — consuming seats and able to trigger code reviews on bot-authored MRs.GitLab's
merge_requestwebhook payload exposes no bot flag (theuserobject is only{id, name, username, avatar_url, email}), so we detect bots from the username already persisted inalias, mirroring how GitHub detection already works.What changed
OrganizationContributors.is_botnow also matches GitLab's reserved bot/service-account username prefixes viaGITLAB_BOT_USERNAME_RE:project_{id}_bot_…group_{id}_bot_…service_account_…/service_account_group_{id}_…is_botcovering GitHub bots, GitLab token/service-account bots, and human lookalikes (e.g.project_manager,my_project_42_bot_thing) that must not match.Why this is safe / additive
GitHub usernames cannot contain underscores, while every GitLab bot pattern is underscore-laden — so teaching the shared
is_botproperty the GitLab patterns cannot misclassify a real GitHub login. GitHub behavior is unchanged, and no migration is needed because the GitLab username is already stored inaliasby the seat-tracking processor.Test plan
pytest tests/sentry/models/test_organizationcontributors.py tests/sentry/seer/code_review/test_contributor_seats.py→ 35 passedruffclean; pre-commit hooks passNotes
botflag only exists onGET /users/:id, which we deliberately avoid to keep the webhook path synchronous and cheap.openaction and short-circuits whenlast_commit/author email is missing) are orthogonal to bot detection.