Skip to content

Conversation

@adityachoudhari26
Copy link
Contributor

@adityachoudhari26 adityachoudhari26 commented Apr 9, 2025

Summary by CodeRabbit

  • New Features
    • Launched an interactive flow diagram that visually presents deployment environments using intuitive nodes and status icons.
    • Introduced components for real-time approval checks, providing clear feedback on deployment status.
    • Added a dedicated checks page that aggregates deployment details and environment validations.
    • Expanded API endpoints to support version status checks and rule evaluations, enhancing overall deployment management.

@adityachoudhari26 adityachoudhari26 changed the title init feat: Init version check routes Apr 9, 2025
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Apr 10, 2025

Walkthrough

This pull request introduces new UI components and backend routes to support deployment environment visualization and approval checks. A set of React components—including a flow diagram, status icons, approval check, environment node, and trigger node—are added to visualize deployment flows. Additionally, a new checks page integrates these components with asynchronous data fetching and metadata generation. On the backend side, a new TRPC router for deployment version checks is introduced, along with updates to the version release manager and rule engine. A dependency is also added to support rule evaluation, and an import change is made in one rule engine file.

Changes

File(s) Change Summary
apps/webservice/src/app/[workspaceSlug]/.../checksv2/_components/flow-diagram/FlowDiagram.tsx
apps/webservice/src/app/[workspaceSlug]/.../checksv2/_components/flow-diagram/StatusIcons.tsx
apps/webservice/src/app/[workspaceSlug]/.../checksv2/_components/flow-diagram/checks/Approval.tsx
apps/webservice/src/app/[workspaceSlug]/.../checksv2/_components/flow-diagram/nodes/EnvironmentNode.tsx
apps/webservice/src/app/[workspaceSlug]/.../checksv2/_components/flow-diagram/nodes/TriggerNode.tsx
Added new React components for rendering a flow diagram of deployment environments, status icons, approval checks, and specialized nodes for environments and triggers.
apps/webservice/src/app/[workspaceSlug]/.../checksv2/page.tsx Introduced a new checks page with asynchronous data fetching, metadata generation, and integration of the FlowDiagram component.
packages/api/package.json
packages/api/src/router/deployment-version-checks.ts
packages/api/src/router/deployment-version.ts
Added a new dependency (@ctrlplane/rule-engine) and introduced a TRPC router for deployment version checks, integrating it into the overall version router.
packages/rule-engine/src/manager/version-manager-rules.ts
packages/rule-engine/src/manager/version-manager.ts
packages/rule-engine/src/rules/deployment-deny-rule.ts
Added a helper function to retrieve version approval rules, updated the VersionReleaseManager to optionally accept versions and evaluate approval rules, and modified the import syntax for the rrule module.

Sequence Diagram(s)

sequenceDiagram
    participant User as User
    participant Page as ChecksPage
    participant API as Deployment API
    participant Flow as FlowDiagram Component

    User->>Page: Request checks page
    Page->>API: Fetch deployment version & metadata
    API-->>Page: Deployment data and environments
    Page->>Flow: Pass workspace, deploymentVersion, envs
    Flow-->>User: Render interactive flow diagram
Loading
sequenceDiagram
    participant Client as Client
    participant Router as DeploymentVersionChecks Router
    participant DB as Database

    Client->>Router: Request status (workspaceId, versionId, environmentId)
    Router->>DB: Query deployment version and release target
    DB-->>Router: Return data or error
    Router-->>Client: Return approval status result
Loading

Possibly related PRs

  • fix: Optimize flow node query #190: The changes in the main PR introduce a new FlowDiagram component that accepts a workspace prop, while the retrieved PR modifies the existing FlowDiagram component to include a workspace prop as well, indicating a direct relationship in their code modifications.

Suggested reviewers

  • jsbroks

Poem

I'm a little rabbit with code in my hops,
Crafting flow diagrams where each connection pops.
Nodes and triggers dance in a digital glade,
With approvals checked and statuses displayed.
Bugs scurry away as our release shines bright—
Hopping to a future that's coding just right! 🐇✨

