Skip to content

chore: update gh action to use new api#705

Merged
adityachoudhari26 merged 1 commit intomainfrom
update-gh-action
Oct 28, 2025
Merged

chore: update gh action to use new api#705
adityachoudhari26 merged 1 commit intomainfrom
update-gh-action

Conversation

@adityachoudhari26
Copy link
Copy Markdown
Member

@adityachoudhari26 adityachoudhari26 commented Oct 28, 2025

Summary by CodeRabbit

  • New Features

    • Added new API endpoint to retrieve jobs with release information from the workspace engine SDK.
  • Bug Fixes

    • Improved error handling when jobs cannot be located during retrieval.
  • Dependencies

    • Updated SDK dependency version for workspace engine integration.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Oct 28, 2025

Walkthrough

The PR migrates the GitHub job inputs integration from the node SDK to the workspace-engine-sdk, introduces a new getJobWithRelease API operation for fetching job details with release information, updates client authentication to use header-based apiKey passing, and refactors job retrieval logic to iterate across workspace IDs.

Changes

Cohort / File(s) Summary
Dependency Update
integrations/github-get-job-inputs/package.json
Replaces @ctrlplane/node-sdk with @ctrlplane/workspace-engine-sdk in dependencies.
SDK Integration
integrations/github-get-job-inputs/src/sdk.ts
Updates SDK import to workspace-engine-sdk; changes client initialization from apiKey property to headers object with "x-api-key".
Job Input Logic
integrations/github-get-job-inputs/src/index.ts
Adds getJob(jobId) helper that iterates over workspace IDs and fetches job with release; refactors output mapping to construct and recursively populate a single ghActionsJobObject instead of multi-step field mapping; adds early failure when job not found.
API Schema
packages/workspace-engine-sdk/src/schema.ts
Adds new GET endpoint "/v1/workspaces/{workspaceId}/jobs/{jobId}/with-release" and corresponding getJobWithRelease operation with responses for 200 (JobWithRelease), 400 (ErrorResponse), and 404 (ErrorResponse).

Sequence Diagram

sequenceDiagram
    participant Action as GitHub Action
    participant getJob as getJob Helper
    participant SDK as Workspace Engine SDK
    participant API as Backend API
    
    Action->>getJob: getJob(jobId)
    loop For each workspace
        getJob->>SDK: api.getJobWithRelease({workspaceId, jobId})
        SDK->>API: GET /v1/workspaces/{workspaceId}/jobs/{jobId}/with-release
        alt Job found
            API-->>SDK: 200 JobWithRelease
            SDK-->>getJob: job + workspaceId
            getJob-->>Action: {job, workspaceId}
        else Job not found
            API-->>SDK: 404 ErrorResponse
            SDK-->>getJob: null
        end
    end
    
    alt Job retrieved
        Action->>Action: Construct ghActionsJobObject
        Action->>Action: Set outputs recursively
        Action->>Action: Validate required outputs
    else Job not found
        Action->>Action: Fail with error
    end
Loading

Estimated Code Review Effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

  • index.ts: Verify the new getJob helper correctly iterates workspaces and handles null/undefined cases; ensure refactored recursive output setter covers all required fields from the old multi-step flow.
  • sdk.ts: Confirm the header-based authentication change ("x-api-key") is compatible with backend API expectations.
  • schema.ts: Validate the new endpoint path parameters and response types align with actual API contract.
  • Cross-file consistency: Ensure the new JobWithRelease type used in index.ts matches the schema definition.

Possibly related PRs

  • fix: tfc Scanner #195: Updates SDK usage and client instantiation patterns in integration files, including similar changes to createClient/DefaultApi calls.
  • chore: convert endpoint to use go engine #690: Modifies workspace-engine-sdk API schema and job-related response structures, directly complementing the new getJobWithRelease operation.
  • fix get job inputs #196: Alters the same GitHub job inputs integration, refactoring how SDK client is constructed and how the API is called to fetch job data.

Suggested Reviewers

  • jsbroks

Poem

🐰 A workspace hop, a job to find,
With SDK renewed, no node left behind,
Headers now carry keys so bright,
Release and data, all in sight! ✨

Pre-merge checks and finishing touches

