-
-
Notifications
You must be signed in to change notification settings - Fork 2
feat: add project delete command #397
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
MathurAditya724
wants to merge
8
commits into
main
Choose a base branch
from
feat/adi/project-delete
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
72292f9
feat: add project delete command
MathurAditya724 dcc0f2d
chore: regenerate SKILL.md
github-actions[bot] 6d26185
fix: add project:admin scope and improve 403 error handling
MathurAditya724 1023888
fix: simplify 403 error message to only suggest re-authentication
MathurAditya724 e6b5a2b
fix: preserve ApiError on 403 and add --dry-run support
MathurAditya724 910b59f
chore: regenerate SKILL.md
github-actions[bot] b0fed2e
chore: trigger CI
MathurAditya724 95a87b9
refactor: reuse resolveOrgProjectTarget instead of custom resolveDele…
MathurAditya724 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,199 @@ | ||
| /** | ||
| * sentry project delete | ||
| * | ||
| * Permanently delete a Sentry project. | ||
| * | ||
| * ## Flow | ||
| * | ||
| * 1. Parse target arg → extract org/project (e.g., "acme/my-app" or "my-app") | ||
| * 2. Verify the project exists via `getProject` (also displays its name) | ||
| * 3. Prompt for confirmation (unless --yes is passed) | ||
| * 4. Call `deleteProject` API | ||
| * 5. Display result | ||
| * | ||
| * Safety measures: | ||
| * - No auto-detect mode: requires explicit target to prevent accidental deletion | ||
| * - Confirmation prompt with strict `confirmed !== true` check (Symbol(clack:cancel) gotcha) | ||
| * - Refuses to run in non-interactive mode without --yes flag | ||
| */ | ||
|
|
||
| import { isatty } from "node:tty"; | ||
| import type { SentryContext } from "../../context.js"; | ||
| import { deleteProject, getProject } from "../../lib/api-client.js"; | ||
| import { parseOrgProjectArg } from "../../lib/arg-parsing.js"; | ||
| import { buildCommand } from "../../lib/command.js"; | ||
| import { ApiError, CliError, ContextError } from "../../lib/errors.js"; | ||
| import { logger } from "../../lib/logger.js"; | ||
| import { resolveOrgProjectTarget } from "../../lib/resolve-target.js"; | ||
| import { buildProjectUrl } from "../../lib/sentry-urls.js"; | ||
|
|
||
| const log = logger.withTag("project.delete"); | ||
|
|
||
| /** Command name used in error messages and resolution hints */ | ||
| const COMMAND_NAME = "project delete"; | ||
|
|
||
| /** | ||
| * Prompt for confirmation before deleting a project. | ||
| * | ||
| * Throws in non-interactive mode without --yes. Returns true if confirmed, | ||
| * false if the user cancels. | ||
| * | ||
| * @param orgSlug - Organization slug for display | ||
| * @param project - Project with slug and name for display | ||
| * @returns true if confirmed, false if cancelled | ||
| */ | ||
| async function confirmDeletion( | ||
| orgSlug: string, | ||
| project: { slug: string; name: string } | ||
| ): Promise<boolean> { | ||
| if (!isatty(0)) { | ||
| throw new CliError( | ||
| `Refusing to delete '${orgSlug}/${project.slug}' in non-interactive mode. Use --yes to confirm.` | ||
| ); | ||
| } | ||
|
|
||
| const confirmed = await log.prompt( | ||
| `Delete project '${project.name}' (${orgSlug}/${project.slug})? This cannot be undone.`, | ||
| { type: "confirm", initial: false } | ||
| ); | ||
|
|
||
| // consola prompt returns Symbol(clack:cancel) on Ctrl+C — a truthy value. | ||
| // Strictly check for `true` to avoid deleting on cancel. | ||
| return confirmed === true; | ||
| } | ||
|
|
||
| /** | ||
| * Write dry-run output describing what would be deleted. | ||
| * | ||
| * @param stdout - Output stream | ||
| * @param orgSlug - Organization slug | ||
| * @param project - Project details | ||
| * @param json - Whether to output JSON | ||
| */ | ||
| function writeDryRunOutput( | ||
| stdout: { write: (s: string) => unknown }, | ||
| orgSlug: string, | ||
| project: { slug: string; name: string }, | ||
| json: boolean | ||
| ): void { | ||
| if (json) { | ||
| stdout.write( | ||
| `${JSON.stringify({ dryRun: true, org: orgSlug, project: project.slug, name: project.name, url: buildProjectUrl(orgSlug, project.slug) })}\n` | ||
| ); | ||
| } else { | ||
| stdout.write( | ||
| `Would delete project '${project.name}' (${orgSlug}/${project.slug}).\n` + | ||
| ` URL: ${buildProjectUrl(orgSlug, project.slug)}\n` | ||
| ); | ||
| } | ||
| } | ||
|
|
||
| type DeleteFlags = { | ||
| readonly yes: boolean; | ||
| readonly "dry-run": boolean; | ||
| readonly json: boolean; | ||
| readonly fields?: string[]; | ||
| }; | ||
|
|
||
| export const deleteCommand = buildCommand({ | ||
| docs: { | ||
| brief: "Delete a project", | ||
| fullDescription: | ||
| "Permanently delete a Sentry project. This action cannot be undone.\n\n" + | ||
| "Requires explicit target — auto-detection is disabled for safety.\n\n" + | ||
| "Examples:\n" + | ||
| " sentry project delete acme-corp/my-app\n" + | ||
| " sentry project delete my-app\n" + | ||
| " sentry project delete acme-corp/my-app --yes\n" + | ||
| " sentry project delete acme-corp/my-app --dry-run", | ||
| }, | ||
| output: "json", | ||
| parameters: { | ||
| positional: { | ||
| kind: "tuple", | ||
| parameters: [ | ||
| { | ||
| placeholder: "org/project", | ||
| brief: "<org>/<project> or <project> (search across orgs)", | ||
| parse: String, | ||
| }, | ||
| ], | ||
| }, | ||
| flags: { | ||
| yes: { | ||
| kind: "boolean", | ||
| brief: "Skip confirmation prompt", | ||
| default: false, | ||
| }, | ||
| "dry-run": { | ||
| kind: "boolean", | ||
| brief: | ||
| "Validate inputs and show what would be deleted without deleting it", | ||
| default: false, | ||
| }, | ||
| }, | ||
| aliases: { y: "yes", n: "dry-run" }, | ||
| }, | ||
| async func(this: SentryContext, flags: DeleteFlags, target: string) { | ||
| const { stdout, cwd } = this; | ||
|
|
||
| // Block auto-detect for safety — destructive commands require explicit targets | ||
| const parsed = parseOrgProjectArg(target); | ||
| if (parsed.type === "auto-detect") { | ||
| throw new ContextError( | ||
| "Project target", | ||
| `sentry ${COMMAND_NAME} <org>/<project>`, | ||
| [ | ||
| "Auto-detection is disabled for delete — specify the target explicitly", | ||
| ] | ||
| ); | ||
| } | ||
|
|
||
| const { org: orgSlug, project: projectSlug } = | ||
| await resolveOrgProjectTarget(parsed, cwd, COMMAND_NAME); | ||
|
|
||
| // Verify project exists before prompting — also used to display the project name | ||
| const project = await getProject(orgSlug, projectSlug); | ||
|
|
||
| // Dry-run mode: show what would be deleted without deleting it | ||
| if (flags["dry-run"]) { | ||
| writeDryRunOutput(stdout, orgSlug, project, flags.json); | ||
| return; | ||
| } | ||
|
|
||
| // Confirmation gate | ||
| if (!flags.yes) { | ||
| const confirmed = await confirmDeletion(orgSlug, project); | ||
| if (!confirmed) { | ||
| stdout.write("Cancelled.\n"); | ||
| return; | ||
| } | ||
| } | ||
|
|
||
| try { | ||
| await deleteProject(orgSlug, project.slug); | ||
| } catch (error) { | ||
| 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", | ||
| 403, | ||
| error.detail, | ||
| error.endpoint | ||
| ); | ||
| } | ||
| throw error; | ||
| } | ||
|
|
||
| if (flags.json) { | ||
| stdout.write( | ||
| `${JSON.stringify({ deleted: true, org: orgSlug, project: project.slug })}\n` | ||
| ); | ||
| } else { | ||
| stdout.write( | ||
| `Deleted project '${project.name}' (${orgSlug}/${project.slug}).\n` | ||
| ); | ||
| } | ||
| }, | ||
| }); |
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
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
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
Oops, something went wrong.
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what would happen if someone doesn't have this permission? would it face trouble signing in?