✨ Finishing Touches
  • 📝 Generate Docstrings

🪧 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.

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 resolve resolve all the CodeRabbit review comments.
  • @coderabbitai plan to trigger planning for file edits and PR creation.
  • @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 (2)
apps/webservice/src/app/[workspaceSlug]/(app)/(deploy)/(raw)/systems/[systemSlug]/(raw)/deployments/[deploymentSlug]/(raw)/releases/[releaseId]/checksv2/_components/flow-diagram/checks/Approval.tsx (1)

1-35: Consider adding explicit error handling.

The component handles loading and data states appropriately but lacks explicit error handling for query failures. While it will default to showing "Not enough approvals" if the query fails, it would be better to explicitly handle and display error states.

-  const { data: isApproved, isLoading } =
+  const { data: isApproved, isLoading, error } =
     api.deployment.version.checks.approval.status.useQuery({
       workspaceId,
       environmentId,
       versionId,
     });

   if (isLoading)
     return (
       <div className="flex items-center gap-2">
         <Loading /> Loading approval status
       </div>
     );

+  if (error)
+    return (
+      <div className="flex items-center gap-2 text-red-500">
+        <IconX className="h-4 w-4" /> Error loading approval status
+      </div>
+    );
+
   if (isApproved)
     return (
       <div className="flex items-center gap-2">
         <Passing /> Approved
       </div>
     );
apps/webservice/src/app/[workspaceSlug]/(app)/(deploy)/(raw)/systems/[systemSlug]/(raw)/deployments/[deploymentSlug]/(raw)/releases/[releaseId]/checksv2/_components/flow-diagram/FlowDiagram.tsx (1)

28-51: Consider removing redundant label property in environment nodes

The environment node data includes both environmentName and label with the same value. Since you're only using environmentName in the EnvironmentNode component, the label property appears redundant.

  data: {
    workspaceId: workspace.id,
    versionId: deploymentVersion.id,
    versionTag: deploymentVersion.tag,
    deploymentId: deploymentVersion.deploymentId,
    environmentId: env.id,
    environmentName: env.name,
-   label: env.name,
  },
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 740d18a and 10aa864.

⛔ Files ignored due to path filters (1)
  • pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
📒 Files selected for processing (12)
  • apps/webservice/src/app/[workspaceSlug]/(app)/(deploy)/(raw)/systems/[systemSlug]/(raw)/deployments/[deploymentSlug]/(raw)/releases/[releaseId]/checksv2/_components/flow-diagram/FlowDiagram.tsx (1 hunks)
  • apps/webservice/src/app/[workspaceSlug]/(app)/(deploy)/(raw)/systems/[systemSlug]/(raw)/deployments/[deploymentSlug]/(raw)/releases/[releaseId]/checksv2/_components/flow-diagram/StatusIcons.tsx (1 hunks)
  • apps/webservice/src/app/[workspaceSlug]/(app)/(deploy)/(raw)/systems/[systemSlug]/(raw)/deployments/[deploymentSlug]/(raw)/releases/[releaseId]/checksv2/_components/flow-diagram/checks/Approval.tsx (1 hunks)
  • apps/webservice/src/app/[workspaceSlug]/(app)/(deploy)/(raw)/systems/[systemSlug]/(raw)/deployments/[deploymentSlug]/(raw)/releases/[releaseId]/checksv2/_components/flow-diagram/nodes/EnvironmentNode.tsx (1 hunks)
  • apps/webservice/src/app/[workspaceSlug]/(app)/(deploy)/(raw)/systems/[systemSlug]/(raw)/deployments/[deploymentSlug]/(raw)/releases/[releaseId]/checksv2/_components/flow-diagram/nodes/TriggerNode.tsx (1 hunks)
  • apps/webservice/src/app/[workspaceSlug]/(app)/(deploy)/(raw)/systems/[systemSlug]/(raw)/deployments/[deploymentSlug]/(raw)/releases/[releaseId]/checksv2/page.tsx (1 hunks)
  • packages/api/package.json (1 hunks)
  • packages/api/src/router/deployment-version-checks.ts (1 hunks)
  • packages/api/src/router/deployment-version.ts (2 hunks)
  • packages/rule-engine/src/manager/version-manager-rules.ts (1 hunks)
  • packages/rule-engine/src/manager/version-manager.ts (2 hunks)
  • packages/rule-engine/src/rules/deployment-deny-rule.ts (1 hunks)
🧰 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.

  • packages/rule-engine/src/rules/deployment-deny-rule.ts
  • packages/api/src/router/deployment-version.ts
  • apps/webservice/src/app/[workspaceSlug]/(app)/(deploy)/(raw)/systems/[systemSlug]/(raw)/deployments/[deploymentSlug]/(raw)/releases/[releaseId]/checksv2/_components/flow-diagram/checks/Approval.tsx
  • packages/rule-engine/src/manager/version-manager-rules.ts
  • apps/webservice/src/app/[workspaceSlug]/(app)/(deploy)/(raw)/systems/[systemSlug]/(raw)/deployments/[deploymentSlug]/(raw)/releases/[releaseId]/checksv2/_components/flow-diagram/StatusIcons.tsx
  • packages/rule-engine/src/manager/version-manager.ts
  • apps/webservice/src/app/[workspaceSlug]/(app)/(deploy)/(raw)/systems/[systemSlug]/(raw)/deployments/[deploymentSlug]/(raw)/releases/[releaseId]/checksv2/_components/flow-diagram/nodes/EnvironmentNode.tsx
  • apps/webservice/src/app/[workspaceSlug]/(app)/(deploy)/(raw)/systems/[systemSlug]/(raw)/deployments/[deploymentSlug]/(raw)/releases/[releaseId]/checksv2/page.tsx
  • packages/api/src/router/deployment-version-checks.ts
  • apps/webservice/src/app/[workspaceSlug]/(app)/(deploy)/(raw)/systems/[systemSlug]/(raw)/deployments/[deploymentSlug]/(raw)/releases/[releaseId]/checksv2/_components/flow-diagram/FlowDiagram.tsx
  • apps/webservice/src/app/[workspaceSlug]/(app)/(deploy)/(raw)/systems/[systemSlug]/(raw)/deployments/[deploymentSlug]/(raw)/releases/[releaseId]/checksv2/_components/flow-diagram/nodes/TriggerNode.tsx
🧬 Code Graph Analysis (5)
packages/api/src/router/deployment-version.ts (1)
packages/api/src/router/deployment-version-checks.ts (1)
  • deploymentVersionChecksRouter (73-100)
apps/webservice/src/app/[workspaceSlug]/(app)/(deploy)/(raw)/systems/[systemSlug]/(raw)/deployments/[deploymentSlug]/(raw)/releases/[releaseId]/checksv2/_components/flow-diagram/checks/Approval.tsx (1)
apps/webservice/src/app/[workspaceSlug]/(app)/(deploy)/(raw)/systems/[systemSlug]/(raw)/deployments/[deploymentSlug]/(raw)/releases/[releaseId]/checksv2/_components/flow-diagram/StatusIcons.tsx (3)
  • Loading (28-32)
  • Passing (5-9)
  • Waiting (17-26)
packages/rule-engine/src/manager/version-manager-rules.ts (2)
packages/rule-engine/src/types.ts (2)
  • Policy (51-57)
  • RuleEngineFilter (43-49)
packages/rule-engine/src/manager/version-rule-engine.ts (1)
  • Version (10-16)
apps/webservice/src/app/[workspaceSlug]/(app)/(deploy)/(raw)/systems/[systemSlug]/(raw)/deployments/[deploymentSlug]/(raw)/releases/[releaseId]/checksv2/_components/flow-diagram/nodes/EnvironmentNode.tsx (2)
packages/db/src/schema/environment.ts (1)
  • EnvironmentPolicy (197-197)