❌ 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%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title Check ✅ Passed The pull request title "chore: update gh action to use new api" is directly related to the main changes in the changeset. The primary modifications involve migrating the GitHub action integration to use a new SDK (@ctrlplane/workspace-engine-sdk instead of @ctrlplane/node-sdk), refactoring the action's logic to use a new API endpoint structure (the /with-release endpoint), and adding this new endpoint to the schema. The title accurately captures this update, and a teammate scanning the git history would understand that this commit modernizes the GitHub action to integrate with a new API structure. While the phrase "new api" is somewhat generic, it appropriately refers to both the updated SDK and the new endpoint being used.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch update-gh-action

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

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

Copy link
Copy Markdown
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)
integrations/github-get-job-inputs/src/index.ts (2)

46-61: Consider performance optimization and error handling.

The sequential iteration through workspace IDs could be slow if there are many workspaces. Additionally, API call failures will cause the function to throw without graceful error handling.

Consider these improvements:

  1. Parallel requests: Use Promise.all() or Promise.allSettled() to check multiple workspaces concurrently:
 const getJob = async (jobId: string): Promise<JobWithWorkspace | null> => {
   const workspaceIdsResponse = await api.GET("/v1/workspaces");
   const workspaceIds = workspaceIdsResponse.data?.workspaceIds ?? [];
 
-  for (const workspaceId of workspaceIds) {
-    const jobResponse = await api.GET(
-      "/v1/workspaces/{workspaceId}/jobs/{jobId}/with-release",
-      { params: { path: { workspaceId, jobId } } },
-    );
-
-    const job = jobResponse.data;
-    if (job != null) return { ...job, workspaceId };
-  }
-
-  return null;
+  const results = await Promise.allSettled(
+    workspaceIds.map((workspaceId) =>
+      api.GET("/v1/workspaces/{workspaceId}/jobs/{jobId}/with-release", {
+        params: { path: { workspaceId, jobId } },
+      }).then((response) => 
+        response.data ? { ...response.data, workspaceId } : null
+      )
+    )
+  );
+
+  for (const result of results) {
+    if (result.status === "fulfilled" && result.value != null) {
+      return result.value;
+    }
+  }
+
+  return null;
 };
  1. Error logging: Add logging for failed API calls to aid debugging.

63-93: Add error handling for robustness.

The run function should handle potential errors from getJob to provide clearer error messages when API calls fail.

Wrap the main logic in a try/catch to handle API failures gracefully:

 async function run() {
   const jobId: string = core.getInput("job_id", { required: true });
   const baseUrl = core.getInput("base_url") || "https://app.ctrlplane.dev";
 
+  try {
     const job = await getJob(jobId);
     if (job == null) {
       core.setFailed(`Job not found: ${jobId}`);
       return;
     }
 
     const ghActionsJobObject = {
       base: { url: baseUrl },
       variable: job.release.variables,
       resource: job.resource,
       version: job.release.version,
       workspace: { id: job.workspaceId },
       environment: job.environment,
       deployment: job.deployment,
     };
 
     setOutputsRecursively(null, ghActionsJobObject);
 
     const missingOutputs = requiredOutputs.filter(
       (output) => !outputTracker.has(output),
     );
 
     if (missingOutputs.length > 0) {
       core.setFailed(`Missing required outputs: ${missingOutputs.join(", ")}`);
       return;
     }
+  } catch (error) {
+    const message = error instanceof Error ? error.message : String(error);
+    core.setFailed(`Failed to get job inputs: ${message}`);
+  }
 }
📜 Review details

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Disabled knowledge base sources:

  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between ac5610f and bfde965.

⛔ Files ignored due to path filters (1)
  • pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
📒 Files selected for processing (4)
  • integrations/github-get-job-inputs/package.json (1 hunks)
  • integrations/github-get-job-inputs/src/index.ts (2 hunks)
  • integrations/github-get-job-inputs/src/sdk.ts (1 hunks)
  • packages/workspace-engine-sdk/src/schema.ts (2 hunks)
🧰 Additional context used
📓 Path-based instructions (2)
**/*.{ts,tsx}

📄 CodeRabbit inference engine (CLAUDE.md)

**/*.{ts,tsx}: Use TypeScript with explicit types (prefer interfaces for public APIs)
Import styles: Use named imports, group imports by source (std lib > external > internal)
Consistent type imports: import type { Type } from "module"
Prefer async/await over raw promises
Handle errors explicitly (use try/catch and typed error responses)

