chore: update gh action to use new api#705
Conversation
WalkthroughThe 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
Sequence DiagramsequenceDiagram
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
Estimated Code Review Effort🎯 3 (Moderate) | ⏱️ ~20 minutes
Possibly related PRs
Suggested Reviewers
Poem
Pre-merge checks and finishing touches❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
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:
- Parallel requests: Use
Promise.all()orPromise.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; };
- Error logging: Add logging for failed API calls to aid debugging.
63-93: Add error handling for robustness.The
runfunction should handle potential errors fromgetJobto 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.
⛔ Files ignored due to path filters (1)
pnpm-lock.yamlis 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.tsintegrations/github-get-job-inputs/src/sdk.tsintegrations/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.tsintegrations/github-get-job-inputs/src/sdk.tsintegrations/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.tsintegrations/github-get-job-inputs/package.jsonintegrations/github-get-job-inputs/src/sdk.tsintegrations/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-sdkto@ctrlplane/workspace-engine-sdkis 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
apiKeyproperty toheaders: { "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-releasehas 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
getJobWithReleaseoperation 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
WorkspaceEnginefollows 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
workspaceIdfield. This is clean and type-safe.
Summary by CodeRabbit
New Features
Bug Fixes
Dependencies