fix(init): prompt for team selection when user belongs to multiple teams#621
Merged
fix(init): prompt for team selection when user belongs to multiple teams#621
Conversation
When users belong to more than one team, `sentry init` would fail during project creation with "Team is required" after minutes of setup. Now resolves the team interactively in `resolvePreSpinnerOptions()` before the spinner starts, so the prompt appears early alongside org selection. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Contributor
Semver Impact of This PR🟢 Patch (bug fixes) 📋 Changelog PreviewThis is how your changes will appear in the changelog. New Features ✨
Bug Fixes 🐛
Internal Changes 🔧
🤖 This preview updates automatically when you update the PR. |
Sort imports and use type assertion instead of non-null assertion to match existing codebase patterns. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
File is in src/lib/init/, so types need ../../types/ not ../types/. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
The team selection code calls listTeams() which triggers real API calls through the authenticated fetch chain, causing tests to hang. Mock it following the same pattern as local-ops.create-sentry-project.test.ts. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Contributor
Codecov Results 📊✅ 129 passed | Total: 129 | Pass Rate: 100% | Execution Time: 0ms 📊 Comparison with Base Branch
✨ No test changes detected All tests are passing successfully. ✅ Patch coverage is 100.00%. Project has 1291 uncovered lines. Coverage diff@@ Coverage Diff @@
## main #PR +/-##
==========================================
+ Coverage 95.65% 95.67% +0.02%
==========================================
Files 204 204 —
Lines 29769 29785 +16
Branches 0 0 —
==========================================
+ Hits 28472 28494 +22
- Misses 1297 1291 -6
- Partials 0 0 —Generated by Codecov Action |
Previously, when a user had no team memberships, --yes mode would arbitrarily pick the first org team, which could cause 403 errors during project creation. Now only member teams are considered for auto-selection; if there are none, we defer to resolveOrCreateTeam which surfaces a proper error. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This reverts commit 4509155.
…scope The primary use case for sentry init is new users who just signed up — they have an org but no teams and no projects. Previously this failed with a cryptic 403 deep in the workflow because: 1. The OAuth token lacked team:write scope (even Owners couldn't create teams via CLI) 2. The 0-teams case was only handled after minutes of AI analysis Now: - Added team:write to OAuth scopes so team creation works - All team scenarios are resolved in resolvePreSpinnerOptions (before the spinner), not just the multi-team case: - 0 teams: auto-create one (named after user or org) - 1 team: auto-select it - Multiple teams: prompt to pick (or auto-select with --yes) - If team creation fails (e.g. permissions), shows a friendly error with a link to create a team in the UI Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Both the team auto-creation failure (403) and the listTeams API error are now reported via captureException with org/context metadata, even when the error is the user's fault — helps track onboarding friction. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
The helper was inserted between the JSDoc block and its function, orphaning the documentation. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Contributor
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
This was referenced Apr 1, 2026
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
sentry initfailed for most new users — people who just signed up on sentry.io and ran the wizard. The root causes:team:writescope, so even org Owners couldn't create teamsNow all team scenarios are resolved early in
resolvePreSpinnerOptions(), right after org selection and before the spinner starts. Also addedteam:writeto the OAuth scopes.All team scenarios handled
--yes--yes--teamflag providedresolveOrCreateTeamas fallbackTest plan
sentry loginthensentry initon org with 0 teams → auto-creates "default" team, proceedssentry initon org with 1 team → no prompt, auto-selectssentry initon org with multiple teams → shows team selection promptsentry init --team <slug>→ skips promptsentry init --yeson org with multiple teams → auto-selects first member teamsentry loginagain to get the newteam:writescope🤖 Generated with Claude Code