feat(init): support org/project positional to pin org and project name#428
Open
MathurAditya724 wants to merge 10 commits intomainfrom
Open
feat(init): support org/project positional to pin org and project name#428MathurAditya724 wants to merge 10 commits intomainfrom
MathurAditya724 wants to merge 10 commits intomainfrom
Conversation
Replace the directory positional with an org/project target using parseOrgProjectArg. Directory is now a --directory/-d flag. Supported forms: sentry init — auto-detect everything sentry init acme — explicit org sentry init acme/my-app — explicit org + project name sentry init --directory ./dir — specify project directory When org is provided explicitly, createSentryProject skips interactive org resolution. When project name is provided, it overrides the wizard-detected name.
Contributor
Semver Impact of This PR🟡 Minor (new features) 📋 Changelog PreviewThis is how your changes will appear in the changelog. New Features ✨Init
Issue List
Other
Bug Fixes 🐛Dsn
Init
Other
Documentation 📚
Internal Changes 🔧Init
Tests
Other
Other
🤖 This preview updates automatically when you update the PR. |
Contributor
Codecov Results 📊✅ 111 passed | Total: 111 | 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 1101 uncovered lines. Files with missing lines (1)
Coverage diff@@ Coverage Diff @@
## main #PR +/-##
==========================================
+ Coverage 95.02% 95.04% +0.02%
==========================================
Files 163 163 —
Lines 22103 22194 +91
Branches 0 0 —
==========================================
+ Hits 21002 21093 +91
- Misses 1101 1101 —
- Partials 0 0 —Generated by Codecov Action |
Bare strings like 'sentry init acme' are ambiguous (could be org or project slug). Now throws a ContextError with a disambiguation hint telling users to use 'acme/' for org or 'acme/<project>' for both. Also validates explicit org and project slugs via validateResourceId to catch malformed input (control chars, whitespace, etc.) early before API calls.
Show which organization is being used during the init wizard: - Explicit org from CLI arg: shown at startup before the spinner - Auto-detected/selected org: shown after resolution in createSentryProject Uses @clack/prompts log.info for consistent styling with other wizard messages.
Redesign init command to accept two optional positionals: sentry init [target] [directory] Path-like args (starting with . / ~) are treated as the directory; everything else is treated as the org/project target. When args are in the wrong order (path first, target second), they are auto-swapped with a warning — following the established swap pattern from view commands. Bare slugs (e.g., 'sentry init my-app') are resolved via resolveProjectBySlug to search across all accessible orgs, setting both org and project from the match. Add looksLikePath() to arg-parsing.ts for syntactic path detection (no filesystem I/O). Remove the --directory flag in favor of the second positional.
Move validateResourceId into resolveTarget so it only runs on user-provided values (explicit and org-all cases), not on API-resolved slugs from resolveProjectBySlug. Tighten looksLikePath to match ~ only as '~' or '~/' — not '~foo', which could be a valid slug. Rename misleading test accordingly.
Drop logExplicitTarget() from wizard-runner.ts and the log.info() call after org resolution in local-ops.ts. This keeps the PR focused on the arg parsing changes.
When both org and project are explicitly provided (e.g., from resolveProjectBySlug resolving a bare slug), check if the project already exists via getProject before attempting to create it. This avoids a 409 Conflict from the create API when re-running init on an existing Sentry project. Also extract resolveOrgForInit and formatLocalOpError helpers to keep createSentryProject under the cognitive complexity limit.
Inline the org resolution back into createSentryProject. The formatLocalOpError extraction alone keeps the function under the cognitive complexity limit.
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
Redesign
sentry initto support smart positional arguments for org/project targeting and directory specification.Supported forms
Design
Two optional positionals with smart disambiguation:
./~~/) are treated as the directorymy-app) are resolved viaresolveProjectBySlugto search across all accessible orgs, setting both org and project from the matchvalidateResourceIdat parse time; API-resolved values fromresolveProjectBySlugskip redundant validationFiles changed
src/lib/arg-parsing.tslooksLikePath()for syntactic path detection (no filesystem I/O)src/commands/init.tsclassifyArgs()disambiguation,resolveTarget()withresolveProjectBySlugfor bare slugs,validateResourceIdon user-provided slugs onlysrc/lib/init/types.tsorg?andproject?toWizardOptionssrc/lib/init/local-ops.tsoptions.org/options.projectincreateSentryProject()to skip interactive org resolution and override wizard-detected project nametest/commands/init.test.tsBreaking change
sentry init <directory>no longer works for bare directory names (e.g.,sentry init mydir). Use path syntax:sentry init ./mydir.