Skip to content

Feat/delete function#15

Open
jwfing wants to merge 3 commits intomainfrom
feat/delete-function
Open

Feat/delete function#15
jwfing wants to merge 3 commits intomainfrom
feat/delete-function

Conversation

@jwfing
Copy link
Contributor

@jwfing jwfing commented Mar 10, 2026

modify function deploy result, and add delete command

Summary by CodeRabbit

  • New Features

    • Added a delete command for edge functions that requires authentication, includes confirmation (or bypass via flags), supports JSON output, and reports success/failure clearly.
  • Improvements

    • Enhanced deployment feedback to show operation status, deployment URL on success, and build logs on failure; CLI exits with non-zero on failed deployments.
    • Improved JSON output formatting for function operations.

@coderabbitai
Copy link

coderabbitai bot commented Mar 10, 2026

Walkthrough

Adds a new CLI delete command for edge functions, introduces FunctionResponse and FunctionDeploymentResult types, and updates the deploy command to parse and display deployment results (status, URL, build logs) from the API response.

Changes

Cohort / File(s) Summary
Type Definitions
src/types.ts
Added FunctionDeploymentResult and FunctionResponse interfaces describing deployment result, function metadata, and optional build logs.
Delete Command
src/commands/functions/delete.ts
New registerFunctionsDeleteCommand(functionsCmd) implementing delete <slug>: enforces auth, confirmation prompt (skippable with -y/--json), issues DELETE /api/functions/{slug}, parses response as FunctionResponse, supports --json output, logs usage, and uses unified error handling.
Deploy Command Updates
src/commands/functions/deploy.ts
Parse API responses as FunctionResponse; return parsed result in --json mode; in normal mode, compute action/result from response, print deployment status, optional URL on success, and build logs on failure; report usage success/failure and exit with code 1 on deployment failure.
Command Registration
src/index.ts
Imported and registered registerFunctionsDeleteCommand to extend the functions command set with the delete operation.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

🐰 I nibbled at code and found a way,
A delete hop joins the functions play,
Types whisper where deployments tread,
Logs and URLs laid out ahead,
I dance — CLI tidy, bright, and gay.

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'Feat/delete function' refers to the main change—adding a delete command for functions—but uses a branch-naming convention format that is less appropriate for a PR title in commit history.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
  • 📝 Generate docstrings (stacked PR)
  • 📝 Generate docstrings (commit on current branch)
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch feat/delete-function

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 3

🧹 Nitpick comments (1)
src/commands/functions/delete.ts (1)

35-42: Drop the impossible result.success fallback.

FunctionResponse.success is true in src/types.ts, and ossFetch() already throws on non-OK responses, so Lines 38-42 are dead code. If that type is widened later, the fallback still emits a success marker for a failure message.

Proposed simplification
         if (json) {
           outputJson(result);
         } else {
-          if (result.success) {
-            outputSuccess(`Function "${slug}" deleted successfully.`);
-          } else {
-            outputSuccess(`Failed to delete function "${slug}".`);
-          }
+          outputSuccess(`Function "${slug}" deleted successfully.`);
         }
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/commands/functions/delete.ts` around lines 35 - 42, The code contains a
dead fallback branch checking result.success (FunctionResponse.success is always
true and ossFetch throws on errors), so remove the impossible else branch and
simplify: after outputJson(result) when json is true, otherwise unconditionally
call outputSuccess(`Function "${slug}" deleted successfully.`) and drop the
`else { outputSuccess("Failed...") }` branch; reference symbols: delete.ts,
result, slug, outputJson, outputSuccess, FunctionResponse.success, and ossFetch.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@src/commands/functions/delete.ts`:
- Around line 15-17: The command currently calls requireAuth() without passing
the CLI API URL override extracted via getRootOpts(cmd), so authentication may
target the default platform; update the call in delete.ts to extract the apiUrl
from getRootOpts (alongside json and yes) and pass it into requireAuth (e.g.,
requireAuth({ apiUrl })) or otherwise forward that apiUrl option into your auth
call so the command honors --api-url during authentication.
- Line 8: The import of FunctionResponse should be type-only and the variable
res is never reassigned—update the import to a type import (e.g., import type {
FunctionResponse } from '../../types.js') and change the declaration of res from
let to const where it is assigned (the res used as the FunctionResponse-typed
response in delete.ts).

