Skip to content

feat(init): support org/project positional to pin org and project name#428

Open
MathurAditya724 wants to merge 10 commits intomainfrom
fix/init-org
Open

feat(init): support org/project positional to pin org and project name#428
MathurAditya724 wants to merge 10 commits intomainfrom
fix/init-org

Conversation

@MathurAditya724
Copy link
Member

@MathurAditya724 MathurAditya724 commented Mar 16, 2026

Summary

Redesign sentry init to support smart positional arguments for org/project targeting and directory specification.

Supported forms

sentry init                           # auto-detect everything, dir = cwd
sentry init .                         # dir = cwd, auto-detect org
sentry init ./subdir                  # dir = subdir, auto-detect org
sentry init acme/                     # explicit org, dir = cwd
sentry init acme/my-app               # explicit org + project, dir = cwd
sentry init my-app                    # search for project across orgs → sets org + project
sentry init acme/ ./subdir            # explicit org, dir = subdir
sentry init acme/my-app ./subdir      # explicit org + project, dir = subdir
sentry init ./subdir acme/            # swapped → auto-correct with warning
sentry init ./subdir acme/my-app      # swapped → auto-correct with warning

Design

Two optional positionals with smart disambiguation:

  • Path-like args (starting with . / ~ ~/) are treated as the directory
  • Everything else is treated as the org/project target
  • When args are in 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., my-app) are resolved via resolveProjectBySlug to search across all accessible orgs, setting both org and project from the match
  • Two paths or two targets → error with helpful message
  • User-provided org/project slugs are validated via validateResourceId at parse time; API-resolved values from resolveProjectBySlug skip redundant validation

Files changed

File Change
src/lib/arg-parsing.ts Add looksLikePath() for syntactic path detection (no filesystem I/O)
src/commands/init.ts Two positionals, classifyArgs() disambiguation, resolveTarget() with resolveProjectBySlug for bare slugs, validateResourceId on user-provided slugs only
src/lib/init/types.ts Add org? and project? to WizardOptions
src/lib/init/local-ops.ts Use options.org/options.project in createSentryProject() to skip interactive org resolution and override wizard-detected project name
test/commands/init.test.ts 26 tests covering all arg combinations, swap detection, error cases

Breaking change

sentry init <directory> no longer works for bare directory names (e.g., sentry init mydir). Use path syntax: sentry init ./mydir.

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.
@github-actions
Copy link
Contributor

github-actions bot commented Mar 16, 2026

Semver Impact of This PR

🟡 Minor (new features)

📋 Changelog Preview

This is how your changes will appear in the changelog.
Entries from this PR are highlighted with a left border (blockquote style).


New Features ✨

Init

  • Support org/project positional to pin org and project name by MathurAditya724 in #428
  • Show feedback hint after successful setup by betegon in #430
  • Add --team flag to relay team selection to project creation by MathurAditya724 in #403
  • Enforce canonical feature display order by betegon in #388
  • Accept multiple delimiter formats for --features flag by betegon in #386
  • Add git safety checks before wizard modifies files by betegon in #379
  • Add experimental warning before wizard runs by betegon in #378
  • Add init command for guided Sentry project setup by betegon in #283

Issue List

  • Auto-compact when table exceeds terminal height by BYK in #395
  • Redesign table to match Sentry web UI by BYK in #372

Other

  • (auth) Allow re-authentication without manual logout by BYK in #417
  • (trial) Auto-prompt for Seer trial + sentry trial list/start commands by BYK in #399
  • Add sentry span list and sentry span view commands by betegon in #393
  • Support SENTRY_HOST as alias for SENTRY_URL by betegon in #409
  • Add --dry-run flag to mutating commands by BYK in #387
  • Return-based output with OutputConfig on buildCommand by BYK in #380
  • Add --fields flag for context-window-friendly JSON output by BYK in #373
  • Magic @ selectors (@latest, @most_frequent) for issue commands by BYK in #371
  • Input hardening against agent hallucinations by BYK in #370
  • Add response caching for read-only API calls by BYK in #330

Bug Fixes 🐛

Dsn

Init

  • Make URLs clickable with OSC 8 terminal hyperlinks by MathurAditya724 in #423
  • Remove implementation detail from help text by betegon in #385
  • Truncate uncommitted file list to first 5 entries by MathurAditya724 in #381

Other

  • (api) Convert --data to query params for GET requests by BYK in #383
  • (docs) Remove double borders and fix column alignment on landing page tables by betegon in #369
  • (trace) Show span IDs in trace view and fix event_id mapping by betegon in #400
  • Show human-friendly names in trial list and surface plan trials by BYK in #412
  • Add trace ID validation to trace view + UUID dash-stripping by BYK in #375

Documentation 📚

  • Update AGENTS.md with patterns from span commands work by BYK in #433
  • Update credential storage docs and remove stale config.json references by betegon in #408

Internal Changes 🔧

Init

  • Remove --force flag by betegon in #377
  • Remove dead determine-pm step label by betegon in #374

Tests

  • Consolidate unit tests subsumed by property tests by BYK in #422
  • Remove redundant and low-value tests by BYK in #418

Other

  • (log/list) Convert non-follow paths to return CommandOutput by BYK in #410
  • Unify commands as generators with HumanRenderer factory, remove stdout plumbing by BYK in #416
  • Convert list command handlers to return data instead of writing stdout by BYK in #404
  • Split api-client.ts into focused domain modules by BYK in #405
  • Migrate non-streaming commands to CommandOutput with markdown rendering by BYK in #398
  • Convert Tier 2-3 commands to return-based output and consola by BYK in #394
  • Convert remaining Tier 1 commands to return-based output by BYK in #382
  • Converge Tier 1 commands to writeOutput helper by BYK in #376

Other

  • Minify JSON on read and pretty-print on write in init local ops by MathurAditya724 in #396

🤖 This preview updates automatically when you update the PR.

@github-actions
Copy link
Contributor

github-actions bot commented Mar 16, 2026

Codecov Results 📊

111 passed | Total: 111 | Pass Rate: 100% | Execution Time: 0ms

📊 Comparison with Base Branch

Metric Change
Total Tests
Passed Tests
Failed Tests
Skipped Tests

✨ No test changes detected

All tests are passing successfully.

✅ Patch coverage is 100.00%. Project has 1101 uncovered lines.
✅ Project coverage is 95.04%. Comparing base (base) to head (head).

Files with missing lines (1)
File Patch % Lines
arg-parsing.ts 93.97% ⚠️ 19 Missing
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

MathurAditya724 and others added 6 commits March 16, 2026 16:38
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.
@MathurAditya724 MathurAditya724 marked this pull request as ready for review March 16, 2026 18:05
@MathurAditya724 MathurAditya724 requested review from BYK and betegon March 16, 2026 18:06
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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant