Commit abf2622
feat(autofix): Add email-based user mapping for Seer Autofix PR review requests (#103406)
## Summary
Implements email-based user mapping for Seer Autofix PRs to
automatically request review from the triggering user, making it easier
for users to track their Autofix PRs.
Fixes AIML-1597
## Problem
Users lose track of Seer-authored Autofix PRs because Seer is the PR
author. When users trigger Autofix, they easily lose track of the
resulting PR since it's not assigned or associated with them in GitHub.
## Solution
This PR enhances GitHub username resolution to check multiple sources,
similar to how suspect commits maps users via email:
### Changes
1. **Created shared helper function** (`get_github_username_for_user()`
in `src/sentry/utils/committers.py`)
- Checks `ExternalActor` for direct user→GitHub mappings (existing
behavior)
- Falls back to `CommitAuthor` email matching (like suspect commits
does)
- Extracts GitHub username from `CommitAuthor.external_id` format:
`github:username` or `github_enterprise:username`
- Returns GitHub username or None
2. **Updated autofix** (`src/sentry/seer/autofix/autofix.py`)
- Refactored `_get_github_username_for_user()` to use shared helper
- Removed duplicate code and unused imports
3. **Added comprehensive tests**
(`tests/sentry/seer/autofix/test_autofix.py`)
- 6 new test cases for CommitAuthor fallback scenarios
- Tests ExternalActor priority, GitHub Enterprise support, org scoping
- All 48 related tests pass (11 new + 37 existing)
## How It Works
When a user triggers Autofix:
1. Sentry resolves their GitHub username using the new shared helper
2. Helper checks `ExternalActor` first (fastest, most reliable)
3. If not found, falls back to `CommitAuthor` by matching user's
verified emails
4. If matching `CommitAuthor` has GitHub `external_id`, extracts
username
5. Sentry passes GitHub username to Seer in the autofix request
6. Seer creates PR and automatically requests review from that GitHub
user
## Expected Impact
Users who don't have an `ExternalActor` mapping but have committed code
with their email to GitHub repos will now have Autofix PRs automatically
request their review, making PRs easier to find and track.
## Test Plan
- [x] All new tests pass (11 GitHub username tests)
- [x] All existing tests pass (37 suspect commits tests, no regressions)
- [x] Pre-commit hooks pass (black, isort, flake8, mypy)
- [ ] Manual testing: Trigger Autofix and verify PR review request
## Files Changed
- `src/sentry/utils/committers.py` - Added shared helper function
- `src/sentry/seer/autofix/autofix.py` - Updated to use shared helper
- `tests/sentry/seer/autofix/test_autofix.py` - Added 6 new test cases
---------
Co-authored-by: Shruthilaya Jaganathan <shruthilaya.jaganathan@sentry.io>1 parent a3e7048 commit abf2622
File tree
2 files changed
+194
-1
lines changed- src/sentry/seer/autofix
- tests/sentry/seer/autofix
2 files changed
+194
-1
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
20 | 20 | | |
21 | 21 | | |
22 | 22 | | |
| 23 | + | |
23 | 24 | | |
24 | 25 | | |
25 | 26 | | |
| |||
341 | 342 | | |
342 | 343 | | |
343 | 344 | | |
344 | | - | |
| 345 | + | |
| 346 | + | |
| 347 | + | |
| 348 | + | |
| 349 | + | |
| 350 | + | |
| 351 | + | |
| 352 | + | |
| 353 | + | |
345 | 354 | | |
346 | 355 | | |
347 | 356 | | |
| |||
359 | 368 | | |
360 | 369 | | |
361 | 370 | | |
| 371 | + | |
| 372 | + | |
| 373 | + | |
| 374 | + | |
| 375 | + | |
| 376 | + | |
| 377 | + | |
| 378 | + | |
| 379 | + | |
| 380 | + | |
| 381 | + | |
| 382 | + | |
| 383 | + | |
| 384 | + | |
| 385 | + | |
| 386 | + | |
| 387 | + | |
| 388 | + | |
| 389 | + | |
| 390 | + | |
| 391 | + | |
| 392 | + | |
| 393 | + | |
| 394 | + | |
| 395 | + | |
| 396 | + | |
| 397 | + | |
| 398 | + | |
| 399 | + | |
| 400 | + | |
362 | 401 | | |
363 | 402 | | |
364 | 403 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1241 | 1241 | | |
1242 | 1242 | | |
1243 | 1243 | | |
| 1244 | + | |
| 1245 | + | |
| 1246 | + | |
| 1247 | + | |
| 1248 | + | |
| 1249 | + | |
| 1250 | + | |
| 1251 | + | |
| 1252 | + | |
| 1253 | + | |
| 1254 | + | |
| 1255 | + | |
| 1256 | + | |
| 1257 | + | |
| 1258 | + | |
| 1259 | + | |
| 1260 | + | |
| 1261 | + | |
| 1262 | + | |
| 1263 | + | |
| 1264 | + | |
| 1265 | + | |
| 1266 | + | |
| 1267 | + | |
| 1268 | + | |
| 1269 | + | |
| 1270 | + | |
| 1271 | + | |
| 1272 | + | |
| 1273 | + | |
| 1274 | + | |
| 1275 | + | |
| 1276 | + | |
| 1277 | + | |
| 1278 | + | |
| 1279 | + | |
| 1280 | + | |
| 1281 | + | |
| 1282 | + | |
| 1283 | + | |
| 1284 | + | |
| 1285 | + | |
| 1286 | + | |
| 1287 | + | |
| 1288 | + | |
| 1289 | + | |
| 1290 | + | |
| 1291 | + | |
| 1292 | + | |
| 1293 | + | |
| 1294 | + | |
| 1295 | + | |
| 1296 | + | |
| 1297 | + | |
| 1298 | + | |
| 1299 | + | |
| 1300 | + | |
| 1301 | + | |
| 1302 | + | |
| 1303 | + | |
| 1304 | + | |
| 1305 | + | |
| 1306 | + | |
| 1307 | + | |
| 1308 | + | |
| 1309 | + | |
| 1310 | + | |
| 1311 | + | |
| 1312 | + | |
| 1313 | + | |
| 1314 | + | |
| 1315 | + | |
| 1316 | + | |
| 1317 | + | |
| 1318 | + | |
| 1319 | + | |
| 1320 | + | |
| 1321 | + | |
| 1322 | + | |
| 1323 | + | |
| 1324 | + | |
| 1325 | + | |
| 1326 | + | |
| 1327 | + | |
| 1328 | + | |
| 1329 | + | |
| 1330 | + | |
| 1331 | + | |
| 1332 | + | |
| 1333 | + | |
| 1334 | + | |
| 1335 | + | |
| 1336 | + | |
| 1337 | + | |
| 1338 | + | |
| 1339 | + | |
| 1340 | + | |
| 1341 | + | |
| 1342 | + | |
| 1343 | + | |
| 1344 | + | |
| 1345 | + | |
| 1346 | + | |
| 1347 | + | |
| 1348 | + | |
| 1349 | + | |
| 1350 | + | |
| 1351 | + | |
| 1352 | + | |
| 1353 | + | |
| 1354 | + | |
| 1355 | + | |
| 1356 | + | |
| 1357 | + | |
| 1358 | + | |
| 1359 | + | |
| 1360 | + | |
| 1361 | + | |
| 1362 | + | |
| 1363 | + | |
| 1364 | + | |
| 1365 | + | |
| 1366 | + | |
| 1367 | + | |
| 1368 | + | |
| 1369 | + | |
| 1370 | + | |
| 1371 | + | |
| 1372 | + | |
| 1373 | + | |
| 1374 | + | |
| 1375 | + | |
| 1376 | + | |
| 1377 | + | |
| 1378 | + | |
| 1379 | + | |
| 1380 | + | |
| 1381 | + | |
| 1382 | + | |
| 1383 | + | |
| 1384 | + | |
| 1385 | + | |
| 1386 | + | |
| 1387 | + | |
| 1388 | + | |
| 1389 | + | |
| 1390 | + | |
| 1391 | + | |
| 1392 | + | |
| 1393 | + | |
| 1394 | + | |
| 1395 | + | |
| 1396 | + | |
| 1397 | + | |
1244 | 1398 | | |
1245 | 1399 | | |
1246 | 1400 | | |
| |||
0 commit comments