In `@src/commands/functions/deploy.ts`:
- Around line 61-80: The code currently treats the API envelope result as
success and always calls reportCliUsage('cli.functions.deploy', true) and exits
0 even when result.deployment.status === 'failed'; change the branch after
printing deployment output to detect a failing deployment (check
result.deployment && result.deployment.status === 'failed') and in that case
call reportCliUsage('cli.functions.deploy', false) and exit with a non-zero code
(e.g., process.exit(1)) — also ensure the same behavior applies in JSON mode by
emitting the failing status via outputJson(result) then exiting non‑zero so
CI/scripts see the failure; adjust any uses of result.success to prefer
result.deployment.status when deciding final exit/usage state.

---

Nitpick comments:
In `@src/commands/functions/delete.ts`:
- Around line 35-42: The code contains a dead fallback branch checking
result.success (FunctionResponse.success is always true and ossFetch throws on
errors), so remove the impossible else branch and simplify: after
outputJson(result) when json is true, otherwise unconditionally call
outputSuccess(`Function "${slug}" deleted successfully.`) and drop the `else {
outputSuccess("Failed...") }` branch; reference symbols: delete.ts, result,
slug, outputJson, outputSuccess, FunctionResponse.success, and ossFetch.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: f7562b5d-a7fc-4c9b-8715-bb09e45bc7c2

📥 Commits

Reviewing files that changed from the base of the PR and between 11e8ada and 3ad06ec.

📒 Files selected for processing (4)
  • src/commands/functions/delete.ts
  • src/commands/functions/deploy.ts
  • src/index.ts
  • src/types.ts

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

♻️ Duplicate comments (1)
src/commands/functions/deploy.ts (1)

65-67: ⚠️ Potential issue | 🟡 Minor

Misleading success message when deployment fails.

Two issues here:

  1. Grammar: "updation" is non-standard English; use "update" or "creation" → "update" / "create".

  2. Misleading output: result.success is typed as literal true in FunctionResponse, so resultStatus will always be 'success'. When deployFailed is true, the user sees:

    ✓ Function "foo" creation success.
      Deployment: failed
    

    This is confusing—showing a checkmark and "success" while the deployment actually failed.

The exit code fix (lines 82-83) addresses the CI/scripting concern from the previous review, but the human-readable output remains misleading.

Proposed fix for clearer messaging
-        const action = exists ? 'updation' : 'creation';
-        const resultStatus = result.success ? 'success' : 'failed';
-        outputSuccess(`Function "${result.function.slug}" ${action} ${resultStatus}.`);
+        const action = exists ? 'updated' : 'created';
+        if (deployFailed) {
+          console.error(`✗ Function "${result.function.slug}" ${action}, but deployment failed.`);
+        } else {
+          outputSuccess(`Function "${result.function.slug}" ${action} successfully.`);
+        }
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/commands/functions/deploy.ts` around lines 65 - 67, Replace the
non-standard "updation" with "update" (use "update" when exists is true,
otherwise "create") and stop using result.success (which is always true) to
determine the user-facing status; instead use the actual deploy result flag
(deployFailed) to choose the message and output function. Locate the block that
builds action and resultStatus (references: exists, result.success,
outputSuccess) and change it to compute action = exists ? 'update' : 'create',
compute status = deployFailed ? 'failed' : 'success', and call the appropriate
output helper (e.g., outputSuccess when success, outputError or outputInfo when
failed) so the terminal message and checkmark reflect the real deployment
outcome. Ensure the printed message still includes result.function.slug.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Duplicate comments:
In `@src/commands/functions/deploy.ts`:
- Around line 65-67: Replace the non-standard "updation" with "update" (use
"update" when exists is true, otherwise "create") and stop using result.success
(which is always true) to determine the user-facing status; instead use the
actual deploy result flag (deployFailed) to choose the message and output
function. Locate the block that builds action and resultStatus (references:
exists, result.success, outputSuccess) and change it to compute action = exists
? 'update' : 'create', compute status = deployFailed ? 'failed' : 'success', and
call the appropriate output helper (e.g., outputSuccess when success,
outputError or outputInfo when failed) so the terminal message and checkmark
reflect the real deployment outcome. Ensure the printed message still includes
result.function.slug.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 9f439ca4-dc95-4f9e-9e1a-ce3d608623ad

📥 Commits

Reviewing files that changed from the base of the PR and between 3ad06ec and 9134685.

📒 Files selected for processing (2)
  • src/commands/functions/delete.ts
  • src/commands/functions/deploy.ts
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/commands/functions/delete.ts

@jwfing jwfing requested a review from tonychang04 March 11, 2026 00:06
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