Files:

  • packages/workspace-engine-sdk/src/schema.ts
  • integrations/github-get-job-inputs/src/sdk.ts
  • integrations/github-get-job-inputs/src/index.ts

⚙️ CodeRabbit configuration file

**/*.{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.

Files:

  • packages/workspace-engine-sdk/src/schema.ts
  • integrations/github-get-job-inputs/src/sdk.ts
  • integrations/github-get-job-inputs/src/index.ts
**/*.{js,jsx,ts,tsx,json,md,yml,yaml}

📄 CodeRabbit inference engine (CLAUDE.md)

Formatting: Prettier is used with @ctrlplane/prettier-config

Files:

  • packages/workspace-engine-sdk/src/schema.ts
  • integrations/github-get-job-inputs/package.json
  • integrations/github-get-job-inputs/src/sdk.ts
  • integrations/github-get-job-inputs/src/index.ts
🧠 Learnings (1)
📚 Learning: 2024-11-03T00:15:33.442Z
Learnt from: zacharyblasczyk
PR: ctrlplanedev/ctrlplane#196
File: integrations/github-get-job-inputs/src/index.ts:39-39
Timestamp: 2024-11-03T00:15:33.442Z
Learning: In `integrations/github-get-job-inputs/src/sdk.ts`, the API client is properly configured with the `baseUrl` input.

Applied to files:

  • integrations/github-get-job-inputs/src/sdk.ts
🧬 Code graph analysis (2)
integrations/github-get-job-inputs/src/sdk.ts (1)
github/get-job-inputs/index.js (2)
  • api (3475-3475)
  • api (32598-32601)
integrations/github-get-job-inputs/src/index.ts (3)
packages/node-sdk/src/index.ts (1)
  • Job (114-142)
apps/webservice/src/app/api/v1/jobs/[jobId]/get-job.ts (1)
  • getJob (172-214)
integrations/github-get-job-inputs/src/sdk.ts (1)
  • api (5-8)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (7)
  • GitHub Check: build (linux/amd64)
  • GitHub Check: build-and-push (linux/amd64)
  • GitHub Check: build (linux/amd64)
  • GitHub Check: build (linux/amd64)
  • GitHub Check: Lint
  • GitHub Check: Format
  • GitHub Check: Typecheck
🔇 Additional comments (7)
integrations/github-get-job-inputs/package.json (1)

23-23: LGTM! Clean SDK migration.

The dependency swap from @ctrlplane/node-sdk to @ctrlplane/workspace-engine-sdk is correct and aligns with the PR objective to migrate to the new API.

integrations/github-get-job-inputs/src/sdk.ts (2)

3-3: LGTM! SDK import updated correctly.

The import source has been updated to use the new @ctrlplane/workspace-engine-sdk, consistent with the package.json change.


5-8: Authentication migrated to header-based approach.

The client initialization correctly switches from apiKey property to headers: { "x-api-key": ... } for authentication. This aligns with the new workspace-engine-sdk's API.

packages/workspace-engine-sdk/src/schema.ts (2)

404-423: New API endpoint added correctly.

The new path /v1/workspaces/{workspaceId}/jobs/{jobId}/with-release has been properly defined with a GET operation that returns job details with release information. The structure is consistent with other endpoints in the auto-generated schema.


2064-2106: Operation definition is complete.

The getJobWithRelease operation is properly defined with appropriate path parameters (workspaceId, jobId) and response types (200: JobWithRelease, 400/404: ErrorResponse). This matches the usage in the GitHub Action integration.

integrations/github-get-job-inputs/src/index.ts (2)

1-1: LGTM! Proper type import.

The type-only import for WorkspaceEngine follows TypeScript best practices and aligns with the coding guidelines.


40-44: Well-defined types.

The type definitions properly reference the schema and extend it with the necessary workspaceId field. This is clean and type-safe.

@adityachoudhari26 adityachoudhari26 merged commit f069565 into main Oct 28, 2025
8 of 10 checks passed
@adityachoudhari26 adityachoudhari26 deleted the update-gh-action branch October 28, 2025 21:16
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