Skip to content

Conversation

@adityachoudhari26
Copy link
Contributor

@adityachoudhari26 adityachoudhari26 commented May 6, 2025

Summary by CodeRabbit

  • New Features

    • Approval checks now provide a simplified status display, showing a clear "Not enough approvals" message when requirements are not met.
    • Approval actions are still available, but detailed rejection reasons are no longer shown in tooltips.
  • Bug Fixes

    • Improved accuracy of version selector checks for deployment versions.
  • Refactor

    • Approval and version selector checks now use a unified policy evaluation approach for more consistent results.
  • Chores

    • Removed deny window checks and related UI elements.
    • Streamlined environment data fetching for deployment checks.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented May 6, 2025

Walkthrough

This change removes the legacy deployment version checks API and associated React components, refactoring the frontend to use a new unified policy evaluation API for approval and version selector checks. Approval record mutations are now handled via a new endpoint. Deny window checks and related utilities are deleted, and environment data is now derived from release targets.

Changes

File(s) Change Summary
.../checks/Approval.tsx, .../checks/VersionSelector.tsx Refactored to use api.policy.evaluate.useQuery for policy evaluation; updated approval/version selector logic and removed rejection tooltips.
.../checks/_components/flow-diagram/checks/DenyWindow.tsx, .../checks/_components/flow-diagram/nodes/EnvironmentNode.tsx Deleted DenyWindowCheck component and its usage in EnvironmentNode.
.../checks/page.tsx Changed environment fetching to derive from release targets instead of a dedicated environments-to-check API.
.../deployment-version/ApprovalDialog.tsx Updated approval record mutation to use new addApprovalRecord endpoint.
packages/api/src/router/deployment-version-checks/* Deleted legacy deployment version checks routers, utilities, and related API endpoints.
packages/api/src/router/deployment-version.ts Removed checks sub-router; added new addApprovalRecord mutation to versionRouter.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant ApprovalCheck (React)
    participant PolicyEvalAPI
    participant ApprovalDialog (React)
    participant AddApprovalRecordAPI

    User->>ApprovalCheck (React): View approval status
    ApprovalCheck (React)->>PolicyEvalAPI: Evaluate approval policy
    PolicyEvalAPI-->>ApprovalCheck (React): Return approval status

    User->>ApprovalDialog (React): Submit approval
    ApprovalDialog (React)->>AddApprovalRecordAPI: addApprovalRecord mutation
    AddApprovalRecordAPI-->>ApprovalDialog (React): Return approval record
Loading

Possibly related PRs

Suggested reviewers

  • jsbroks

Poem

In the warren, code hops anew,
Old checks are gone—now policy is true.
Approval flows with a single call,
While DenyWindow takes no role at all.
The rabbits cheer, the carrots stack,
For simpler checks and a streamlined track! 🥕

✨ Finishing Touches
  • 📝 Generate Docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@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: 0

🧹 Nitpick comments (3)
packages/api/src/router/deployment-version.ts (3)

391-396: Consider using a more specific permission for approval actions.

While using DeploymentVersionGet permission works, since this is a mutation that creates an approval record, it might be more semantically appropriate to check for a more specific permission like DeploymentVersionApprove if such a permission exists in your permission model.


397-411: Consider wrapping database operations in a transaction.

The procedure performs multiple database operations (insert approval record, query release targets). To ensure atomicity, consider wrapping these operations in a transaction to prevent partial updates if an error occurs.

.mutation(async ({ ctx, input }) => {
  const { deploymentVersionId, environmentId, status, reason } = input;

+  return await ctx.db.transaction(async (tx) => {
-  const record = await ctx.db
+    const record = await tx
      .insert(SCHEMA.policyRuleAnyApprovalRecord)
      .values({
        deploymentVersionId,
        userId: ctx.session.user.id,
        status,
        reason,
        approvedAt:
          status === SCHEMA.ApprovalStatus.Approved ? new Date() : null,
      })
      .returning();

-  const rows = await ctx.db
+    const rows = await tx
      // Rest of the query...
      
    // Queue operations and return record
+    return record;
+  });
});

412-436: Add error handling for queue operations.

When adding jobs to the evaluation queue, there's no explicit error handling. While the coding guidelines allow for this, it would be beneficial to add explicit error handling for queue operations since they're external system calls.

if (targets.length > 0)
-  await getQueue(Channel.EvaluateReleaseTarget).addBulk(
-    targets.map((rt) => ({
-      name: `${rt.resourceId}-${rt.environmentId}-${rt.deploymentId}`,
-      data: rt,
-    })),
-  );
+  try {
+    await getQueue(Channel.EvaluateReleaseTarget).addBulk(
+      targets.map((rt) => ({
+        name: `${rt.resourceId}-${rt.environmentId}-${rt.deploymentId}`,
+        data: rt,
+      })),
+    );
+  } catch (error) {
+    console.error("Failed to add evaluation jobs to queue:", error);
+    // Consider how to handle this error - rethrow or continue
+  }
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between b5475ea and 1f2c1cc.

📒 Files selected for processing (12)
  • apps/webservice/src/app/[workspaceSlug]/(app)/(deploy)/(raw)/systems/[systemSlug]/(raw)/deployments/[deploymentSlug]/(raw)/releases/[releaseId]/checks/_components/flow-diagram/checks/Approval.tsx (1 hunks)
  • apps/webservice/src/app/[workspaceSlug]/(app)/(deploy)/(raw)/systems/[systemSlug]/(raw)/deployments/[deploymentSlug]/(raw)/releases/[releaseId]/checks/_components/flow-diagram/checks/DenyWindow.tsx (0 hunks)
  • apps/webservice/src/app/[workspaceSlug]/(app)/(deploy)/(raw)/systems/[systemSlug]/(raw)/deployments/[deploymentSlug]/(raw)/releases/[releaseId]/checks/_components/flow-diagram/checks/VersionSelector.tsx (1 hunks)
  • apps/webservice/src/app/[workspaceSlug]/(app)/(deploy)/(raw)/systems/[systemSlug]/(raw)/deployments/[deploymentSlug]/(raw)/releases/[releaseId]/checks/_components/flow-diagram/nodes/EnvironmentNode.tsx (0 hunks)
  • apps/webservice/src/app/[workspaceSlug]/(app)/(deploy)/(raw)/systems/[systemSlug]/(raw)/deployments/[deploymentSlug]/(raw)/releases/[releaseId]/checks/page.tsx (2 hunks)
  • apps/webservice/src/app/[workspaceSlug]/(app)/(deploy)/_components/deployment-version/ApprovalDialog.tsx (1 hunks)
  • packages/api/src/router/deployment-version-checks/approvals.ts (0 hunks)
  • packages/api/src/router/deployment-version-checks/deny-window.ts (0 hunks)
  • packages/api/src/router/deployment-version-checks/router.ts (0 hunks)
  • packages/api/src/router/deployment-version-checks/utils.ts (0 hunks)
  • packages/api/src/router/deployment-version-checks/version-selector.ts (0 hunks)
  • packages/api/src/router/deployment-version.ts (1 hunks)
💤 Files with no reviewable changes (7)
  • apps/webservice/src/app/[workspaceSlug]/(app)/(deploy)/(raw)/systems/[systemSlug]/(raw)/deployments/[deploymentSlug]/(raw)/releases/[releaseId]/checks/_components/flow-diagram/nodes/EnvironmentNode.tsx
  • packages/api/src/router/deployment-version-checks/deny-window.ts
  • apps/webservice/src/app/[workspaceSlug]/(app)/(deploy)/(raw)/systems/[systemSlug]/(raw)/deployments/[deploymentSlug]/(raw)/releases/[releaseId]/checks/_components/flow-diagram/checks/DenyWindow.tsx
  • packages/api/src/router/deployment-version-checks/router.ts
  • packages/api/src/router/deployment-version-checks/approvals.ts
  • packages/api/src/router/deployment-version-checks/utils.ts
  • packages/api/src/router/deployment-version-checks/version-selector.ts
🧰 Additional context used
📓 Path-based instructions (1)
`**/*.{ts,tsx}`: **Note on Error Handling:** Avoid strict enforcement of try/catch blocks. Code may use early returns, Promise chains (.then().catch()), or other patterns for error...

**/*.{ts,tsx}: Note on Error Handling:
Avoid strict enforcement of try/catch blocks. Code may use early returns, Promise chains (.then().catch()), or other patterns for error handling. These are acceptable as long as they maintain clarity and predictability.

  • apps/webservice/src/app/[workspaceSlug]/(app)/(deploy)/(raw)/systems/[systemSlug]/(raw)/deployments/[deploymentSlug]/(raw)/releases/[releaseId]/checks/_components/flow-diagram/checks/VersionSelector.tsx
  • apps/webservice/src/app/[workspaceSlug]/(app)/(deploy)/(raw)/systems/[systemSlug]/(raw)/deployments/[deploymentSlug]/(raw)/releases/[releaseId]/checks/_components/flow-diagram/checks/Approval.tsx
  • apps/webservice/src/app/[workspaceSlug]/(app)/(deploy)/(raw)/systems/[systemSlug]/(raw)/deployments/[deploymentSlug]/(raw)/releases/[releaseId]/checks/page.tsx
  • packages/api/src/router/deployment-version.ts
  • apps/webservice/src/app/[workspaceSlug]/(app)/(deploy)/_components/deployment-version/ApprovalDialog.tsx
🧬 Code Graph Analysis (1)
packages/api/src/router/deployment-version.ts (2)
packages/api/src/trpc.ts (1)
  • protectedProcedure (173-173)
packages/events/src/index.ts (1)
  • getQueue (28-34)
⏰ Context from checks skipped due to timeout of 90000ms (3)
  • GitHub Check: Lint
  • GitHub Check: Typecheck
  • GitHub Check: build (linux/amd64)
🔇 Additional comments (8)
apps/webservice/src/app/[workspaceSlug]/(app)/(deploy)/_components/deployment-version/ApprovalDialog.tsx (1)

29-29: API endpoint update looks good

The mutation hook has been updated to use the new consolidated endpoint api.deployment.version.addApprovalRecord.useMutation() instead of the previous checks-specific endpoint. This aligns with the PR objective of cleaning up the checks endpoints.

apps/webservice/src/app/[workspaceSlug]/(app)/(deploy)/(raw)/systems/[systemSlug]/(raw)/deployments/[deploymentSlug]/(raw)/releases/[releaseId]/checks/page.tsx (2)

4-4: Good addition of lodash import

The lodash import is appropriate for the new data transformation logic.


48-55: Good refactor to derive environments from release targets

The implementation properly fetches release targets and extracts unique environments using lodash.uniqBy. This approach is more normalized than having a specialized endpoint and aligns with the PR objective of cleaning up checks endpoints.

apps/webservice/src/app/[workspaceSlug]/(app)/(deploy)/(raw)/systems/[systemSlug]/(raw)/deployments/[deploymentSlug]/(raw)/releases/[releaseId]/checks/_components/flow-diagram/checks/VersionSelector.tsx (2)

8-11: API migration to unified policy evaluation looks good

The component now correctly uses the new unified policy evaluation API with properly ordered parameters.


13-15: Improved version selector check logic

The new implementation properly extracts the versionSelector object from policy evaluation rules and verifies that all values are truthy. This is more robust than the previous implementation and handles nested data structures appropriately.

apps/webservice/src/app/[workspaceSlug]/(app)/(deploy)/(raw)/systems/[systemSlug]/(raw)/deployments/[deploymentSlug]/(raw)/releases/[releaseId]/checks/_components/flow-diagram/checks/Approval.tsx (2)

13-15: API migration to unified policy evaluation looks good

The component now correctly uses the new unified policy evaluation API and updates the invalidation function accordingly.


17-30: More granular approval status logic

The new implementation checks three distinct approval categories (anyApprovals, userApprovals, and roleApprovals) and ensures all rejection reasons arrays are empty for each. This provides a more comprehensive assessment of approval status.

packages/api/src/router/deployment-version.ts (1)

381-439: LGTM: Good implementation of the new approval record mutation procedure.

The new addApprovalRecord procedure properly handles creating approval records and triggering evaluation jobs for related release targets. This aligns with the PR objective of moving to a unified policy evaluation API for approval checks.

Key strengths:

  • Proper authorization checks
  • Correctly setting approvedAt based on approval status
  • Triggering appropriate evaluation jobs after creating the record

@adityachoudhari26 adityachoudhari26 merged commit fce18c1 into main May 6, 2025
5 of 6 checks passed
@adityachoudhari26 adityachoudhari26 deleted the cleanup-checks-endpoints branch May 6, 2025 06:20
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.

2 participants