Conversation
Add `sentry project delete` subcommand for permanently deleting Sentry projects via the API. Safety measures: - Requires explicit target (no auto-detect to prevent accidental deletion) - Confirmation prompt with --yes/-y flag to skip - Refuses to run in non-interactive mode without --yes - Verifies project exists before prompting Changes: - src/commands/project/delete.ts: New command implementation - src/commands/project/index.ts: Register delete in route map - src/lib/api-client.ts: Add deleteProject() using @sentry/api SDK - test/commands/project/delete.test.ts: Unit tests (8 tests)
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 🐛Init
Other
Documentation 📚
Internal Changes 🔧Init
Other
Other
🤖 This preview updates automatically when you update the PR. |
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 92.73%. Project has 1077 uncovered lines. Files with missing lines (3)
Coverage diff@@ Coverage Diff @@
## main #PR +/-##
==========================================
- Coverage 95.02% 95.01% -0.01%
==========================================
Files 159 160 +1
Lines 21404 21569 +165
Branches 0 0 —
==========================================
+ Hits 20339 20492 +153
- Misses 1065 1077 +12
- Partials 0 0 —Generated by Codecov Action |
- Add 'project:admin' to OAuth SCOPES so new tokens include the permission required for project deletion - Catch 403 in project delete command and show actionable message pointing users to re-authenticate or check their org role - Existing tokens require re-login: sentry auth login
- 403 error now throws ApiError (preserving status/detail/endpoint) instead of CliError, so upstream handlers can still match on status - Add --dry-run / -n flag consistent with project create and other mutating commands — validates inputs and shows what would be deleted - Extract resolveDeleteTarget() to reduce func() complexity - Add 2 new dry-run tests (human + JSON output)
…teTarget Replace the custom resolveDeleteTarget() with the shared resolveOrgProjectTarget() from resolve-target.ts. Only the auto-detect guard remains delete-specific — all other resolution modes (explicit, project-search, org-all) are handled by the shared infrastructure. This also gains resolveEffectiveOrg() region routing for the explicit case, which the custom function was missing.
| const SCOPES = [ | ||
| "project:read", | ||
| "project:write", | ||
| "project:admin", |
There was a problem hiding this comment.
what would happen if someone doesn't have this permission? would it face trouble signing in?
Port deleteProject into src/lib/api/projects.ts and re-export from the barrel file, aligning with main's split of api-client into domain modules under src/lib/api/. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
Bugbot Autofix prepared a fix for the issue found in the latest run.
- ✅ Fixed: New OAuth scope may break login for non-admin users
- Removed project:admin from global OAuth SCOPES to prevent potentially breaking authentication for non-admin users, and updated the delete command's 403 error to direct users to contact their org admin instead.
Or push these changes by commenting:
@cursor push 3eb69e6f5d
Preview (3eb69e6f5d)
diff --git a/src/commands/project/delete.ts b/src/commands/project/delete.ts
--- a/src/commands/project/delete.ts
+++ b/src/commands/project/delete.ts
@@ -176,8 +176,8 @@
if (error instanceof ApiError && error.status === 403) {
throw new ApiError(
`Permission denied: You don't have permission to delete '${orgSlug}/${project.slug}'.\n\n` +
- "Project deletion requires the 'project:admin' scope.\n" +
- " Re-authenticate: sentry auth login",
+ "Project deletion requires the 'project:admin' permission.\n" +
+ "Contact your organization admin to grant you project admin access.",
403,
error.detail,
error.endpoint
diff --git a/src/lib/oauth.ts b/src/lib/oauth.ts
--- a/src/lib/oauth.ts
+++ b/src/lib/oauth.ts
@@ -52,7 +52,6 @@
const SCOPES = [
"project:read",
"project:write",
- "project:admin",
"org:read",
"event:read",
"event:write",
diff --git a/test/commands/project/delete.test.ts b/test/commands/project/delete.test.ts
--- a/test/commands/project/delete.test.ts
+++ b/test/commands/project/delete.test.ts
@@ -185,7 +185,7 @@
const apiErr = error as ApiError;
expect(apiErr.status).toBe(403);
expect(apiErr.message).toContain("project:admin");
- expect(apiErr.message).toContain("sentry auth login");
+ expect(apiErr.message).toContain("organization admin");
}
});This Bugbot Autofix run was free. To enable autofix for future PRs, go to the Cursor dashboard.
Convert project delete from manual stdout.write/JSON.stringify to the return-based OutputConfig pattern used by project create and other commands. Adds formatProjectDeleted formatter in human.ts, jsonTransform to preserve JSON contract, and role-aware 403 errors. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>


Summary
Add
sentry project deletesubcommand for permanently deleting Sentry projects via the API.Changes
src/commands/project/delete.ts— New command with safety measures:<org>/<project>or<project>target (no auto-detect)confirmed !== truecheck for Symbol(clack:cancel) gotcha)--yes/-yflag to skip confirmation for CI/agent usage--dry-run/-nflag to validate inputs and show what would be deleted without deleting--yesgetProject()before promptingApiErrorwith actionable message (preserves HTTP status for upstream handlers)src/commands/project/index.ts— Registereddeletein project route mapsrc/lib/api-client.ts— AddeddeleteProject()using@sentry/apiSDK'sdeleteAProjectsrc/lib/oauth.ts— Addedproject:adminto OAuth scopes (required for project deletion; existing users must re-runsentry auth login)test/commands/project/delete.test.ts— 10 unit tests covering happy path, error cases, dry-run, JSON output, and safety checksUsage
Notes
project:admin— users need to re-authenticate viasentry auth loginafter upgrading