apps/webservice/src/app/[workspaceSlug]/(app)/(deploy)/(raw)/systems/[systemSlug]/(raw)/deployments/[deploymentSlug]/(raw)/releases/[releaseId]/checksv2/_components/flow-diagram/checks/Approval.tsx (1)
  • ApprovalCheck (4-35)
apps/webservice/src/app/[workspaceSlug]/(app)/(deploy)/(raw)/systems/[systemSlug]/(raw)/deployments/[deploymentSlug]/(raw)/releases/[releaseId]/checksv2/_components/flow-diagram/FlowDiagram.tsx (6)
apps/webservice/src/app/[workspaceSlug]/(app)/(deploy)/(raw)/systems/[systemSlug]/(raw)/deployments/[deploymentSlug]/(raw)/releases/[releaseId]/checksv2/_components/flow-diagram/nodes/EnvironmentNode.tsx (1)
  • EnvironmentNode (22-55)
apps/webservice/src/app/[workspaceSlug]/(app)/(deploy)/(raw)/systems/[systemSlug]/(raw)/deployments/[deploymentSlug]/(raw)/releases/[releaseId]/checksv2/_components/flow-diagram/nodes/TriggerNode.tsx (1)
  • TriggerNode (9-30)
packages/db/src/schema/workspace.ts (2)
  • Workspace (53-53)
  • workspace (18-27)
packages/db/src/schema/deployment-version.ts (1)
  • deploymentVersion (109-136)
apps/webservice/src/app/[workspaceSlug]/(app)/_components/reactflow/layout.ts (1)
  • useLayoutAndFitView (76-150)
apps/webservice/src/app/[workspaceSlug]/(app)/_components/reactflow/ArrowEdge.tsx (1)
  • ArrowEdge (5-20)
⏰ Context from checks skipped due to timeout of 90000ms (4)
  • GitHub Check: Typecheck
  • GitHub Check: build (linux/amd64)
  • GitHub Check: Lint
  • GitHub Check: build (linux/amd64)
🔇 Additional comments (22)
packages/api/package.json (1)

32-32: New dependency added for rule engine functionality.

The addition of @ctrlplane/rule-engine as a workspace dependency is appropriate for integrating rule engine functionality to support deployment environment visualization and approval checks.

packages/rule-engine/src/rules/deployment-deny-rule.ts (1)

8-8: Import style changed to namespace import.

The change from default import to namespace import for rrule is appropriate and matches how the module is used later in the file (line 18 where it's destructured).

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

49-49: New deployment version checks router imported.

The import for the deploymentVersionChecksRouter is properly added, which will enable the router to handle deployment version check functionality.


1008-1008: Router extended with version checks functionality.

The addition of the checks property to the versionRouter follows the existing pattern of the codebase and correctly incorporates the deployment version checks router.

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

1-39: Well-structured status icon components.

The status icon components are well-implemented with clear, consistent styling and appropriate use of the Tabler icon library. Each component serves a specific purpose in the UI flow, and the Waiting component properly accepts an optional className for flexibility.

packages/rule-engine/src/manager/version-manager-rules.ts (1)

63-69: Well-structured and focused approval rules function.

The getVersionApprovalRules function provides a clean abstraction for obtaining only version approval rules from a policy, making the code more modular and reusable. It properly handles null policies and leverages existing functions to maintain consistency.

apps/webservice/src/app/[workspaceSlug]/(app)/(deploy)/(raw)/systems/[systemSlug]/(raw)/deployments/[deploymentSlug]/(raw)/releases/[releaseId]/checksv2/_components/flow-diagram/nodes/TriggerNode.tsx (1)

1-30: Clean component implementation with proper typing.

The TriggerNode component is well-structured, properly leveraging React Flow's node architecture with appropriate positioning and styling. The component is correctly typed with TriggerNodeProps extending NodeProps with the necessary data structure.

packages/rule-engine/src/manager/version-manager.ts (4)

17-17: Appropriate imports for the new functionality.

The imports have been correctly updated to include the necessary types and functions for the new implementation.

Also applies to: 23-23


27-31: Good extension of constructor to support optional versions.

Adding the optional versions parameter to the constructor allows for greater flexibility in how the class is used, enabling callers to provide pre-fetched versions when needed.


179-181: Effective reuse of versions parameter.

The update appropriately leverages the optional versions parameter, falling back to fetching versions only when necessary. This optimization can reduce database queries when versions are already available.


184-204: Well-implemented approval rules evaluation method.

The evaluateApprovalRules method follows the same pattern as the existing evaluate method, making it consistent and easy to understand. It correctly uses the new getVersionApprovalRules function to obtain only the approval rules, focusing the evaluation on approval status.

apps/webservice/src/app/[workspaceSlug]/(app)/(deploy)/(raw)/systems/[systemSlug]/(raw)/deployments/[deploymentSlug]/(raw)/releases/[releaseId]/checksv2/_components/flow-diagram/nodes/EnvironmentNode.tsx (3)

1-55: Well-structured environment node component with good composition

The EnvironmentNode component is well-implemented with clear separation of concerns and good use of UI utilities. The component correctly integrates with reactflow's node system by extending the NodeProps type and implementing both target and source handles.


12-20: Props type definition is comprehensive and well-typed

The EnvironmentNodeProps type properly extends the reactflow NodeProps and includes all necessary properties to render the environment node in the flow diagram.


35-39: Good integration with ApprovalCheck component

The component correctly passes the required workspaceId, environmentId, and versionId props to the ApprovalCheck component, enabling proper approval status display.

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

1-80: Well-structured flow diagram component with proper reactflow integration

The component correctly implements the reactflow library for creating an interactive flow diagram. It properly handles node and edge creation, layout configuration, and event handling.


67-78: Good use of ReactFlow configuration

The ReactFlow component is configured with all necessary props for proper rendering and interaction, including node and edge types, change handlers, and fitting the view. The hideAttribution option in proOptions is also appropriately set.

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

11-71: Well-implemented approval router with proper error handling

The approvalRouter correctly implements the approval status check procedure with proper input validation, authorization checks, and error handling. The database queries are structured well, and the approval evaluation logic is clear.


41-44: Efficient metadata transformation

The code efficiently transforms the metadata array into a key-value object using Object.fromEntries and a map operation, making it easier to work with.


73-100: Well-structured environmentsToCheck procedure with proper authorization

The environmentsToCheck procedure correctly implements the retrieval of environments associated with a deployment. The authorization check is comprehensive, and the database query is optimized using selectDistinctOn to retrieve unique environments.

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

21-32: Well-implemented metadata generation

The generateMetadata function correctly fetches the necessary data and formats the page title with relevant information, providing good SEO support.


34-67: Efficient data fetching with proper error handling

The ChecksPage component efficiently uses Promise.all for parallel data fetching and properly handles missing data with the notFound function. The layout structure is clean with appropriate positioning of the sidebar trigger and flow diagram.


40-44: Good use of parallel promises for data fetching

Using Promise.all for fetching both deployment version and deployment data concurrently is an efficient approach that improves page loading performance.

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 (5)
apps/webservice/src/app/[workspaceSlug]/(app)/(deploy)/(raw)/systems/[systemSlug]/(raw)/deployments/[deploymentSlug]/(raw)/releases/[releaseId]/checksv2/_components/flow-diagram/checks/Approval.tsx (3)

16-21: Good use of TRPC for data fetching, but error handling is missing.

The component correctly uses the TRPC query hook to fetch approval status data, but there's no error handling if the query fails. Consider adding error handling to improve user experience.

-  const { data, isLoading } =
+  const { data, isLoading, error } =
     api.deployment.version.checks.approval.status.useQuery({
       workspaceId,
       environmentId,
       versionId,
     });

+  if (error) {
+    return (
+      <div className="flex items-center gap-2 text-destructive">
+        <IconX className="h-3 w-3" /> Error loading approval status
+      </div>
+    );
+  }

42-63: Consider improving tooltip UX with visual indicators.

The tooltip is triggered when clicking on "Not enough approvals" but there's no visual indication that more information is available. Users might miss this important rejection information.

Add a visual indicator (like an info icon) to make it clearer that additional information is available:

            <div className="flex items-center gap-2">
-              <Waiting /> Not enough approvals
+              <Waiting /> Not enough approvals <IconInfoCircle className="ml-1 h-3 w-3 text-muted-foreground" />
            </div>

42-69: Refactor duplicate UI rendering code.

There are two nearly identical render branches for the "Not enough approvals" state - one with a tooltip (lines 42-63) and one without (lines 65-69). This creates unnecessary code duplication.

Consider refactoring this to remove duplication:

- if (rejectionReasonEntries.length > 0) {
-   return (
-     <TooltipProvider>
-       <Tooltip>
-         <TooltipTrigger>
-           <div className="flex items-center gap-2">
-             <Waiting /> Not enough approvals
-           </div>
-         </TooltipTrigger>
-         <TooltipContent>
-           <ul>
-             {rejectionReasonEntries.map(([reason, comment]) => (
-               <li key={reason}>
-                 {reason}: {comment}
-               </li>
-             ))}
-           </ul>
-         </TooltipContent>
-       </Tooltip>
-     </TooltipProvider>
-   );
- }
-
- return (
-   <div className="flex items-center gap-2">
-     <Waiting /> Not enough approvals
-   </div>
- );

+ const notEnoughApprovalsContent = (
+   <div className="flex items-center gap-2">
+     <Waiting /> Not enough approvals {rejectionReasonEntries.length > 0 && <IconInfoCircle className="ml-1 h-3 w-3 text-muted-foreground" />}
+   </div>
+ );
+
+ if (rejectionReasonEntries.length > 0) {
+   return (
+     <TooltipProvider>
+       <Tooltip>
+         <TooltipTrigger>
+           {notEnoughApprovalsContent}
+         </TooltipTrigger>
+         <TooltipContent>
+           <ul>
+             {rejectionReasonEntries.map(([reason, comment]) => (
+               <li key={reason}>
+                 {reason}: {comment}
+               </li>
+             ))}
+           </ul>
+         </TooltipContent>
+       </Tooltip>
+     </TooltipProvider>
+   );
+ }
+
+ return notEnoughApprovalsContent;
packages/api/src/router/deployment-version-checks.ts (2)

49-66: Clarify the release target selection logic

The comment on lines 50-51 explains the rationale for selecting any release target for the given deployment and environment. This design decision is important but could be more explicitly documented.

Also, consider adding a debug log when a release target isn't found to help with troubleshooting.


65-75: Consider adding error handling for the manager.evaluate() call

The evaluation call to the VersionReleaseManager is not wrapped in a try/catch block. While this follows the guideline of not strictly enforcing try/catch, adding error handling could improve the reliability of this critical operation.

-        const { chosenCandidate, rejectionReasons } = await manager.evaluate({
-          versions: [version],
-          rules: getVersionApprovalRules,
-        });
-        return {
-          approved: chosenCandidate != null,
-          rejectionReasons,
-        };
+        try {
+          const { chosenCandidate, rejectionReasons } = await manager.evaluate({
+            versions: [version],
+            rules: getVersionApprovalRules,
+          });
+          return {
+            approved: chosenCandidate != null,
+            rejectionReasons,
+          };
+        } catch (error) {
+          throw new TRPCError({
+            code: "INTERNAL_SERVER_ERROR",
+            message: `Error evaluating approval rules: ${error instanceof Error ? error.message : String(error)}`,
+            cause: error,
+          });
+        }
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 10aa864 and 5d189d0.

📒 Files selected for processing (4)
  • apps/webservice/src/app/[workspaceSlug]/(app)/(deploy)/(raw)/systems/[systemSlug]/(raw)/deployments/[deploymentSlug]/(raw)/releases/[releaseId]/checksv2/_components/flow-diagram/checks/Approval.tsx (1 hunks)
  • packages/api/src/router/deployment-version-checks.ts (1 hunks)
  • packages/rule-engine/src/index.ts (1 hunks)
  • packages/rule-engine/src/manager/version-manager.ts (3 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • packages/rule-engine/src/manager/version-manager.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.

  • packages/rule-engine/src/index.ts
  • apps/webservice/src/app/[workspaceSlug]/(app)/(deploy)/(raw)/systems/[systemSlug]/(raw)/deployments/[deploymentSlug]/(raw)/releases/[releaseId]/checksv2/_components/flow-diagram/checks/Approval.tsx
  • packages/api/src/router/deployment-version-checks.ts
🧬 Code Graph Analysis (2)
apps/webservice/src/app/[workspaceSlug]/(app)/(deploy)/(raw)/systems/[systemSlug]/(raw)/deployments/[deploymentSlug]/(raw)/releases/[releaseId]/checksv2/_components/flow-diagram/checks/Approval.tsx (1)
apps/webservice/src/app/[workspaceSlug]/(app)/(deploy)/(raw)/systems/[systemSlug]/(raw)/deployments/[deploymentSlug]/(raw)/releases/[releaseId]/checksv2/_components/flow-diagram/StatusIcons.tsx (3)
  • Loading (28-32)
  • Passing (5-9)
  • Waiting (17-26)
packages/api/src/router/deployment-version-checks.ts (5)
packages/api/src/router/environment-approval.ts (1)
  • approvalRouter (23-219)
packages/api/src/trpc.ts (2)
  • createTRPCRouter (55-55)
  • protectedProcedure (150-150)
packages/db/src/schema/release.ts (1)
  • releaseTarget (19-41)
packages/rule-engine/src/manager/version-manager.ts (1)
  • VersionReleaseManager (30-188)
packages/rule-engine/src/manager/version-manager-rules.ts (1)
  • getVersionApprovalRules (63-69)
⏰ Context from checks skipped due to timeout of 90000ms (4)
  • GitHub Check: Typecheck
  • GitHub Check: Lint
  • GitHub Check: build (linux/amd64)
  • GitHub Check: build (linux/amd64)
🔇 Additional comments (10)
packages/rule-engine/src/index.ts (1)

2-2: Export addition looks good.

This new export adds the version manager rules module to the public API, which aligns with the PR objective of initializing version check routes. The export follows the consistent pattern used in this file.

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

23-26: Type safety improvement in data handling.

The code correctly handles potential undefined values with nullish coalescing and optional chaining. This ensures type safety when working with the API response.


1-15: Component correctly implements props and imports.

The component definition is well structured with properly typed props. The imports are organized and show good separation of concerns between UI components and data fetching.


28-40: Good conditional rendering for loading and approved states.

The component correctly handles loading and approved states with appropriate visual indicators, making the UX clear and intuitive.

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

1-12: Imports are well-organized and appropriate for implementation

The file correctly imports all necessary dependencies for TRPC router creation, validation, database operations, and rule engine functionality.


14-29: Well-structured authorization checks

The authorization implementation correctly validates user permissions against the deployment version using the DeploymentVersionGet permission. The input validation using Zod ensures that all required parameters are valid UUIDs.


30-47: Good error handling for deployment version lookup

The code appropriately checks for the existence of the deployment version and throws a properly formatted TRPC error with a NOT_FOUND code if needed. The metadata transformation is clean and efficient.


79-92: Thorough authorization check for environmentsToCheck procedure

The authorization check correctly verifies that the user has permission to list environments for the deployment's system. Good practice to check deployment existence first and return false if not found.


93-104: Efficient database query for distinct environments

The query is well-constructed using selectDistinctOn to ensure unique environment records are returned. The join and filters are appropriate for the task.


105-106: Clean nested router structure

The approach of exposing the approvalRouter as a nested router under approval is clean and maintains a logical hierarchy in the API.

@adityachoudhari26 adityachoudhari26 merged commit 9b153b3 into main Apr 10, 2025
9 checks passed
@adityachoudhari26 adityachoudhari26 deleted the init-check-routes branch April 10, 2025 04:42
@coderabbitai coderabbitai bot mentioned this pull request Apr 15, 2025
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