-
Notifications
You must be signed in to change notification settings - Fork 18
feat: new import command to import your existing Checkly resources to the CLI [sc-23506]
#1045
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: new import command to import your existing Checkly resources to the CLI [sc-23506]
#1045
Conversation
WalkthroughThis change introduces a comprehensive import and code generation system for Checkly CLI, enabling users to import existing Checkly resources into their projects. It adds new CLI commands for managing import plans ( Changes
Note ⚡️ AI Code Reviews for VS Code, Cursor, WindsurfCodeRabbit now has a plugin for VS Code, Cursor and Windsurf. This brings AI code reviews directly in the code editor. Each commit is reviewed immediately, finding bugs before the PR is raised. Seamless context handoff to your AI code agent ensures that you can easily incorporate review feedback. Note ⚡️ Faster reviews with cachingCodeRabbit now supports caching for code and dependencies, helping speed up reviews. This means quicker feedback, reduced wait times, and a smoother review experience overall. Cached data is encrypted and stored securely. This feature will be automatically enabled for all accounts on May 16th. To opt out, configure ✨ Finishing Touches
🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed 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)
Other keywords and placeholders
CodeRabbit Configuration File (
|
import command to import your existing Checkly resources to the CLI [sc-23506]
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 6
🧹 Nitpick comments (38)
packages/cli/src/sourcegen/undefined.ts (1)
4-8: Implementation looks good.The
UndefinedValueclass correctly implements the rendering of the JavaScriptundefinedliteral. The class follows a clean pattern by extending the baseValueclass and implementing the requiredrendermethod.Consider adding a JSDoc comment to document the purpose of this class for better code maintainability.
packages/cli/src/sourcegen/null.ts (1)
4-8: Implementation looks good.The
NullValueclass correctly implements the rendering of the JavaScriptnullliteral. It follows the same clean pattern as the other value classes by extending the baseValueclass and implementing the requiredrendermethod.Consider adding a JSDoc comment to document the purpose of this class for better code maintainability and consistency with other value classes.
packages/cli/src/sourcegen/boolean.ts (1)
4-15: Implementation looks good.The
BooleanValueclass correctly implements the rendering of boolean values. It properly:
- Stores the boolean value as a property
- Calls super() in the constructor before accessing 'this'
- Uses toString() to convert the boolean to a string representation
This implementation is consistent with the value class pattern in this codebase.
Consider adding a JSDoc comment to document the purpose of this class for better code maintainability.
packages/cli/src/sourcegen/number.ts (1)
4-15: Implementation looks good with minor considerations.The
NumberValueclass correctly implements the rendering of number values, following the same pattern as the other value classes. It properly:
- Stores the number value as a property
- Calls super() in the constructor
- Uses toString() to convert the number to a string representation
Consider handling special number cases like
NaN,Infinity, or very large numbers that might produce unexpected string representations. You might want to add special handling for these cases if they need to be represented in a specific format in the generated code.Also, consider adding a JSDoc comment to document the purpose of this class for better code maintainability.
packages/cli/src/constructs/ref-codegen.ts (1)
4-13: Clean implementation of reference value generation.This function effectively generates the AST for a
Ref.from(...)expression, adding the necessary import and building the expression tree. This approach will work well for code generation use cases.Consider adding a brief documentation comment describing the expected output format of this function (e.g.,
Ref.from('ref-id')). This would improve clarity for maintainers unfamiliar with this part of the codebase.+/** + * Creates an expression representing a reference lookup using Ref.from('ref') + * @param program - The program to add imports to + * @param ref - The reference to generate a value for + * @returns A Value representing the Ref.from('ref') expression + */ export function valueForRef (program: Program, ref: Ref): Value {packages/cli/src/sourcegen/array.ts (1)
21-25: Consider handling trailing commas more explicitly.Currently, the render method adds a comma after each array element, including the last one. While trailing commas are valid in modern JavaScript/TypeScript, you might want to consider making this behavior configurable or more explicit for better clarity.
render (output: Output): void { if (this.value.length === 0) { output.append('[]') return } output.append('[') output.increaseIndent() - for (const value of this.value) { + for (let i = 0; i < this.value.length; i++) { + const value = this.value[i]; output.endLine() value.render(output) - output.append(',') + if (i < this.value.length - 1) { + output.append(',') + } } output.decreaseIndent() output.endLine() output.append(']') }packages/cli/src/sourcegen/object.ts (1)
26-33: Consider handling trailing commas more explicitly for object properties.Similar to the array implementation, the render method adds a comma after each property, including the last one. While trailing commas are valid in modern JavaScript/TypeScript, you might want to consider making this behavior configurable or more explicit for consistency and clarity.
render (output: Output): void { output.append('{') output.increaseIndent() - for (const { name, value } of this.value) { + for (let i = 0; i < this.value.length; i++) { + const { name, value } = this.value[i]; output.endLine() output.append(name) output.append(':') output.cosmeticWhitespace() value.render(output) - output.append(',') + if (i < this.value.length - 1) { + output.append(',') + } } output.decreaseIndent() output.endLine() output.append('}') }packages/cli/src/constructs/internal/codegen/codegen.ts (1)
11-13: Consider documenting the purpose of thepreparemethodThe
preparemethod is currently a no-op, but it might be intended for subclasses to override. Adding a comment explaining its purpose and when/how subclasses should use it would improve clarity.prepare (logicalId: string, resource: T, context: Context): void { - // No-op + // No-op by default. Subclasses can override this method to perform + // setup or validation before code generation. }packages/cli/src/sourcegen/string.ts (1)
19-22: Clarify the comment about using inspect()The comment notes that using
inspect()is "not ideal" but doesn't explain why or suggest a better approach. Consider adding more context to guide future improvements.- // Not ideal but for now inspect() works. + // Not ideal because inspect() includes Node.js-specific formatting that may change + // between versions, but it works for now. A more robust solution would be to implement + // proper string escaping for JavaScript/TypeScript syntax. return inspect(value)packages/cli/src/sourcegen/unknown.ts (1)
19-26: Consider adding a default case to handle all typesThe switch statement handles string, boolean, and number primitives, but doesn't explicitly handle other types like Symbol, BigInt, or functions. Adding a default case would make it more robust.
switch (typeof value) { case 'string': return new StringValue(value) case 'boolean': return new BooleanValue(value) case 'number': return new NumberValue(value) + default: + // For symbols, functions, bigints or other types we can't directly represent + // Convert to string representation as a fallback + return new StringValue(String(value)) }packages/cli/src/sourcegen/program.ts (2)
11-17: Simplify import method by removing redundant optional chainingSince you've already checked if the map has the key with
this.#imports.has(from), the optional chaining inthis.#imports.get(from)?.add(type)is unnecessary.import (type: string, from: string) { if (this.#imports.has(from)) { - this.#imports.get(from)?.add(type) + this.#imports.get(from)!.add(type) } else { this.#imports.set(from, new Set([type])) } }
23-45: Consider refactoring the import rendering logic for better readabilityThe complex rendering logic for imports could be extracted into a separate method to improve readability and maintainability.
render (output: Output): void { if (this.#imports.size > 0) { - for (const [pkg, types] of this.#imports.entries()) { - output.append('import') - output.cosmeticWhitespace() - output.append('{') - let first = true - for (const type of Array.from(types).sort()) { - if (!first) { - output.append(',') - } - output.cosmeticWhitespace() - first = false - output.append(type) - } - output.cosmeticWhitespace() - output.append('}') - output.significantWhitespace() - output.append('from') - output.significantWhitespace() - output.append(`'${pkg}'`) - } + this.#renderImports(output) } // ...rest of method... } + + #renderImports(output: Output): void { + for (const [pkg, types] of this.#imports.entries()) { + output.append('import') + output.cosmeticWhitespace() + output.append('{') + let first = true + for (const type of Array.from(types).sort()) { + if (!first) { + output.append(',') + } + output.cosmeticWhitespace() + first = false + output.append(type) + } + output.cosmeticWhitespace() + output.append('}') + output.significantWhitespace() + output.append('from') + output.significantWhitespace() + output.append(`'${pkg}'`) + } + }packages/cli/src/constructs/browser-check-codegen.ts (1)
25-32: TODO comment needs a more detailed plan.The TODO comment does not provide enough context about what exactly needs to be separated into a file and why. This makes it difficult for future developers to understand the intention.
Consider replacing the comment with a more detailed explanation:
- // TODO separate file + // TODO: Extract script content to a separate file in the repository + // and reference it via the entrypoint path for better maintainabilitypackages/cli/src/commands/import/commit.ts (2)
70-75: Misleading plan title for multiple plans.The plan title is hardcoded as "Plan #1" which is confusing when there are multiple plans being displayed in the list.
Update the title to include the plan's index or ID:
- const choices: prompts.Choice[] = plans.map(plan => ({ - title: `Plan #1 from ${new Date(plan.createdAt)}`, + const choices: prompts.Choice[] = plans.map((plan, index) => ({ + title: `Plan #${index + 1} from ${new Date(plan.createdAt)}`, value: plan.id, description: `ID: ${plan.id}`, }))
52-65: Error handling could be improved with more specific error messages.The current error handling just rethrows the error without providing context about what was being attempted.
Consider adding more context to the error:
try { await api.projects.commitImportPlan(plan.id) if (this.fancy) { ux.action.stop('✅ ') } } catch (err) { if (this.fancy) { ux.action.stop('❌') } - throw err + throw new Error(`Failed to commit plan ${plan.id}: ${err.message}`, { cause: err }) }packages/cli/src/commands/import/cancel.ts (2)
66-71: Misleading plan title for multiple plans.Similar to the commit command, the plan title is hardcoded as "Plan #1" which is confusing when there are multiple plans being displayed in the list.
Update the title to include the plan's index or ID:
- const choices: prompts.Choice[] = plans.map(plan => ({ - title: `Plan #1 from ${new Date(plan.createdAt)}`, + const choices: prompts.Choice[] = plans.map((plan, index) => ({ + title: `Plan #${index + 1} from ${new Date(plan.createdAt)}`, value: plan.id, description: `ID: ${plan.id}`, }))
47-63: Improved error handling would provide better context.When an error occurs during the cancellation of a plan, the current error handling just rethrows the error without context about which plan failed.
Consider modifying the error handling:
try { for (const plan of plans) { - await api.projects.cancelImportPlan(plan.id) - this.log(`${logSymbols.success} Canceled plan ${plan.id}`) + try { + await api.projects.cancelImportPlan(plan.id) + this.log(`${logSymbols.success} Canceled plan ${plan.id}`) + } catch (err) { + throw new Error(`Failed to cancel plan ${plan.id}: ${err.message}`, { cause: err }) + } } if (this.fancy) { ux.action.stop('✅ ') } } catch (err) { if (this.fancy) { ux.action.stop('❌') } throw err }packages/cli/src/constructs/dashboard-codegen.ts (1)
119-121: TODO comment about file separation needs more detail.The TODO comment is vague and doesn't provide specifics about when or why this refactoring should occur.
Consider adding more context:
- // TODO: Consider creating a separate file with the content - // and referring to it via entrypoint instead. + // TODO: For large CSS content, consider creating a separate .css file + // in the repository and referring to it via entrypoint instead to improve + // readability and enable proper syntax highlighting.packages/cli/src/constructs/telegram-alert-channel-codegen.ts (2)
12-17: Consider making the API key extraction more robustThe regex pattern assumes a specific URL format from Telegram's API. If their URL structure changes in the future, this extraction might fail.
-function apiKeyFromUrl (url: string): string | undefined { - const match = /https:\/\/api.telegram.org\/bot([^/]+)\/sendMessage/.exec(url) - if (match) { - return match[1] - } -} +function apiKeyFromUrl (url: string): string | undefined { + // Extract token between /bot and next slash from Telegram API URLs + const match = /api\.telegram\.org\/bot([^/]+)/.exec(url) + if (match) { + return match[1] + } +}
19-24: Consider adding validation for chat ID formatThe current implementation extracts any numeric string as a chat ID. Consider validating that it's a valid Telegram chat ID format.
function chatIdFromTemplate (template: string): string | undefined { const match = /chatId=(-?[0-9]+)/.exec(template) if (match) { + // Telegram chat IDs are numeric values and can be negative for groups return match[1] } }packages/cli/src/constructs/maintenance-window-codegen.ts (1)
16-64: Consider validating date strings or adding time-zone awareness.Since the code instantiates
Dateobjects based on unverified string inputs, it may be beneficial to inspect or validate these date strings. This could prevent unexpected runtime errors when the input is invalid or incorrectly formatted. Additionally, ensuring proper time-zone handling yields more predictable outcomes in different environments.Do you want me to propose a quick solution or add optional date parsing checks?
packages/cli/src/constructs/multi-step-check-codegen.ts (1)
16-41: Follow up on the TODO in the script handling.At line 25, there's a
// TODO separate filecomment. Separating script logic into its own module or file can promote cleaner organization and improved maintainability.Do you want me to open a tracking issue or propose a refactor for extracting the script logic?
packages/cli/src/sourcegen/decl.ts (1)
22-24: Consider expandingVariableDeclarationOptions.Right now, it's limited to a single
mutableflag. In the future, additional styling or scoping options (e.g., const enums) might be warranted for broader use.packages/cli/src/sourcegen/output.ts (1)
40-85: Consider adding validation to decreaseIndent method.While the Output class implementation is generally good, the decreaseIndent method doesn't check whether the level would become negative. Although this might not be an issue in the current implementation if calls to decreaseIndent are always balanced with increaseIndent, adding validation would make the code more robust.
Also, the methods significantWhitespace and cosmeticWhitespace currently do the same thing - they both append a single space. This suggests they might be intended to be differentiated in the future.
decreaseIndent () { + if (this.#level > 0) { this.#level -= 1 + } else { + console.warn('Attempted to decrease indent below 0') + } }packages/cli/src/commands/import/apply.ts (1)
22-60: Consider adding validation for configFilename.The run method implementation is good, but it doesn't validate whether configFilename is defined. If a user doesn't provide the --config flag, this could lead to errors in the subsequent operations.
Also, there's no handling for the case where no unapplied plans are found. Consider providing a clear message to the user in this scenario.
async run (): Promise<void> { const { flags } = await this.parse(ImportApplyCommand) const { config: configFilename, } = flags + if (!configFilename) { + this.error('No configuration file specified. Use --config flag to specify a configuration file.') + return + } const { configDirectory, configFilenames } = splitConfigFilePath(configFilename) // Rest of the method... const { data: unappliedPlans } = await api.projects.findImportPlans(logicalId, { onlyUnapplied: true, }) + if (unappliedPlans.length === 0) { + this.log('No unapplied import plans found.') + return + } const plan = await this.#selectPlan(unappliedPlans) // Rest of the method... }packages/cli/src/constructs/api-check-codegen.ts (2)
110-123: Handling setup scripts from string content or file paths.
Defining separate objects forlocalSetupScriptandsetupScriptPathis fine. However, if both are provided, we’ll end up with twosetupScriptobjects in the final output. It might be beneficial to enforce a mutual exclusion or define a preference.Would you like help adding a fallback or merging these properties to avoid potential conflicts?
125-138: Symmetrical teardown script logic.
Mirroring the approach from the setup script is consistent. Keep in mind the same mutual-exclusion considerations if bothlocalTearDownScriptandtearDownScriptPathare set.packages/cli/src/constructs/check-codegen.ts (1)
164-181: Lint warnings about returning a value from a void function.
Theswitchstatements immediately return calls to other.gencode()methods. If these are typed to returnvoid, removingreturnwould align better with certain lint rules:- return this.browserCheckCodegen.gencode(logicalId, resource as BrowserCheckResource, context) + this.browserCheckCodegen.gencode(logicalId, resource as BrowserCheckResource, context)And similarly for lines 171, 173, 175, and 177.
🧰 Tools
🪛 Biome (1.9.4)
[error] 169-169: The function should not return a value because its return type is void.
The function is here:
'void' signals the absence of value. The returned value is likely to be ignored by the caller.
(lint/correctness/noVoidTypeReturn)
[error] 171-171: The function should not return a value because its return type is void.
The function is here:
'void' signals the absence of value. The returned value is likely to be ignored by the caller.
(lint/correctness/noVoidTypeReturn)
[error] 173-173: The function should not return a value because its return type is void.
The function is here:
'void' signals the absence of value. The returned value is likely to be ignored by the caller.
(lint/correctness/noVoidTypeReturn)
[error] 175-175: The function should not return a value because its return type is void.
The function is here:
'void' signals the absence of value. The returned value is likely to be ignored by the caller.
(lint/correctness/noVoidTypeReturn)
[error] 177-177: The function should not return a value because its return type is void.
The function is here:
'void' signals the absence of value. The returned value is likely to be ignored by the caller.
(lint/correctness/noVoidTypeReturn)
packages/cli/src/commands/import/plan.ts (3)
52-82: Handle additional HTTP error codes gracefully.
Currently, only 404 status codes have a custom error message. Consider adding user-friendly messages for other common errors such as 401 or 403 to improve the developer experience.
86-129: Allow user-specified output paths for generated code.
The generated file path is currently hardcoded. Offering a user-configurable file/directory path can enhance flexibility.Would you like help implementing a solution that accepts an output path?
130-223: Improve partial cancellation flow for existing plans.
When canceling multiple plans, an error in one plan halts the entire cancellation loop. Consider allowing partial cancellation or a rollback mechanism for unprocessed plans.packages/cli/src/constructs/tcp-check-codegen.ts (1)
7-12: Validate response time fields.
Consider enforcing a logical constraint (e.g.,degradedResponseTime <= maxResponseTime) to avoid confusion or invalid configurations.packages/cli/src/constructs/incidentio-alert-channel-codegen.ts (1)
13-25: API key extraction could be improved with early returnsThe
apiKeyFromHeadersfunction extracts the API key from the Authorization header, but the implementation could be simplified using early returns for better readability.function apiKeyFromHeaders (headers: HttpHeader[]): string | undefined { for (const header of headers) { - if (header.key.toLocaleLowerCase() !== 'authorization') { - continue - } - - if (!header.value.startsWith('Bearer ')) { - continue - } - - return header.value.replace('Bearer ', '') + if (header.key.toLocaleLowerCase() === 'authorization' && header.value.startsWith('Bearer ')) { + return header.value.replace('Bearer ', '') + } } + return undefined }packages/cli/src/constructs/construct-codegen.ts (1)
25-29:Resourceinterface is minimal yet effective.
payload: anydoes reduce type safety. In future, consider parameterizing the interface or introducing type refinements per resource type.-interface Resource { - type: ResourceType - logicalId: string - payload: any -} +interface Resource<TPayload = unknown> { + type: ResourceType + logicalId: string + payload: TPayload +}packages/cli/src/rest/projects.ts (1)
85-92: Minor improvement for filtering logic
The usage of optional parameters foronlyUnappliedandonlyUncommittedis correct. Consider whether the server should handle contradictory filters or if you want to guard them here.packages/cli/src/sourcegen/expr.ts (1)
42-57: Consider bracket notation for invalid identifiers
The comment at line 55 hints at handling property names that require bracket syntax. Consider adding logic to detect such cases and use bracket notation when needed.packages/cli/src/constructs/check-group-codegen.ts (1)
43-227: Consider better error handling for context lookups
The function currently swallows errors when looking up private locations or alert channels (lines 72–77, 110–115). Logging or graceful fallback might be preferable. Also consider splitting this function into smaller parts for easier maintainability.packages/cli/src/constructs/internal/codegen/context.ts (1)
3-4: Consider adding a more descriptive error message.
Throwing a bareMissingContextVariableMappingErrorcan make debugging harder. Including the requested ID or a custom message aids in tracing the missing mapping.-export class MissingContextVariableMappingError extends Error {} +export class MissingContextVariableMappingError extends Error { + constructor(message?: string) { + super(message || 'Context variable mapping not found.') + this.name = 'MissingContextVariableMappingError' + } +}
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (65)
packages/cli/e2e/__tests__/help.spec.ts(2 hunks)packages/cli/package.json(1 hunks)packages/cli/src/commands/import/apply.ts(1 hunks)packages/cli/src/commands/import/cancel.ts(1 hunks)packages/cli/src/commands/import/commit.ts(1 hunks)packages/cli/src/commands/import/plan.ts(1 hunks)packages/cli/src/constructs/alert-channel-codegen.ts(1 hunks)packages/cli/src/constructs/alert-channel-subscription-codegen.ts(1 hunks)packages/cli/src/constructs/alert-escalation-policy-codegen.ts(1 hunks)packages/cli/src/constructs/api-check-codegen.ts(1 hunks)packages/cli/src/constructs/browser-check-codegen.ts(1 hunks)packages/cli/src/constructs/check-codegen.ts(1 hunks)packages/cli/src/constructs/check-group-codegen.ts(1 hunks)packages/cli/src/constructs/check-group.ts(1 hunks)packages/cli/src/constructs/construct-codegen.ts(1 hunks)packages/cli/src/constructs/dashboard-codegen.ts(1 hunks)packages/cli/src/constructs/email-alert-channel-codegen.ts(1 hunks)packages/cli/src/constructs/frequency-codegen.ts(1 hunks)packages/cli/src/constructs/heartbeat-check-codegen.ts(1 hunks)packages/cli/src/constructs/incidentio-alert-channel-codegen.ts(1 hunks)packages/cli/src/constructs/internal/assertion-codegen.ts(1 hunks)packages/cli/src/constructs/internal/codegen/codegen.ts(1 hunks)packages/cli/src/constructs/internal/codegen/context.ts(1 hunks)packages/cli/src/constructs/internal/codegen/index.ts(1 hunks)packages/cli/src/constructs/key-value-pair-codegen.ts(1 hunks)packages/cli/src/constructs/maintenance-window-codegen.ts(1 hunks)packages/cli/src/constructs/msteams-alert-channel-codegen.ts(1 hunks)packages/cli/src/constructs/multi-step-check-codegen.ts(1 hunks)packages/cli/src/constructs/opsgenie-alert-channel-codegen.ts(1 hunks)packages/cli/src/constructs/pagerduty-alert-channel-codegen.ts(1 hunks)packages/cli/src/constructs/phone-call-alert-channel-codegen.ts(1 hunks)packages/cli/src/constructs/playwright-config-codegen.ts(1 hunks)packages/cli/src/constructs/playwright-config.ts(0 hunks)packages/cli/src/constructs/private-location-check-assignment-codegen.ts(1 hunks)packages/cli/src/constructs/private-location-codegen.ts(1 hunks)packages/cli/src/constructs/private-location-group-assignment-codegen.ts(1 hunks)packages/cli/src/constructs/ref-codegen.ts(1 hunks)packages/cli/src/constructs/retry-strategy-codegen.ts(1 hunks)packages/cli/src/constructs/slack-alert-channel-codegen.ts(1 hunks)packages/cli/src/constructs/sms-alert-channel-codegen.ts(1 hunks)packages/cli/src/constructs/tcp-check-codegen.ts(1 hunks)packages/cli/src/constructs/telegram-alert-channel-codegen.ts(1 hunks)packages/cli/src/constructs/webhook-alert-channel-codegen.ts(1 hunks)packages/cli/src/rest/projects.ts(3 hunks)packages/cli/src/sourcegen/args.ts(1 hunks)packages/cli/src/sourcegen/argsbuilder.ts(1 hunks)packages/cli/src/sourcegen/array.ts(1 hunks)packages/cli/src/sourcegen/arraybuilder.ts(1 hunks)packages/cli/src/sourcegen/boolean.ts(1 hunks)packages/cli/src/sourcegen/decl.ts(1 hunks)packages/cli/src/sourcegen/declbuilder.ts(1 hunks)packages/cli/src/sourcegen/expr.ts(1 hunks)packages/cli/src/sourcegen/exprbuilder.ts(1 hunks)packages/cli/src/sourcegen/identifier.ts(1 hunks)packages/cli/src/sourcegen/index.ts(1 hunks)packages/cli/src/sourcegen/null.ts(1 hunks)packages/cli/src/sourcegen/number.ts(1 hunks)packages/cli/src/sourcegen/object.ts(1 hunks)packages/cli/src/sourcegen/objectbuilder.ts(1 hunks)packages/cli/src/sourcegen/output.ts(1 hunks)packages/cli/src/sourcegen/program.ts(1 hunks)packages/cli/src/sourcegen/string.ts(1 hunks)packages/cli/src/sourcegen/undefined.ts(1 hunks)packages/cli/src/sourcegen/unknown.ts(1 hunks)packages/cli/src/sourcegen/value.ts(1 hunks)
💤 Files with no reviewable changes (1)
- packages/cli/src/constructs/playwright-config.ts
🧰 Additional context used
🧬 Code Definitions (42)
packages/cli/src/sourcegen/undefined.ts (2)
packages/cli/src/sourcegen/index.ts (3)
UndefinedValue(31-31)Value(33-33)Output(28-28)packages/cli/src/sourcegen/output.ts (1)
Output(40-85)
packages/cli/src/sourcegen/null.ts (2)
packages/cli/src/sourcegen/index.ts (3)
NullValue(24-24)Value(33-33)Output(28-28)packages/cli/src/sourcegen/output.ts (1)
Output(40-85)
packages/cli/src/sourcegen/boolean.ts (2)
packages/cli/src/sourcegen/index.ts (3)
BooleanValue(5-5)Value(33-33)Output(28-28)packages/cli/src/sourcegen/output.ts (1)
Output(40-85)
packages/cli/e2e/__tests__/help.spec.ts (1)
packages/cli/e2e/run-checkly.ts (1)
runChecklyCli(7-77)
packages/cli/src/sourcegen/value.ts (1)
packages/cli/src/sourcegen/output.ts (1)
Output(40-85)
packages/cli/src/sourcegen/array.ts (2)
packages/cli/src/sourcegen/index.ts (3)
ArrayValue(3-3)Value(33-33)Output(28-28)packages/cli/src/sourcegen/output.ts (1)
Output(40-85)
packages/cli/src/sourcegen/object.ts (4)
packages/cli/src/sourcegen/index.ts (3)
Value(33-33)ObjectValue(26-26)Output(28-28)packages/cli/src/sourcegen/arraybuilder.ts (1)
value(62-65)packages/cli/src/sourcegen/objectbuilder.ts (1)
value(57-60)packages/cli/src/sourcegen/output.ts (1)
Output(40-85)
packages/cli/src/sourcegen/unknown.ts (7)
packages/cli/src/sourcegen/arraybuilder.ts (4)
value(62-65)array(12-16)array(50-52)object(54-56)packages/cli/src/sourcegen/objectbuilder.ts (4)
value(57-60)array(45-47)object(12-16)object(49-51)packages/cli/src/sourcegen/null.ts (1)
NullValue(4-8)packages/cli/src/sourcegen/undefined.ts (1)
UndefinedValue(4-8)packages/cli/src/sourcegen/string.ts (1)
StringValue(6-17)packages/cli/src/sourcegen/boolean.ts (1)
BooleanValue(4-15)packages/cli/src/sourcegen/number.ts (1)
NumberValue(4-15)
packages/cli/src/constructs/email-alert-channel-codegen.ts (3)
packages/cli/src/constructs/alert-channel-codegen.ts (2)
AlertChannelResource(21-29)buildAlertChannelProps(31-51)packages/cli/src/constructs/internal/codegen/index.ts (2)
Codegen(1-1)Context(2-2)packages/cli/src/constructs/internal/codegen/context.ts (1)
Context(5-121)
packages/cli/src/constructs/multi-step-check-codegen.ts (4)
packages/cli/src/constructs/check-codegen.ts (2)
CheckResource(15-33)buildCheckProps(35-144)packages/cli/src/constructs/playwright-config-codegen.ts (2)
PlaywrightConfigResource(4-4)valueForPlaywrightConfig(6-8)packages/cli/src/constructs/internal/codegen/index.ts (2)
Codegen(1-1)Context(2-2)packages/cli/src/constructs/internal/codegen/context.ts (1)
Context(5-121)
packages/cli/src/constructs/private-location-check-assignment-codegen.ts (2)
packages/cli/src/constructs/internal/codegen/index.ts (2)
Codegen(1-1)Context(2-2)packages/cli/src/constructs/internal/codegen/context.ts (1)
Context(5-121)
packages/cli/src/constructs/telegram-alert-channel-codegen.ts (4)
packages/cli/src/constructs/webhook-alert-channel-codegen.ts (2)
WebhookAlertChannelResource(28-31)WebhookAlertChannelResourceConfig(17-26)packages/cli/src/constructs/internal/codegen/index.ts (2)
Codegen(1-1)Context(2-2)packages/cli/src/constructs/internal/codegen/context.ts (1)
Context(5-121)packages/cli/src/constructs/alert-channel-codegen.ts (1)
buildAlertChannelProps(31-51)
packages/cli/src/sourcegen/output.ts (3)
packages/cli/src/sourcegen/arraybuilder.ts (1)
value(62-65)packages/cli/src/sourcegen/objectbuilder.ts (1)
value(57-60)packages/cli/src/sourcegen/index.ts (1)
Output(28-28)
packages/cli/src/constructs/private-location-group-assignment-codegen.ts (2)
packages/cli/src/constructs/internal/codegen/index.ts (2)
Codegen(1-1)Context(2-2)packages/cli/src/constructs/internal/codegen/context.ts (1)
Context(5-121)
packages/cli/src/constructs/browser-check-codegen.ts (4)
packages/cli/src/constructs/check-codegen.ts (2)
CheckResource(15-33)buildCheckProps(35-144)packages/cli/src/constructs/playwright-config-codegen.ts (2)
PlaywrightConfigResource(4-4)valueForPlaywrightConfig(6-8)packages/cli/src/constructs/internal/codegen/index.ts (2)
Codegen(1-1)Context(2-2)packages/cli/src/constructs/internal/codegen/context.ts (1)
Context(5-121)
packages/cli/src/sourcegen/identifier.ts (4)
packages/cli/src/sourcegen/index.ts (4)
IdentifierValue(23-23)Value(33-33)Output(28-28)ident(23-23)packages/cli/src/sourcegen/arraybuilder.ts (2)
value(62-65)ident(46-48)packages/cli/src/sourcegen/objectbuilder.ts (2)
value(57-60)ident(41-43)packages/cli/src/sourcegen/output.ts (1)
Output(40-85)
packages/cli/src/constructs/api-check-codegen.ts (5)
packages/cli/src/constructs/check-codegen.ts (2)
CheckResource(15-33)buildCheckProps(35-144)packages/cli/src/constructs/internal/assertion-codegen.ts (2)
valueForNumericAssertion(4-43)valueForGeneralAssertion(45-146)packages/cli/src/constructs/internal/codegen/index.ts (2)
Codegen(1-1)Context(2-2)packages/cli/src/constructs/internal/codegen/context.ts (1)
Context(5-121)packages/cli/src/constructs/key-value-pair-codegen.ts (1)
valueForKeyValuePair(4-17)
packages/cli/src/sourcegen/string.ts (4)
packages/cli/src/sourcegen/index.ts (3)
StringValue(30-30)Value(33-33)Output(28-28)packages/cli/src/sourcegen/arraybuilder.ts (1)
value(62-65)packages/cli/src/sourcegen/objectbuilder.ts (1)
value(57-60)packages/cli/src/sourcegen/output.ts (1)
Output(40-85)
packages/cli/src/constructs/tcp-check-codegen.ts (4)
packages/cli/src/constructs/check-codegen.ts (2)
CheckResource(15-33)buildCheckProps(35-144)packages/cli/src/constructs/internal/assertion-codegen.ts (2)
valueForGeneralAssertion(45-146)valueForNumericAssertion(4-43)packages/cli/src/constructs/internal/codegen/index.ts (2)
Codegen(1-1)Context(2-2)packages/cli/src/constructs/internal/codegen/context.ts (1)
Context(5-121)
packages/cli/src/constructs/alert-channel-subscription-codegen.ts (1)
packages/cli/src/constructs/internal/codegen/context.ts (1)
Context(5-121)
packages/cli/src/constructs/dashboard-codegen.ts (2)
packages/cli/src/constructs/internal/codegen/index.ts (2)
Codegen(1-1)Context(2-2)packages/cli/src/constructs/internal/codegen/context.ts (1)
Context(5-121)
packages/cli/src/constructs/pagerduty-alert-channel-codegen.ts (3)
packages/cli/src/constructs/alert-channel-codegen.ts (2)
AlertChannelResource(21-29)buildAlertChannelProps(31-51)packages/cli/src/constructs/internal/codegen/index.ts (2)
Codegen(1-1)Context(2-2)packages/cli/src/constructs/internal/codegen/context.ts (1)
Context(5-121)
packages/cli/src/constructs/opsgenie-alert-channel-codegen.ts (3)
packages/cli/src/constructs/alert-channel-codegen.ts (2)
AlertChannelResource(21-29)buildAlertChannelProps(31-51)packages/cli/src/constructs/internal/codegen/index.ts (2)
Codegen(1-1)Context(2-2)packages/cli/src/constructs/internal/codegen/context.ts (1)
Context(5-121)
packages/cli/src/sourcegen/declbuilder.ts (2)
packages/cli/src/sourcegen/index.ts (6)
decl(11-11)IdentifierValue(23-23)DeclarationBuilder(12-12)Value(33-33)VariableDeclaration(7-7)ExportDeclaration(8-8)packages/cli/src/sourcegen/decl.ts (4)
IdentifierDeclaration(9-20)VariableDeclarationOptions(22-24)VariableDeclaration(26-52)ExportDeclaration(54-66)
packages/cli/src/constructs/construct-codegen.ts (12)
packages/cli/src/constructs/internal/codegen/index.ts (2)
Codegen(1-1)Context(2-2)packages/cli/src/constructs/alert-channel-codegen.ts (1)
AlertChannelCodegen(53-101)packages/cli/src/constructs/alert-channel-subscription-codegen.ts (1)
AlertChannelSubscriptionCodegen(9-24)packages/cli/src/constructs/check-codegen.ts (1)
CheckCodegen(146-182)packages/cli/src/constructs/check-group-codegen.ts (1)
CheckGroupCodegen(231-252)packages/cli/src/constructs/dashboard-codegen.ts (1)
DashboardCodegen(31-140)packages/cli/src/constructs/maintenance-window-codegen.ts (1)
MaintenanceWindowCodegen(16-64)packages/cli/src/constructs/private-location-codegen.ts (1)
PrivateLocationCodegen(14-44)packages/cli/src/constructs/private-location-check-assignment-codegen.ts (1)
PrivateLocationCheckAssignmentCodegen(8-17)packages/cli/src/constructs/private-location-group-assignment-codegen.ts (1)
PrivateLocationGroupAssignmentCodegen(8-17)packages/cli/src/sourcegen/program.ts (1)
Program(7-53)packages/cli/src/constructs/internal/codegen/context.ts (1)
Context(5-121)
packages/cli/src/constructs/maintenance-window-codegen.ts (2)
packages/cli/src/constructs/internal/codegen/index.ts (2)
Codegen(1-1)Context(2-2)packages/cli/src/constructs/internal/codegen/context.ts (1)
Context(5-121)
packages/cli/src/constructs/slack-alert-channel-codegen.ts (2)
packages/cli/src/constructs/alert-channel-codegen.ts (2)
AlertChannelResource(21-29)buildAlertChannelProps(31-51)packages/cli/src/constructs/internal/codegen/context.ts (1)
Context(5-121)
packages/cli/src/constructs/check-codegen.ts (6)
packages/cli/src/constructs/frequency-codegen.ts (2)
FrequencyResource(4-4)valueForFrequency(6-54)packages/cli/src/constructs/alert-escalation-policy-codegen.ts (2)
AlertEscalationResource(4-4)valueForAlertEscalation(6-65)packages/cli/src/constructs/retry-strategy-codegen.ts (2)
RetryStrategyResource(4-4)valueForRetryStrategy(6-77)packages/cli/src/constructs/internal/codegen/index.ts (2)
Context(2-2)Codegen(1-1)packages/cli/src/constructs/key-value-pair-codegen.ts (1)
valueForKeyValuePair(4-17)packages/cli/src/constructs/api-check-codegen.ts (1)
ApiCheckResource(8-19)
packages/cli/src/sourcegen/decl.ts (3)
packages/cli/src/sourcegen/output.ts (1)
Output(40-85)packages/cli/src/sourcegen/index.ts (6)
Output(28-28)IdentifierValue(23-23)VariableDeclaration(7-7)Value(33-33)ExportDeclaration(8-8)decl(11-11)packages/cli/src/sourcegen/declbuilder.ts (1)
decl(5-9)
packages/cli/src/constructs/incidentio-alert-channel-codegen.ts (4)
packages/cli/src/constructs/webhook-alert-channel-codegen.ts (2)
WebhookAlertChannelResource(28-31)WebhookAlertChannelResourceConfig(17-26)packages/cli/src/constructs/internal/codegen/index.ts (2)
Codegen(1-1)Context(2-2)packages/cli/src/constructs/internal/codegen/context.ts (1)
Context(5-121)packages/cli/src/constructs/alert-channel-codegen.ts (1)
buildAlertChannelProps(31-51)
packages/cli/src/constructs/private-location-codegen.ts (2)
packages/cli/src/constructs/internal/codegen/index.ts (2)
Codegen(1-1)Context(2-2)packages/cli/src/constructs/internal/codegen/context.ts (1)
Context(5-121)
packages/cli/src/constructs/msteams-alert-channel-codegen.ts (4)
packages/cli/src/constructs/webhook-alert-channel-codegen.ts (2)
WebhookAlertChannelResource(28-31)WebhookAlertChannelResourceConfig(17-26)packages/cli/src/constructs/internal/codegen/index.ts (2)
Codegen(1-1)Context(2-2)packages/cli/src/constructs/internal/codegen/context.ts (1)
Context(5-121)packages/cli/src/constructs/alert-channel-codegen.ts (1)
buildAlertChannelProps(31-51)
packages/cli/src/constructs/sms-alert-channel-codegen.ts (2)
packages/cli/src/constructs/alert-channel-codegen.ts (2)
AlertChannelResource(21-29)buildAlertChannelProps(31-51)packages/cli/src/constructs/internal/codegen/context.ts (1)
Context(5-121)
packages/cli/src/constructs/phone-call-alert-channel-codegen.ts (3)
packages/cli/src/constructs/alert-channel-codegen.ts (2)
AlertChannelResource(21-29)buildAlertChannelProps(31-51)packages/cli/src/constructs/internal/codegen/index.ts (2)
Codegen(1-1)Context(2-2)packages/cli/src/constructs/internal/codegen/context.ts (1)
Context(5-121)
packages/cli/src/constructs/alert-channel-codegen.ts (3)
packages/cli/src/constructs/internal/codegen/index.ts (2)
Codegen(1-1)Context(2-2)packages/cli/src/sourcegen/program.ts (1)
Program(7-53)packages/cli/src/constructs/internal/codegen/context.ts (1)
Context(5-121)
packages/cli/src/sourcegen/expr.ts (3)
packages/cli/src/sourcegen/index.ts (10)
ExpressionValue(15-15)Value(33-33)NewExpressionValue(16-16)ArgumentsValue(1-1)args(2-2)Output(28-28)CallExpressionValue(17-17)MemberExpressionValue(18-18)BinaryExpressionValue(19-19)UnaryExpressionValue(20-20)packages/cli/src/sourcegen/args.ts (1)
ArgumentsValue(4-27)packages/cli/src/sourcegen/output.ts (1)
Output(40-85)
packages/cli/src/constructs/check-group-codegen.ts (7)
packages/cli/src/constructs/frequency-codegen.ts (2)
FrequencyResource(4-4)valueForFrequency(6-54)packages/cli/src/constructs/alert-escalation-policy-codegen.ts (2)
AlertEscalationResource(4-4)valueForAlertEscalation(6-65)packages/cli/src/constructs/retry-strategy-codegen.ts (2)
RetryStrategyResource(4-4)valueForRetryStrategy(6-77)packages/cli/src/constructs/internal/codegen/context.ts (1)
Context(5-121)packages/cli/src/constructs/internal/codegen/index.ts (2)
Context(2-2)Codegen(1-1)packages/cli/src/constructs/key-value-pair-codegen.ts (1)
valueForKeyValuePair(4-17)packages/cli/src/constructs/api-check-codegen.ts (1)
valueForAssertion(21-38)
packages/cli/src/constructs/heartbeat-check-codegen.ts (3)
packages/cli/src/constructs/check-codegen.ts (2)
CheckResource(15-33)buildCheckProps(35-144)packages/cli/src/constructs/internal/codegen/index.ts (2)
Codegen(1-1)Context(2-2)packages/cli/src/constructs/internal/codegen/context.ts (1)
Context(5-121)
packages/cli/src/constructs/webhook-alert-channel-codegen.ts (7)
packages/cli/src/constructs/alert-channel-codegen.ts (2)
AlertChannelResource(21-29)buildAlertChannelProps(31-51)packages/cli/src/constructs/key-value-pair-codegen.ts (1)
valueForKeyValuePair(4-17)packages/cli/src/constructs/internal/codegen/index.ts (2)
Codegen(1-1)Context(2-2)packages/cli/src/constructs/incidentio-alert-channel-codegen.ts (1)
IncidentioAlertChannelCodegen(29-62)packages/cli/src/constructs/msteams-alert-channel-codegen.ts (1)
MSTeamsAlertChannelCodegen(14-40)packages/cli/src/constructs/telegram-alert-channel-codegen.ts (1)
TelegramAlertChannelCodegen(28-67)packages/cli/src/constructs/internal/codegen/context.ts (1)
Context(5-121)
packages/cli/src/sourcegen/argsbuilder.ts (2)
packages/cli/src/sourcegen/exprbuilder.ts (4)
build(39-41)context(34-37)ExpressionValueBuilder(11-42)expr(5-9)packages/cli/src/sourcegen/args.ts (1)
ArgumentsValue(4-27)
packages/cli/src/sourcegen/arraybuilder.ts (9)
packages/cli/src/sourcegen/objectbuilder.ts (7)
array(45-47)build(62-64)value(57-60)ObjectValueBuilder(18-65)object(12-16)object(49-51)expr(53-55)packages/cli/src/sourcegen/exprbuilder.ts (4)
build(39-41)context(34-37)ExpressionValueBuilder(11-42)expr(5-9)packages/cli/src/sourcegen/array.ts (1)
ArrayValue(4-31)packages/cli/src/sourcegen/string.ts (1)
StringValue(6-17)packages/cli/src/sourcegen/boolean.ts (1)
BooleanValue(4-15)packages/cli/src/sourcegen/number.ts (1)
NumberValue(4-15)packages/cli/src/sourcegen/null.ts (1)
NullValue(4-8)packages/cli/src/sourcegen/undefined.ts (1)
UndefinedValue(4-8)packages/cli/src/sourcegen/identifier.ts (1)
IdentifierValue(4-15)
packages/cli/src/sourcegen/objectbuilder.ts (9)
packages/cli/src/sourcegen/arraybuilder.ts (7)
object(54-56)build(71-73)value(62-65)ArrayValueBuilder(18-74)array(12-16)array(50-52)expr(58-60)packages/cli/src/sourcegen/exprbuilder.ts (4)
build(39-41)context(34-37)ExpressionValueBuilder(11-42)expr(5-9)packages/cli/src/sourcegen/object.ts (2)
ObjectProperty(4-12)ObjectValue(14-39)packages/cli/src/sourcegen/string.ts (1)
StringValue(6-17)packages/cli/src/sourcegen/boolean.ts (1)
BooleanValue(4-15)packages/cli/src/sourcegen/number.ts (1)
NumberValue(4-15)packages/cli/src/sourcegen/null.ts (1)
NullValue(4-8)packages/cli/src/sourcegen/undefined.ts (1)
UndefinedValue(4-8)packages/cli/src/sourcegen/identifier.ts (1)
IdentifierValue(4-15)
🪛 Biome (1.9.4)
packages/cli/src/constructs/check-codegen.ts
[error] 169-169: The function should not return a value because its return type is void.
The function is here:
'void' signals the absence of value. The returned value is likely to be ignored by the caller.
(lint/correctness/noVoidTypeReturn)
[error] 171-171: The function should not return a value because its return type is void.
The function is here:
'void' signals the absence of value. The returned value is likely to be ignored by the caller.
(lint/correctness/noVoidTypeReturn)
[error] 173-173: The function should not return a value because its return type is void.
The function is here:
'void' signals the absence of value. The returned value is likely to be ignored by the caller.
(lint/correctness/noVoidTypeReturn)
[error] 175-175: The function should not return a value because its return type is void.
The function is here:
'void' signals the absence of value. The returned value is likely to be ignored by the caller.
(lint/correctness/noVoidTypeReturn)
[error] 177-177: The function should not return a value because its return type is void.
The function is here:
'void' signals the absence of value. The returned value is likely to be ignored by the caller.
(lint/correctness/noVoidTypeReturn)
packages/cli/src/constructs/webhook-alert-channel-codegen.ts
[error] 102-102: The function should not return a value because its return type is void.
The function is here:
'void' signals the absence of value. The returned value is likely to be ignored by the caller.
(lint/correctness/noVoidTypeReturn)
[error] 114-114: The function should not return a value because its return type is void.
The function is here:
'void' signals the absence of value. The returned value is likely to be ignored by the caller.
(lint/correctness/noVoidTypeReturn)
🔇 Additional comments (158)
packages/cli/src/sourcegen/value.ts (1)
3-5: Well-designed base class for value type hierarchy.The abstract
Valueclass establishes a clean, polymorphic interface through therendermethod that all subclasses must implement. This approach provides flexibility while ensuring consistent rendering behavior throughout the source generation system.packages/cli/src/constructs/internal/codegen/index.ts (1)
1-2: Follows standard module export pattern.This index file efficiently re-exports classes from their respective modules, creating a clean API surface and simplifying imports throughout the codebase. This is a good practice for maintainable TypeScript modules.
packages/cli/src/sourcegen/args.ts (1)
4-27: Clean implementation of arguments value rendering.The
ArgumentsValueimplementation correctly extends theValueclass and provides a well-structuredrendermethod. The code properly handles parentheses, comma separation, and whitespace between arguments, including the edge case of the first item.packages/cli/src/constructs/playwright-config-codegen.ts (1)
1-8: Clean and focused implementation of a Playwright config transformer.This code aligns with the source code generation pattern, providing a straightforward way to transform Playwright configurations into the AST-like representation required by the sourcegen system. The implementation is minimal and follows the same pattern used elsewhere in the codebase.
packages/cli/src/constructs/key-value-pair-codegen.ts (1)
4-17: Good implementation of conditional property handling.The function correctly implements conditional logic for optional properties (
lockedandsecret), only including them when they're defined. This prevents undefined values from appearing in the generated code and follows best practices for optional fields.packages/cli/src/constructs/check-group.ts (1)
16-17: Import syntax modernization.The change from
import type { X }toimport { type X }reflects a more modern TypeScript import style. This doesn't affect functionality but helps standardize the codebase's import syntax.packages/cli/package.json (1)
63-65: CLI feature addition for importing resources.The new "import" topic entry in the package.json file properly documents the new import functionality for users. This matches the PR's objective of adding AST-like source code generation capabilities, likely for the purpose of importing existing resources into a project.
packages/cli/src/sourcegen/identifier.ts (1)
1-19: Implementation looks correct and well-structured.The
IdentifierValueclass extendingValuealong with theidenthelper function provides a clean implementation for handling identifier values in the source generation process. The code follows good practices with proper type definitions and clear responsibilities.packages/cli/src/sourcegen/array.ts (1)
1-31: Implementation looks correct and consistent with the source generation pattern.The
ArrayValueclass properly extendsValueand provides appropriate rendering logic for arrays, with special handling for empty arrays.packages/cli/e2e/__tests__/help.spec.ts (2)
26-36: Test coverage for the new import command looks good.The test case properly verifies that the CLI provides appropriate help text for the new import command and its subcommands.
51-52: Additional commands section is correctly updated.The addition of the import command to the additional commands section ensures that users can discover the new functionality through the main help output.
packages/cli/src/sourcegen/object.ts (1)
1-39: Implementation of ObjectValue looks correct and well-structured.The
ObjectPropertyandObjectValueclasses provide a clean implementation for handling object structures in the source generation process.packages/cli/src/constructs/internal/codegen/codegen.ts (1)
4-16: Well-structured abstract class for code generationThis abstract class serves as a solid foundation for implementing various code generators, with a clear interface for subclasses to follow. The generic type parameter
Tprovides flexibility for different resource types.packages/cli/src/sourcegen/string.ts (1)
1-23: LGTM! StringValue implementation is clean and follows the Value patternThe implementation properly extends the Value class and provides appropriate rendering functionality. It follows the same pattern as other Value implementations in the system.
packages/cli/src/sourcegen/unknown.ts (1)
1-41: Well-designed recursive value conversion utilityThis function provides a robust way to convert arbitrary JavaScript values into the appropriate Value objects. The recursive handling of arrays and objects is particularly well-implemented.
packages/cli/src/sourcegen/program.ts (1)
1-54: LGTM! Program class provides a good foundation for code generationThe Program class effectively manages imports and code sections, with a clean render method to produce the final output. Overall, this is a well-designed central component for the source generation system.
packages/cli/src/constructs/browser-check-codegen.ts (2)
6-12: Clear and well-structured interface definition.The
BrowserCheckResourceinterface properly extendsCheckResourceand defines all necessary properties for browser checks. The typings are appropriate, and optional properties are correctly marked.
16-46: Implementation of the code generation is complete and follows established patterns.The
BrowserCheckCodegenclass correctly extends the baseCodegenclass and implements thegencodemethod as expected. The method properly imports the necessary construct, builds the program structure, and includes all the required properties. The call tobuildCheckPropsensures that all properties from the baseCheckResourceinterface are included.packages/cli/src/commands/import/commit.ts (1)
12-68: Well-structured implementation of the commit command.The overall structure of the
ImportCommitCommandclass is well designed. It extendsAuthCommand, defines appropriate flags, and implements a clear workflow for selecting and committing import plans. The use of prompts for user interaction is well implemented, and there's appropriate error handling for the case where a plan ID is missing from the plan map.packages/cli/src/commands/import/cancel.ts (1)
12-112: Well-designed command implementation with good user experience.The
ImportCancelCommandclass is well structured and provides a good user experience with clear options and feedback. The implementation correctly handles cancellation of multiple plans, exiting without changes, and error scenarios. The addition of an "all plans" option is especially useful.packages/cli/src/constructs/dashboard-codegen.ts (3)
4-27: Comprehensive interface with well-defined properties.The
DashboardResourceinterface defines a complete set of dashboard properties with appropriate types and optionality markers. The interface is well-organized and should cover all needed dashboard configuration options.
31-139: Clean and consistent implementation of the dashboard code generation.The
DashboardCodegenclass follows the established pattern for code generation in this codebase. It properly handles all the properties defined in the interface, checking if each is defined before adding it to the generated code. The use of the builder pattern makes the code structure clear and maintainable.
84-136: Consistent handling of boolean properties.The code uses
!== undefinedchecks for boolean properties, which is the correct approach since it allows for explicitly setfalsevalues to be included in the generated code.packages/cli/src/constructs/frequency-codegen.ts (1)
1-54: Well-structured implementation for frequency code generationThe implementation cleanly handles both numeric frequency values and Frequency objects, with proper detection of predefined constants. Good use of type safety with the union type FrequencyResource.
packages/cli/src/constructs/telegram-alert-channel-codegen.ts (1)
26-67: Well-structured implementation for Telegram alert channel generationThe implementation correctly extracts necessary information from config, handles conditional properties appropriately, and follows the Codegen pattern established in the codebase.
packages/cli/src/constructs/retry-strategy-codegen.ts (3)
39-58: 'FIXED' and 'LINEAR' strategies have identical implementationsBoth strategies are using the
fixedStrategybuilder. This might be intentional but could be confusing without a comment explaining why LINEAR uses fixedStrategy.Are 'FIXED' and 'LINEAR' retry strategies expected to have identical implementations? If intentional, consider adding a comment explaining this design choice.
case 'LINEAR': return expr(ident('RetryStrategyBuilder'), builder => { + // LINEAR strategy uses fixedStrategy internally as they share the same implementation builder.member(ident('fixedStrategy')) builder.call(builder => { builder.object(builder => { buildCommonOptions(strategy, builder) }) }) })
6-38: Well-structured implementation with good handling of edge casesThe implementation correctly handles null/undefined cases and provides a helper function for common options, making the code more maintainable.
59-77: Good error handling for unsupported typesThe implementation provides appropriate error handling for unsupported strategy types, which helps with debugging and prevents silent failures.
packages/cli/src/constructs/heartbeat-check-codegen.ts (1)
1-29: Clean implementation of heartbeat check code generationThe implementation correctly extends the Codegen class, properly sets required properties, and reuses code through the buildCheckProps utility. The structure follows the established patterns in the codebase.
packages/cli/src/constructs/maintenance-window-codegen.ts (1)
4-12: Well-structured resource interface.This interface clearly defines all the necessary fields for maintaining a maintenance window resource in code generation, ensuring a strong contract for future usage.
packages/cli/src/constructs/multi-step-check-codegen.ts (1)
6-11: Extending fromCheckResourceis a good approach.Including multi-step specifics on top of a shared base streamlines code generation for checks, reducing duplication.
packages/cli/src/sourcegen/decl.ts (4)
5-7: Proper use of an abstract class.Having an abstract
Declarationbase class provides a clean extension point for specialized declarations.
9-20: No immediate concerns withIdentifierDeclaration.The straightforward rendering of the identifier looks consistent with the rest of the code generation framework.
26-52: Variable declaration logic is clear and succinct.Using
letorconstbased on amutableflag cleanly handles different assignment scenarios without introducing unnecessary complexity.
54-66:ExportDeclarationusage is consistent.Wrapping a declaration with export logic is a neat way to keep declaration rendering separate from export handling.
packages/cli/src/constructs/private-location-group-assignment-codegen.ts (1)
1-17: Clean implementation of the private location group assignment code generation.The implementation correctly registers private location group assignments in the context and appropriately indicates that there's no code to generate for this resource type. The class extends Codegen with proper typing and follows the established pattern for resource codegen classes.
packages/cli/src/sourcegen/output.ts (2)
1-11: OutputBuffer implementation looks good.The OutputBuffer class provides a clean way to accumulate string chunks and combine them. The implementation is straightforward and effective.
13-38: OutputLine implementation is well structured.The OutputLine class properly manages line content and indentation. The collect method correctly handles indentation by repeating spaces based on the level.
packages/cli/src/constructs/alert-escalation-policy-codegen.ts (3)
1-8: Good setup of alert escalation resource type and imports.The file properly imports necessary components from sourcegen and defines the AlertEscalationResource type.
9-35: Well structured helper function for common arguments.The appendCommonArguments helper function nicely encapsulates the common configuration options for both escalation types, avoiding code duplication. The function correctly handles undefined checks for the optional properties.
37-65: Comprehensive handling of different escalation types.The switch statement properly handles the different escalation types with appropriate error handling for unsupported types. The implementation generates the correct expressions based on the escalation type and its properties.
packages/cli/src/commands/import/apply.ts (1)
1-21: Command setup looks good.The ImportApplyCommand class correctly extends AuthCommand and provides appropriate configuration for the command description and flags.
packages/cli/src/constructs/api-check-codegen.ts (9)
1-7: Imports and basic setup look correct.
No issues stand out here. The usage ofCodegen,Context, and other imports is consistent, and the structure follows typical TypeScript conventions.
8-19: Interface design is clear and extensible.
TheApiCheckResourceinterface cleanly extendsCheckResourceand adds API-specific fields. The commented-out TODO lines for script dependencies indicate future expansion.
21-38: Robust assertion value generator.
Your switch handles each assertion source thoroughly, and unrecognized sources are rejected with a clear error. This ensures strong type safety and error handling. Great job tying into the existing numeric vs. general assertion logic.
40-42: Constant declaration is straightforward.
Declaringconstructas'ApiCheck'is clear and easy to understand for subsequent usage.
43-73: Well-structured request property builder.
Withingencode, constructing therequestobject is done via a clear builder pattern. Optional fields likeipFamily,followRedirects, andskipSSLare handled gracefully. The loop forassertionsis also intuitive and consistent with your assertion codegen logic.
75-99: Body, headers, and query parameters inclusion is consistent.
LeveragingvalueForKeyValuePairto handle headers and query parameters ensures DRY logic. Everything is straightforward in building up these properties.
101-108: Basic auth integration is simple but lacks validation.
While the code currently allows empty Username/Password fields, this might be acceptable depending on your requirements. If you require non-empty credentials, consider adding a quick check or warning.Do we expect any specific constraints (e.g., non-empty credentials)? If so, verifying this before code generation would prevent error-prone configurations.
140-146: Degraded and max response times handled well.
Using optional checks forresource.degradedResponseTimeandresource.maxResponseTimeensures these fields are only set when relevant.
148-149: Seamless integration with shared check props.
InvokingbuildCheckPropsfinalizes the API check resource generation without redundant logic. This indicates a good separation of concerns.packages/cli/src/constructs/internal/assertion-codegen.ts (2)
4-43: Comprehensive numeric assertion builder.
Your switch statement covers all numeric comparison cases. Parsing the target as an integer prevents unexpected type mismatches. The default case ensures unknown comparisons are rejected early.
45-146: Flexible general assertion builder.
You’ve addressed a wide range of comparison types (like key/value checks, null checks, emptiness checks). The fallback error handling for unknown comparisons is robust. This uniform approach simplifies expansions if new assertions emerge.packages/cli/src/constructs/private-location-check-assignment-codegen.ts (3)
3-6: Resource interface is minimal and focused.
ThePrivateLocationCheckAssignmentResourceinterface precisely captures the two key fields. This keeps it straightforward for downstream logic.
8-11: Preparation phase registers the assignment.
UsingregisterPrivateLocationCheckAssignmentensures the context is immediately aware of the relationship between private location and check, which keeps everything in sync.
13-16: No code generation needed for this resource.
Having a no-opgencodeis acceptable here, given it’s purely a relational mapping. This is clean and unambiguous.packages/cli/src/constructs/slack-alert-channel-codegen.ts (3)
5-11: Interface structure looks correct and consistent.
TheSlackAlertChannelResourceinterface cleanly extendsAlertChannelResourceand mandatesurl, which is essential for Slack integrations. The inclusion of an optionalchannelmaintains flexibility across different Slack workspaces.
16-18: Registration prefix is consistent with other alert channel codegens.
Using'slackAlert'as a prefix aligns with the standard naming convention seen in sister classes (e.g.,emailAlert). This ensures that variable naming in the context remains coherent and predictable.
20-43: Sufficient usage of shared alert channel properties.
CallingbuildAlertChannelProps(builder, resource)guarantees that common alert channel behaviors (like SSL expiry checks) are uniformly applied. This design is consistent with the overall codegen architecture.packages/cli/src/constructs/email-alert-channel-codegen.ts (3)
5-10: Interface mirrors standard patterns for alert channels.
TheEmailAlertChannelResourceneatly extendsAlertChannelResourcewith atypeand a simpleconfigobject. This design follows the pattern established by other alert channel resource interfaces.
15-17: Consistent registration of email alert channels.
Registering the resource with a'emailAlert'prefix keeps it parallel with Slack and future channels, simplifying the context lookups.
19-36: Proper layering via shared builder logic.
LeveragingbuildAlertChannelProps(builder, resource)ensures consistent handling of universal alert channel fields (like recovery/failure flags). The overall code generation approach is coherent and maintainable.packages/cli/src/constructs/alert-channel-subscription-codegen.ts (3)
3-7: Flexible subscription resource structure.
Allowing bothgroupIdandcheckIdto be optional ensures that subscriptions can be created for individual checks or entire groups. This design is flexible for different alerting needs.
9-18: Accurate registration logic but consider edge cases.
Registering check and/or group subscriptions inprepareis appropriate. However, if bothgroupIdandcheckIdare defined, ensure that subscribing an alert channel to both simultaneously is intended and doesn’t cause duplication.Would you like to confirm that subscribing the same channel to a check and a group is desired, or should we prevent double-subscriptions?
20-23: No generation required.
Leavinggencodeempty is valid since no code needs to be generated for mere subscriptions. This approach separates side effects (subscriptions) from code emission.packages/cli/src/constructs/check-codegen.ts (2)
15-33: Comprehensive check resource interface.
TheCheckResourceincludes a thorough set of optional fields, handling advanced configurations (e.g.,frequency,alertSettings,retryStrategy). This design cleanly accommodates multiple check types in one interface.
35-144: Robust property construction with graceful error handling.
- The
buildCheckPropsfunction systematically covers all check fields.- The try-catch blocks for
privateLocationIdsandalertChannelIdsallow for non-blocking fallback behavior, though silently ignoring errors could mask unexpected issues.Consider logging or clarifying such errors to avoid confusion in future debugging scenarios.
packages/cli/src/commands/import/plan.ts (1)
18-27: No immediate issues with the command definition.
The class definition correctly sets flags and description.packages/cli/src/constructs/tcp-check-codegen.ts (2)
14-25: Logic is consistent with existing assertion code.
This function correctly integrates with other assertion-generating utilities.
29-71: Well-structured TCP check code generation.
UsingbuildCheckPropskeeps property handling consistent across different check types.packages/cli/src/constructs/sms-alert-channel-codegen.ts (2)
5-11: Consider phone number validation for SMS alert channels.
You may want to validate or sanitize the phone number before generating code to prevent errors or logs containing invalid PII.Would you like a script to check for existing phone number validation code or relevant tests?
20-43: Implementation is consistent with other alert channel codegen classes.
No issues detected in the approach for generating the SMS alert channel.packages/cli/src/sourcegen/declbuilder.ts (3)
1-4: Well-structured importsThe imports are clean and focused, bringing in only the necessary components from related files.
5-9: Good implementation of the builder patternThe
declfunction provides a clean API for creating declarations using a builder pattern. The function signature is clear and the implementation is concise.
11-33: Well-designed builder class with proper encapsulationThe
DeclarationBuilderclass follows good design principles:
- Uses private fields (with
#prefix) for proper encapsulation- Implements a fluent interface by returning
thisfrom modifier methods- Clear and focused methods that handle specific aspects of declaration building
- Clean separation of concerns between variable declaration and export functionality
packages/cli/src/constructs/msteams-alert-channel-codegen.ts (3)
6-10: Clean interface extensionThe interface properly extends
WebhookAlertChannelResourceand correctly specifies the webhook type as 'WEBHOOK_MSTEAMS'.
14-18: Consistent registration pattern in prepare methodThe
preparemethod follows the established pattern of registering the alert channel with a descriptive prefix ('teamsAlert'), which helps maintain consistency across different alert channel types.
19-39: Well-structured code generationThe
gencodemethod implements a clean approach to generating code for MS Teams alert channels:
- Imports the necessary construct
- Retrieves the context-managed identifier
- Uses the declaration builder in a consistent manner
- Correctly includes the required properties (name, url)
- Reuses the common
buildAlertChannelPropsfunction for shared alert propertiespackages/cli/src/constructs/phone-call-alert-channel-codegen.ts (4)
5-11: Well-defined resource interfaceThe interface clearly defines the structure for phone call alert channels with appropriate types and property requirements. The optional
nameproperty is correctly marked with a question mark.
15-18: Consistent alert channel registrationThe
preparemethod maintains consistency with other alert channel implementations by using a descriptive prefix ('phoneCallAlert') when registering.
32-34: Proper handling of optional propertiesThe code correctly handles the optional
nameproperty with a conditional block, ensuring it's only included in the generated code when present.
20-43: Consistent code generation patternThe overall code generation follows the established pattern across alert channel types, making the codebase more maintainable and predictable.
packages/cli/src/constructs/private-location-codegen.ts (4)
4-10: Clean resource interface definitionThe interface clearly defines all required properties for a private location with appropriate types. Optional properties (
iconandproxyUrl) are correctly marked with question marks.
14-17: Simple and clear registrationThe
preparemethod follows a consistent pattern with other codegen classes, registering the private location with its ID.
32-38: Proper handling of multiple optional propertiesThe code correctly handles both optional properties (
iconandproxyUrl) with separate conditional blocks, ensuring they're only included in the generated code when present.
19-43: Consistent code generation implementationThe
gencodemethod maintains the same structure and approach used across other codegen classes, enhancing maintainability through consistent patterns:
- Imports the necessary construct
- Retrieves the context-managed identifier
- Builds declarations with the same pattern
- Properly handles required and optional properties
packages/cli/src/constructs/opsgenie-alert-channel-codegen.ts (3)
1-13: Well-structured interface definitionThe
OpsgenieAlertChannelResourceinterface correctly extendsAlertChannelResourceand includes all the necessary configuration properties for an OpsGenie alert channel. The type is properly defined as a string literal 'OPSGENIE', which ensures type safety when working with different alert channel types.
17-20: Consistent alert channel registration patternThe
preparemethod follows the established pattern for alert channel registration, using a descriptive prefix 'opsgenieAlert' which will help generate readable variable names in the output code.
22-44: Well-structured code generation implementationThe
gencodemethod follows a consistent pattern for generating source code for OpsGenie alert channels. The implementation correctly:
- Imports the required construct
- Looks up the alert channel ID from the context
- Extracts the configuration
- Generates the appropriate AST nodes using the builder pattern
- Includes all required configuration properties
- Applies the common alert channel properties
This implementation will produce clean, consistent code for OpsGenie alert channels.
packages/cli/src/constructs/pagerduty-alert-channel-codegen.ts (3)
5-12: Properly defined interface with optional propertiesThe
PagerdutyAlertChannelResourceinterface is well-structured, correctly extending the baseAlertChannelResourceand defining the required 'PAGERDUTY' type. The config object properly marksaccountandserviceNameas optional while makingserviceKeyrequired.
16-19: Consistent alert channel registration patternThe
preparemethod correctly registers the alert channel with the 'pagerdutyAlert' prefix, which maintains consistency with other alert channel implementations.
21-48: Robust code generation with proper handling of optional propertiesThe
gencodemethod correctly handles both required and optional configuration properties:
- It only includes
accountandserviceNamewhen they are defined- It always includes the required
serviceKeyproperty- It properly applies the common alert channel properties using
buildAlertChannelPropsThis conditional approach ensures that the generated code is clean and only includes relevant properties.
packages/cli/src/sourcegen/exprbuilder.ts (2)
5-9: Well-designed expression builder factory functionThe
exprfunction provides a clean way to create and configure expression values using the builder pattern. This approach enables fluent, readable code when generating expressions.
11-41: Comprehensive expression building capabilitiesThe
ExpressionValueBuilderclass provides a complete set of methods for building different types of expressions:
newfor constructing new expressionscallfor method callsmemberfor property accesscontextandbuildfor managing the builder stateThe implementation properly handles the builder context throughout method chaining and supports all the core expression types needed for code generation.
packages/cli/src/constructs/incidentio-alert-channel-codegen.ts (3)
7-11: Clear webhook type constraint with proper interface extensionThe
IncidentioAlertChannelResourceinterface correctly extends theWebhookAlertChannelResourceand constrains thewebhookTypeto specifically be 'WEBHOOK_INCIDENTIO', ensuring type safety when working with Incident.io webhooks.
29-32: Consistent alert channel registration patternThe
preparemethod follows the established pattern for alert channel registration, using a descriptive prefix 'incidentioAlert' for clear variable naming.
34-61: Clean implementation with proper API key extractionThe
gencodemethod correctly:
- Imports the necessary construct
- Retrieves the alert channel ID from the context
- Extracts the configuration
- Conditionally includes the API key when it's available
- Applies common alert channel properties
The code is well-structured and follows established patterns from other alert channel implementations while handling the specific requirements of Incident.io integration.
packages/cli/src/constructs/alert-channel-codegen.ts (9)
1-3: Imports look appropriate.
They properly fetch theCodegenandContextclasses from internal modules and theProgramandObjectValueBuilderfromsourcegen. No immediate issues.
4-10: Channel-specific codegen imports are well-organized.
Importing each channel’s codegen in a separate statement is clear and maintainable.
12-19: Union type enumeration is clear.
The definedAlertChannelTypeunion accurately captures the channel options. If additional channels are introduced in the future, be sure to update both this type and the corresponding codegens.
21-29: Interface structure is cohesive.
All relevant fields (sendRecovery,sendFailure, etc.) are included, and numeric/boolean fields are adequately represented. Theid: numberproperty is good for internal reference.
31-51: Property builder function is consistent.
By conditionally checking forundefined, the code avoids generating superfluous fields. The logic is readable and avoids confusion between falsey booleans and the truly undefined case.
53-62: Class definition extends common codegen pattern.
Declaring channel-specific codegens and grouping them intocodegensByTypesimplifies lookups. No issues noted.
63-82: Constructor initialization is well-structured.
Each channel codegen is instantiated and correctly indexed incodegensByType. This is straightforward and maintainable.
84-91:preparemethod design is intuitive.
The method properly dispatches to the relevant channel codegen based on resource type, throwing a clear error if unsupported.
93-100:gencodedispatch method is straightforward.
Mirrors theprepareflow, ensuring the correct codegen is used. This consistent structure helps ensure minimal duplication.packages/cli/src/sourcegen/index.ts (1)
1-33: Central re-exports are well-managed.
This “barrel” file conveniently consolidates exports for the variousValueand builder classes. The naming scheme is consistent, and the exports are straightforward.packages/cli/src/constructs/construct-codegen.ts (9)
1-3: Imports from internal and source modules are correct.
They align with the recognized class interfaces (Codegen,Context,Program). No concerns here.
4-12: Resource-specific codegen imports are clear.
Bringing in each specialized codegen for top-level resource handling is well-structured.
14-23:ResourceTypeunion is extensible.
Similar toAlertChannelType, it’s straightforward to add new resource types. Keep it updated if new resource categories are added.
31-41:resourceOrderimproves sorting but inverts typical ascending logic.
return bo - ao;sorts resources in descending order. If that’s intended for an internal ordering priority, it’s fine. Otherwise, confirm the desired sort direction.Do you intend to sort from highest to lowest priority or would ascending order be preferable?
43-49:sortResourcesis straightforward.
The function leveragesresourceOrderand returns a consistently sorted list. The logic is readable and easy to extend when new resource types are introduced.
51-61: Class fields centralize resource codegens.
The constructor references them. No immediate issues. This design fosters single entry for all resource type code generation.
63-86: Constructor organizes specialized codegens properly.
Objects are instantiated for each resource type and stored in a clear record mapping. Straightforward approach.
88-96:preparemethod logic is consistent.
Ensures the correct codegen is used based onresource.type, relying on a uniform signature. The error message is descriptive.
97-105:gencodedispatch is symmetrical toprepare.
Handles the same resource-based codegen lookup for generation. The uniform pattern keeps logic consistent across methods.packages/cli/src/rest/projects.ts (7)
27-27: No code to review
No content was added besides a blank line. Nothing to discuss.
39-49: Looks good!
The new interfaces for import plan changes and import plans look structurally sound.
81-84: Consider handling potential errors
Creating import plans is straightforward, but consider how to handle or log errors if the server responds with failures.
94-101: Listing import plans appears correct
This implementation is consistent with thefindImportPlansapproach and remains straightforward.
103-105: Looks good
The DELETE request approach for canceling an import plan is well-structured.
107-109: No issues spotted
The method is straightforward and consistent with typical REST design patterns for applying an import plan.
111-113: Implementation is appropriate
Similarly, committing an import plan aligns well with established patterns.packages/cli/src/sourcegen/expr.ts (5)
5-7: Base abstract class is fine
The abstractExpressionValueprovides a good foundation for specialized expressions.
8-24: Clean 'new' Expression Implementation
This neatly constructs a 'new' expression, combining the callee and arguments with appropriate spacing.
26-40: Function call expression is correct
Implementation is consistent with typical call patterns. Therendermethod is straightforward.
59-80: Binary expression operator coverage
The chosen operators cover many common scenarios. Adding parentheses for complex nesting might be beneficial in certain contexts, but this approach is acceptable for now.
82-98: Unary expression checks out
Implementation follows standard patterns for unary operators and rendering.packages/cli/src/constructs/check-group-codegen.ts (2)
1-41: Resource interfaces look comprehensive
Interfaces forBrowserCheckConfigResource,MultiStepCheckConfigResource, andCheckGroupResourceare well-defined and align with the overall check structure.
229-253: Code generation logic is well-structured
The class cleanly registers the resource and generates the final code snippet using the builder pattern. No major issues identified.packages/cli/src/constructs/webhook-alert-channel-codegen.ts (5)
1-11: Good use of imports and type definitions
The initial imports cleanly separate concerns for building alert channel props and advanced code generation. Everything appears consistent.
12-31: Interfaces provide clear structure
DefiningWebhookAlertChannelResourceConfigand extendingAlertChannelResourceforWebhookAlertChannelResourcelooks coherent and keeps the data model consistent with other alert channel resources.
33-74: Streamlined config builder
buildWebhookAlertChannelConfigfollows a consistent pattern to conditionally set fields. This approach is modular and maintainable.
76-83: Construct naming
Usingconst construct = 'WebhookAlertChannel'ensures the final code references a consistent resource name.
84-95: Delegation to specialized codegens
Mapping distinct webhook types to their specialized classes is a sound approach that promotes separation of concerns.packages/cli/src/sourcegen/objectbuilder.ts (3)
1-11: Imports and class references
All imports are relevant for building objects, expressions, and handling special value types. Code is nicely organized.
12-16: Reusable object construction
Theobject(...)helper function effectively encapsulates object building and returns a fully realizedValue.
18-65: Fluent interface for object creation
ObjectValueBuilder’s methods handle varied property types cleanly. This approach improves readability and modularity.packages/cli/src/sourcegen/arraybuilder.ts (3)
1-11: Imports set the stage for array building
All dependencies align well with generating arrays of differentValuesubclasses.
12-16: array(...) factory
EncapsulatingArrayValueBuildercreation behindarray(...)fosters a clean, fluent interface.
18-74: Fluent array builder
ArrayValueBuilderprovides a robust, chainable way to add various value types. Theempty()approach is a nice convenience.packages/cli/src/sourcegen/argsbuilder.ts (16)
1-11: Imports look good.
They provide all necessary dependencies for this builder pattern without introducing unused references or circular dependencies.
13-17: Theargsfunction is concise and straightforward.
This function effectively encapsulates the builder instantiation and usage, returning the constructedArgumentsValue. No issues identified.
19-19: Comment on circular dependency avoidance.
It's good practice to avoid extendingArrayValueBuilderhere to prevent circular imports. This provides a clear separation of responsibilities for argument values versus array values.
20-21: Private field for builder elements is well-scoped.
Using a private array#elementskeeps the implementation details hidden while providing a controlled interface for adding and retrieving values.
23-26:empty()method ensures a quick reset.
This is a convenient way to clear the builder state without re-instantiating the class.
28-34: String & boolean value additions.
The code is straightforward, and callingthis.value(...)maintains a consistent pattern for pushing new values into#elements.
36-38: Number value addition is correct.
No off-by-one or type issues spotted.
40-42: Null value handling is correct.
This method properly adds aNullValueinstance into the builder.
44-46: Undefined value handling is consistent.
Maintains the same approach as thenull()method.
48-50: Identifier values are properly supported.
This ensures references to named identifiers (e.g., variable names) are added to the builder array.
52-54:array(build: ...)usage.
Delegating array construction toarray(build)helps keep the code modular and avoids duplication.
56-58:object(build: ...)usage.
Similar toarray(), nicely delegates object construction to a dedicated builder function.
60-62:exprmethod is a neat way to build expressions.
Leverages theexprhelper, allowing for more complex expressions within arguments.
64-67:value()acts as a generic insertion point.
This gives maximum flexibility for pushing anyValueimplementation into the builder.
69-71:elementsgetter provides read-only access.
Useful for external examination or debugging without exposing direct writes to#elements.
73-75:build()method finalizes the argument values.
Returns a newArgumentsValueinstance containing the accumulated values. This completes the builder pattern cleanly.packages/cli/src/constructs/internal/codegen/context.ts (1)
5-121: Overall Context class design is clear and maintains good data integrity.
- Each register/lookup method pairs well, storing and retrieving identifiers in private
Mapfields.- The usage of numeric vs. string keys is consistent with the domain logic.
- Error handling on undefined mappings is correct, though a more descriptive error (see above) is recommended.
| async run (): Promise<void> { | ||
| const { flags } = await this.parse(ImportPlanCommand) | ||
| const { | ||
| config: configFilename, | ||
| } = flags | ||
|
|
||
| const { configDirectory, configFilenames } = splitConfigFilePath(configFilename) | ||
| const { | ||
| config: checklyConfig, | ||
| } = await loadChecklyConfig(configDirectory, configFilenames) | ||
|
|
||
| const { | ||
| logicalId, | ||
| } = checklyConfig | ||
|
|
||
| const { data: existingPlans } = await api.projects.findImportPlans(logicalId, { | ||
| onlyUncommitted: true, | ||
| }) | ||
|
|
||
| if (existingPlans.length !== 0) { | ||
| await this.#handleExistingPlans(existingPlans) | ||
| } | ||
|
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
💡 Verification agent
❓ Verification inconclusive
Add unit tests to handle existing import plans scenario.
Consider verifying the user flow when existing plans are detected and the user chooses different prompt options.
Run the following script to locate relevant tests:
🏁 Script executed:
#!/bin/bash
rg -A 15 "ImportPlanCommand" testsLength of output: 80
Action Required: Add Unit Tests for Handling Existing Import Plans
The changes in packages/cli/src/commands/import/plan.ts (lines 29–51) currently have no accompanying tests. We need to add unit tests to validate the code paths when existing import plans are detected. In particular, please verify that:
- The flow through
#handleExistingPlansis correctly triggered when there are non-zeroexistingPlans. - Different user prompt responses (e.g., accepting, canceling, or modifying actions) yield the expected outcomes.
- Edge cases and potential error conditions are properly handled.
The earlier search using rg -A 15 "ImportPlanCommand" tests did not find any test files (indicating a missing tests directory). Please address this by creating relevant tests to ensure robustness.
8e0a955 to
470b019
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 5
🧹 Nitpick comments (37)
packages/cli/src/constructs/telegram-alert-channel-codegen.ts (2)
12-17: Consider making the API key extraction more robustThe
apiKeyFromUrlfunction uses a specific regex pattern that assumes a fixed URL format. This might be brittle if the Telegram API URL structure changes in the future.Consider adding:
- More comprehensive regex pattern matching
- Error handling for malformed URLs
- Documentation about the expected URL format
function apiKeyFromUrl (url: string): string | undefined { - const match = /https:\/\/api.telegram.org\/bot([^/]+)\/sendMessage/.exec(url) + // Match both standard and custom domain Telegram bot API URLs + const match = /https:\/\/(?:api\.telegram\.org|[^/]+)\/bot([^/]+)\/sendMessage/.exec(url) if (match) { return match[1] } + // Log warning or return specific error value for debugging }
19-24: Add error handling for chatId extractionThe
chatIdFromTemplatefunction extracts the chat ID without validating if it's a valid Telegram chat ID format.function chatIdFromTemplate (template: string): string | undefined { const match = /chatId=(-?[0-9]+)/.exec(template) if (match) { + // Ensure we have a valid chat ID format (group IDs are negative numbers, user IDs are positive) + const chatId = match[1] + if (!/^-?[0-9]+$/.test(chatId)) { + return undefined + } return match[1] } }packages/cli/src/sourcegen/decl.ts (1)
38-52: Consider centralizing whitespace handlingThe
rendermethod inVariableDeclarationhas several calls to manage whitespace that could be abstracted to reduce duplication and improve consistency across the codebase.Consider refactoring the whitespace handling into helper methods:
render (output: Output): void { if (this.options?.mutable) { output.append('let') } else { output.append('const') } output.significantWhitespace() this.identifier.render(output) - output.cosmeticWhitespace() - output.append('=') - output.cosmeticWhitespace() + output.appendWithSpacing('=') // A new helper method that adds spaces around a token this.value.render(output) output.endLine() }packages/cli/src/constructs/private-location-group-assignment-codegen.ts (1)
13-16: Consider adding documentation for the empty implementationThe
gencodemethod has an eslint-disable comment to suppress unused variable warnings, but it would be helpful to add more context about why this resource doesn't generate code.// eslint-disable-next-line @typescript-eslint/no-unused-vars gencode (logicalId: string, resource: PrivateLocationGroupAssignmentResource, context: Context): void { - // Nothing to generate for this resource. + // This resource only establishes a relationship in the context + // but doesn't generate standalone code. The relationship will be used + // when generating code for associated private locations and groups. }packages/cli/src/constructs/internal/assertion-codegen.ts (1)
45-146: Consolidate duplicate code between assertion functionsThe
valueForGeneralAssertionandvalueForNumericAssertionfunctions contain significant duplication in their structure and many comparison operations. Consider refactoring to reduce duplication.You could create a common helper function to handle the shared logic:
function createAssertionValue( klass: string, method: string, comparison: string, target: string | number, property?: string, isNumeric = false ): Value { return expr(ident(klass), builder => { builder.member(ident(method)) builder.call(builder => { if (property) { builder.string(property) } }) // Handle the comparison methods const methodMap: Record<string, string> = { 'EQUALS': 'equals', 'NOT_EQUALS': 'notEquals', // Add all other mappings } const methodName = methodMap[comparison] if (!methodName) { throw new Error(`Unsupported comparison ${comparison}`) } builder.member(ident(methodName)) builder.call(builder => { if (['IS_EMPTY', 'NOT_EMPTY', 'IS_NULL', 'NOT_NULL'].includes(comparison)) { builder.empty() } else if (isNumeric) { builder.number(Number(target)) } else { builder.string(target.toString()) } }) }) }Then refactor both functions to use this helper.
packages/cli/src/commands/import/apply.ts (2)
37-39: Handle scenarios with zero unapplied plans.When
unappliedPlansis empty, callingthis.#selectPlan(unappliedPlans)may lead to a confusing prompt or an index-out-of-bounds error. Consider short-circuiting ifunappliedPlans.length === 0, displaying a message, and returning early.
84-87: Permit an alternate flow after exit selection.After the user selects "Exit without applying," the command terminates abruptly. Consider providing an option for the user to return to the main menu or reselect, if consistent with the CLI design.
packages/cli/src/constructs/api-check-codegen.ts (1)
8-19: Validate optional script fields with caution.
localSetupScript,setupScriptPath,localTearDownScript, andtearDownScriptPathare optional but may overlap. Consider clarifying in documentation or code whether both scripts and script paths can coexist and how each is prioritized.packages/cli/src/constructs/slack-alert-channel-codegen.ts (2)
5-11: Ensure user-provided Slack URL is valid.
config.urlis mandatory, but there's no validation to ensure it is a valid Slack webhook URL. If relevant to your product's usage, consider validating or error handling for malformed URLs.
20-43: Consider user feedback on Slack channel configuration.While the code properly sets the
channelfield, some Slack webhooks may ignore non-default channels if the incoming webhook is restricted. It might be beneficial to add a note or fallback if the Slack response indicates that the specified channel is invalid or restricted.packages/cli/src/constructs/tcp-check-codegen.ts (1)
7-12: Clarify optional response time properties.
degradedResponseTimeandmaxResponseTimeare optional. Be sure to document how the default behavior works when these fields are unspecified, e.g., no performance-based alerts.packages/cli/src/constructs/sms-alert-channel-codegen.ts (1)
20-43: Consider adding a fallback or error handling for invalid phone numbers.
Right now, the code writesconfig.numberasphoneNumberwithout verifying whetherconfig.numbermeets any format requirements. While it may be sufficient as-is, you could include optional formatting or at least a note in the code to handle potential invalid inputs.If you’d like, here’s a potential snippet to indicate a naive check (though you may replace it with a more robust validator later):
builder.string('phoneNumber', config.number) + // Example naive check (not necessarily recommended for production) + // if (!/^\+?\d+$/.test(config.number)) { + // throw new Error('Invalid phone number format') + // }packages/cli/src/sourcegen/declbuilder.ts (1)
20-23: Overwriting behavior may lead to confusion.
Each time.variable(...)is called, the existing declaration in#declis replaced. Ensure this is always the desired behavior, as one might accidentally chain multiple.variable(...)calls expecting them to accumulate rather than overwrite.packages/cli/src/constructs/phone-call-alert-channel-codegen.ts (1)
16-19: Unused parameter “logicalId”.The
logicalIdparameter is never used in thepreparemethod. If it's not necessary for registration in future enhancements, consider removing it for clarity.- prepare (logicalId: string, resource: PhoneCallAlertChannelResource, context: Context): void { + prepare (_logicalId: string, resource: PhoneCallAlertChannelResource, context: Context): void { context.registerAlertChannel(resource.id, 'phoneCallAlert') }packages/cli/src/constructs/check-codegen.ts (1)
35-144: Consider breaking up the large function into smaller helpers.
buildCheckPropsmethod is quite expansive. Partitioning sections (e.g., location handling, alert channel lookups) into smaller helpers can improve maintainability.function buildCheckProps ( program: Program, builder: ObjectValueBuilder, resource: CheckResource, context: Context, ): void { + // Example: create a "buildLocationProps" helper to handle lines 59-66 & 68-82 + // create a "buildAlertProps" helper to handle lines 115-129 ... }packages/cli/src/constructs/opsgenie-alert-channel-codegen.ts (3)
5-13: Potential risk in storing API keys.The
apiKeyfield is stored in plain text. If you plan to generate code that includes this key, consider storing secrets securely or providing usage instructions that clarify the risks of embedding sensitive data.
17-20: Unused parameter “logicalId”.Similar to other codegen classes, the
logicalIdparameter is not used here. Remove it or rename it for clarity if not needed for future expansions.- prepare (logicalId: string, resource: OpsgenieAlertChannelResource, context: Context): void { + prepare (_logicalId: string, resource: OpsgenieAlertChannelResource, context: Context): void { context.registerAlertChannel(resource.id, 'opsgenieAlert') }
22-44: Add codegen test coverage for Opsgenie channels.Introducing a test that verifies the generated
OpsgenieAlertChannelcode will help detect future regressions. You can mock or stub out any secret data likeapiKey.packages/cli/src/constructs/pagerduty-alert-channel-codegen.ts (2)
5-12: Consider adding JSDoc for clarity
The interface is straightforward, but adding a short doc comment (e.g., describing the config fields) could help future contributors understand its usage.
21-48: Ensure sensitive keys are handled securely
While generating code for theserviceKey, confirm that storing secrets in plain text is acceptable. Consider referencing environment variables or a secrets manager to avoid exposing sensitive credentials.packages/cli/src/sourcegen/exprbuilder.ts (4)
5-9: Add documentation
Theexprfunction is central to building and chaining expressions. A brief docstring could help clarify its usage and parameters.
18-22: Method name 'new' may be confusing
Using “new” as a method name can overshadow the language keyword. Consider renaming it to something likecreateNewfor clarity.Here’s a possible diff:
- new (build: (builder: ArgumentsValueBuilder) => void): this { + createNew (build: (builder: ArgumentsValueBuilder) => void): this { const builder = new ArgumentsValueBuilder() build(builder) return this.context(new NewExpressionValue(this.#context, builder.build())) }
30-32: Nested expressions
Themembermethod looks good, but consider adding tests for multi-level member calls to ensure chaining works as expected.
34-37: Potential naming conflict
context(value)might be confused with the existingcontextparameter in the top-levelexprfunction. A more specific name could improve readability.packages/cli/src/constructs/incidentio-alert-channel-codegen.ts (2)
13-25: Consider usingtoLowerCase()
Instead oftoLocaleLowerCase(), which may behave differently across locales, usingtoLowerCase()is often clearer for case-insensitive matching of “authorization” headers.Here’s a possible diff:
- if (header.key.toLocaleLowerCase() !== 'authorization') { + if (header.key.toLowerCase() !== 'authorization') { continue }
34-61: Handling theapiKey
Embedding the extractedapiKeydirectly in generated code can pose security risks if it’s sensitive. Consider referencing environment variables or a secrets manager to keep credentials out of source control.packages/cli/src/constructs/check-group-codegen.ts (2)
72-77: Error is ignored when private location lookup fails.
Catching and ignoring errors may be intentional, but it risks silent failures if contexts are not properly registered. Consider logging or rethrowing for better traceability, if that’s a concern.
110-115: Similar pattern with alert channels.
As with private locations, catching and ignoring context lookup errors is consistent but could mask issues. Logging such errors may improve diagnostics.packages/cli/src/constructs/construct-codegen.ts (1)
43-49:sortResourcesfunction is straightforward.
Sorting logic is easy to follow, but a small comment clarifying the reversed ranking would reduce confusion.packages/cli/src/rest/projects.ts (3)
39-49: Consider adding documentation for these interfaces.
Adding brief doc comments can help clarify the intended usage ofImportPlanandImportPlanChanges.
85-92: Optional parameter documentation.
Consider documentingonlyUnappliedandonlyUncommittedto help clarify their effect for future maintainers.
94-101: Potential shared logic withfindImportPlans.
listImportPlansis very similar tofindImportPlans; consider extracting common logic if you foresee further expansions in filtering or parameters.packages/cli/src/sourcegen/expr.ts (1)
42-57: Handle bracket notation for member expressions.
A TODO note implies there may be tricky cases with dynamic property names. Let me know if you need assistance implementing bracket notation vs dot notation.packages/cli/src/sourcegen/arraybuilder.ts (1)
18-74:ArrayValueBuilderimplementation is consistent and flexible.
- Methods for adding different value types (e.g.,
null(),undefined(),ident()) are clear.- The
empty()method is a helpful convenience for re-initializing the builder.- Consider adding doc comments for each method to maintain clarity on usage and side effects.
packages/cli/src/sourcegen/argsbuilder.ts (1)
19-76:ArgumentsValueBuilderis thorough and readable.
- The method suite (
string(),object(),expr(), etc.) covers a broad range of argument types.- The
empty()method allows for resetting the argument list seamlessly.- As with other builders, doc comments would be useful for describing each method’s intended usage.
packages/cli/src/constructs/internal/codegen/context.ts (2)
3-4: Provide a default error message or accept a custom one.Although this error class extends
Error, the constructor does not supply any default or custom message. Providing a descriptive message can aid in troubleshooting and enhance clarity for debugging.Here’s a possible revision:
-export class MissingContextVariableMappingError extends Error {} +export class MissingContextVariableMappingError extends Error { + constructor(message?: string) { + super(message || 'Missing context variable mapping') + this.name = 'MissingContextVariableMappingError' + } +}
6-16: Consider adding documentation for private fields.All your private maps look good in terms of scoping, but adding JSDoc comments specifying their purpose would improve maintainability and help readers understand at a glance how each mapping is used.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (65)
packages/cli/e2e/__tests__/help.spec.ts(2 hunks)packages/cli/package.json(1 hunks)packages/cli/src/commands/import/apply.ts(1 hunks)packages/cli/src/commands/import/cancel.ts(1 hunks)packages/cli/src/commands/import/commit.ts(1 hunks)packages/cli/src/commands/import/plan.ts(1 hunks)packages/cli/src/constructs/alert-channel-codegen.ts(1 hunks)packages/cli/src/constructs/alert-channel-subscription-codegen.ts(1 hunks)packages/cli/src/constructs/alert-escalation-policy-codegen.ts(1 hunks)packages/cli/src/constructs/api-check-codegen.ts(1 hunks)packages/cli/src/constructs/browser-check-codegen.ts(1 hunks)packages/cli/src/constructs/check-codegen.ts(1 hunks)packages/cli/src/constructs/check-group-codegen.ts(1 hunks)packages/cli/src/constructs/check-group.ts(1 hunks)packages/cli/src/constructs/construct-codegen.ts(1 hunks)packages/cli/src/constructs/dashboard-codegen.ts(1 hunks)packages/cli/src/constructs/email-alert-channel-codegen.ts(1 hunks)packages/cli/src/constructs/frequency-codegen.ts(1 hunks)packages/cli/src/constructs/heartbeat-check-codegen.ts(1 hunks)packages/cli/src/constructs/incidentio-alert-channel-codegen.ts(1 hunks)packages/cli/src/constructs/internal/assertion-codegen.ts(1 hunks)packages/cli/src/constructs/internal/codegen/codegen.ts(1 hunks)packages/cli/src/constructs/internal/codegen/context.ts(1 hunks)packages/cli/src/constructs/internal/codegen/index.ts(1 hunks)packages/cli/src/constructs/key-value-pair-codegen.ts(1 hunks)packages/cli/src/constructs/maintenance-window-codegen.ts(1 hunks)packages/cli/src/constructs/msteams-alert-channel-codegen.ts(1 hunks)packages/cli/src/constructs/multi-step-check-codegen.ts(1 hunks)packages/cli/src/constructs/opsgenie-alert-channel-codegen.ts(1 hunks)packages/cli/src/constructs/pagerduty-alert-channel-codegen.ts(1 hunks)packages/cli/src/constructs/phone-call-alert-channel-codegen.ts(1 hunks)packages/cli/src/constructs/playwright-config-codegen.ts(1 hunks)packages/cli/src/constructs/playwright-config.ts(0 hunks)packages/cli/src/constructs/private-location-check-assignment-codegen.ts(1 hunks)packages/cli/src/constructs/private-location-codegen.ts(1 hunks)packages/cli/src/constructs/private-location-group-assignment-codegen.ts(1 hunks)packages/cli/src/constructs/ref-codegen.ts(1 hunks)packages/cli/src/constructs/retry-strategy-codegen.ts(1 hunks)packages/cli/src/constructs/slack-alert-channel-codegen.ts(1 hunks)packages/cli/src/constructs/sms-alert-channel-codegen.ts(1 hunks)packages/cli/src/constructs/tcp-check-codegen.ts(1 hunks)packages/cli/src/constructs/telegram-alert-channel-codegen.ts(1 hunks)packages/cli/src/constructs/webhook-alert-channel-codegen.ts(1 hunks)packages/cli/src/rest/projects.ts(3 hunks)packages/cli/src/sourcegen/args.ts(1 hunks)packages/cli/src/sourcegen/argsbuilder.ts(1 hunks)packages/cli/src/sourcegen/array.ts(1 hunks)packages/cli/src/sourcegen/arraybuilder.ts(1 hunks)packages/cli/src/sourcegen/boolean.ts(1 hunks)packages/cli/src/sourcegen/decl.ts(1 hunks)packages/cli/src/sourcegen/declbuilder.ts(1 hunks)packages/cli/src/sourcegen/expr.ts(1 hunks)packages/cli/src/sourcegen/exprbuilder.ts(1 hunks)packages/cli/src/sourcegen/identifier.ts(1 hunks)packages/cli/src/sourcegen/index.ts(1 hunks)packages/cli/src/sourcegen/null.ts(1 hunks)packages/cli/src/sourcegen/number.ts(1 hunks)packages/cli/src/sourcegen/object.ts(1 hunks)packages/cli/src/sourcegen/objectbuilder.ts(1 hunks)packages/cli/src/sourcegen/output.ts(1 hunks)packages/cli/src/sourcegen/program.ts(1 hunks)packages/cli/src/sourcegen/string.ts(1 hunks)packages/cli/src/sourcegen/undefined.ts(1 hunks)packages/cli/src/sourcegen/unknown.ts(1 hunks)packages/cli/src/sourcegen/value.ts(1 hunks)
💤 Files with no reviewable changes (1)
- packages/cli/src/constructs/playwright-config.ts
🚧 Files skipped from review as they are similar to previous changes (37)
- packages/cli/src/sourcegen/number.ts
- packages/cli/src/sourcegen/null.ts
- packages/cli/src/sourcegen/undefined.ts
- packages/cli/e2e/tests/help.spec.ts
- packages/cli/src/constructs/ref-codegen.ts
- packages/cli/src/sourcegen/args.ts
- packages/cli/src/sourcegen/boolean.ts
- packages/cli/src/sourcegen/identifier.ts
- packages/cli/src/constructs/internal/codegen/index.ts
- packages/cli/src/sourcegen/value.ts
- packages/cli/package.json
- packages/cli/src/constructs/check-group.ts
- packages/cli/src/constructs/playwright-config-codegen.ts
- packages/cli/src/commands/import/cancel.ts
- packages/cli/src/sourcegen/object.ts
- packages/cli/src/sourcegen/string.ts
- packages/cli/src/constructs/key-value-pair-codegen.ts
- packages/cli/src/sourcegen/unknown.ts
- packages/cli/src/commands/import/commit.ts
- packages/cli/src/constructs/dashboard-codegen.ts
- packages/cli/src/constructs/internal/codegen/codegen.ts
- packages/cli/src/constructs/multi-step-check-codegen.ts
- packages/cli/src/constructs/alert-escalation-policy-codegen.ts
- packages/cli/src/constructs/heartbeat-check-codegen.ts
- packages/cli/src/commands/import/plan.ts
- packages/cli/src/constructs/frequency-codegen.ts
- packages/cli/src/constructs/browser-check-codegen.ts
- packages/cli/src/constructs/maintenance-window-codegen.ts
- packages/cli/src/sourcegen/output.ts
- packages/cli/src/constructs/retry-strategy-codegen.ts
- packages/cli/src/constructs/private-location-check-assignment-codegen.ts
- packages/cli/src/sourcegen/program.ts
- packages/cli/src/constructs/email-alert-channel-codegen.ts
- packages/cli/src/sourcegen/index.ts
- packages/cli/src/sourcegen/array.ts
- packages/cli/src/constructs/alert-channel-subscription-codegen.ts
- packages/cli/src/constructs/private-location-codegen.ts
🧰 Additional context used
🧬 Code Definitions (21)
packages/cli/src/constructs/api-check-codegen.ts (5)
packages/cli/src/constructs/check-codegen.ts (2)
CheckResource(15-33)buildCheckProps(35-144)packages/cli/src/constructs/internal/assertion-codegen.ts (2)
valueForNumericAssertion(4-43)valueForGeneralAssertion(45-146)packages/cli/src/constructs/internal/codegen/index.ts (2)
Codegen(1-1)Context(2-2)packages/cli/src/constructs/internal/codegen/context.ts (1)
Context(5-121)packages/cli/src/constructs/key-value-pair-codegen.ts (1)
valueForKeyValuePair(4-17)
packages/cli/src/constructs/opsgenie-alert-channel-codegen.ts (3)
packages/cli/src/constructs/alert-channel-codegen.ts (2)
AlertChannelResource(21-29)buildAlertChannelProps(31-51)packages/cli/src/constructs/internal/codegen/index.ts (2)
Codegen(1-1)Context(2-2)packages/cli/src/constructs/internal/codegen/context.ts (1)
Context(5-121)
packages/cli/src/constructs/telegram-alert-channel-codegen.ts (4)
packages/cli/src/constructs/webhook-alert-channel-codegen.ts (2)
WebhookAlertChannelResource(28-31)WebhookAlertChannelResourceConfig(17-26)packages/cli/src/constructs/internal/codegen/index.ts (2)
Codegen(1-1)Context(2-2)packages/cli/src/constructs/internal/codegen/context.ts (1)
Context(5-121)packages/cli/src/constructs/alert-channel-codegen.ts (1)
buildAlertChannelProps(31-51)
packages/cli/src/constructs/msteams-alert-channel-codegen.ts (4)
packages/cli/src/constructs/webhook-alert-channel-codegen.ts (2)
WebhookAlertChannelResource(28-31)WebhookAlertChannelResourceConfig(17-26)packages/cli/src/constructs/internal/codegen/index.ts (2)
Codegen(1-1)Context(2-2)packages/cli/src/constructs/internal/codegen/context.ts (1)
Context(5-121)packages/cli/src/constructs/alert-channel-codegen.ts (1)
buildAlertChannelProps(31-51)
packages/cli/src/sourcegen/decl.ts (3)
packages/cli/src/sourcegen/output.ts (1)
Output(40-85)packages/cli/src/sourcegen/index.ts (6)
Output(28-28)IdentifierValue(23-23)VariableDeclaration(7-7)Value(33-33)ExportDeclaration(8-8)decl(11-11)packages/cli/src/sourcegen/declbuilder.ts (1)
decl(5-9)
packages/cli/src/constructs/check-group-codegen.ts (7)
packages/cli/src/constructs/frequency-codegen.ts (2)
FrequencyResource(4-4)valueForFrequency(6-54)packages/cli/src/constructs/alert-escalation-policy-codegen.ts (2)
AlertEscalationResource(4-4)valueForAlertEscalation(6-65)packages/cli/src/constructs/retry-strategy-codegen.ts (2)
RetryStrategyResource(4-4)valueForRetryStrategy(6-77)packages/cli/src/constructs/internal/codegen/index.ts (2)
Context(2-2)Codegen(1-1)packages/cli/src/constructs/internal/codegen/context.ts (1)
Context(5-121)packages/cli/src/constructs/key-value-pair-codegen.ts (1)
valueForKeyValuePair(4-17)packages/cli/src/constructs/api-check-codegen.ts (1)
valueForAssertion(21-38)
packages/cli/src/constructs/slack-alert-channel-codegen.ts (2)
packages/cli/src/constructs/alert-channel-codegen.ts (2)
AlertChannelResource(21-29)buildAlertChannelProps(31-51)packages/cli/src/constructs/internal/codegen/context.ts (1)
Context(5-121)
packages/cli/src/constructs/construct-codegen.ts (12)
packages/cli/src/constructs/internal/codegen/index.ts (2)
Codegen(1-1)Context(2-2)packages/cli/src/constructs/alert-channel-codegen.ts (1)
AlertChannelCodegen(53-101)packages/cli/src/constructs/alert-channel-subscription-codegen.ts (1)
AlertChannelSubscriptionCodegen(9-24)packages/cli/src/constructs/check-codegen.ts (1)
CheckCodegen(146-182)packages/cli/src/constructs/check-group-codegen.ts (1)
CheckGroupCodegen(231-252)packages/cli/src/constructs/dashboard-codegen.ts (1)
DashboardCodegen(31-140)packages/cli/src/constructs/maintenance-window-codegen.ts (1)
MaintenanceWindowCodegen(16-64)packages/cli/src/constructs/private-location-codegen.ts (1)
PrivateLocationCodegen(14-44)packages/cli/src/constructs/private-location-check-assignment-codegen.ts (1)
PrivateLocationCheckAssignmentCodegen(8-17)packages/cli/src/constructs/private-location-group-assignment-codegen.ts (1)
PrivateLocationGroupAssignmentCodegen(8-17)packages/cli/src/sourcegen/program.ts (1)
Program(7-53)packages/cli/src/constructs/internal/codegen/context.ts (1)
Context(5-121)
packages/cli/src/constructs/tcp-check-codegen.ts (5)
packages/cli/src/constructs/check-codegen.ts (2)
CheckResource(15-33)buildCheckProps(35-144)packages/cli/src/sourcegen/program.ts (1)
Program(7-53)packages/cli/src/constructs/internal/assertion-codegen.ts (2)
valueForGeneralAssertion(45-146)valueForNumericAssertion(4-43)packages/cli/src/constructs/internal/codegen/index.ts (2)
Codegen(1-1)Context(2-2)packages/cli/src/constructs/internal/codegen/context.ts (1)
Context(5-121)
packages/cli/src/constructs/pagerduty-alert-channel-codegen.ts (3)
packages/cli/src/constructs/alert-channel-codegen.ts (2)
AlertChannelResource(21-29)buildAlertChannelProps(31-51)packages/cli/src/constructs/internal/codegen/index.ts (2)
Codegen(1-1)Context(2-2)packages/cli/src/constructs/internal/codegen/context.ts (1)
Context(5-121)
packages/cli/src/constructs/private-location-group-assignment-codegen.ts (2)
packages/cli/src/constructs/internal/codegen/index.ts (2)
Codegen(1-1)Context(2-2)packages/cli/src/constructs/internal/codegen/context.ts (1)
Context(5-121)
packages/cli/src/constructs/phone-call-alert-channel-codegen.ts (3)
packages/cli/src/constructs/alert-channel-codegen.ts (2)
AlertChannelResource(21-29)buildAlertChannelProps(31-51)packages/cli/src/constructs/internal/codegen/index.ts (2)
Codegen(1-1)Context(2-2)packages/cli/src/constructs/internal/codegen/context.ts (1)
Context(5-121)
packages/cli/src/constructs/alert-channel-codegen.ts (9)
packages/cli/src/constructs/internal/codegen/index.ts (2)
Codegen(1-1)Context(2-2)packages/cli/src/constructs/phone-call-alert-channel-codegen.ts (1)
PhoneCallAlertChannelCodegen(15-44)packages/cli/src/constructs/email-alert-channel-codegen.ts (1)
EmailAlertChannelCodegen(14-37)packages/cli/src/constructs/opsgenie-alert-channel-codegen.ts (1)
OpsgenieAlertChannelCodegen(17-45)packages/cli/src/constructs/pagerduty-alert-channel-codegen.ts (1)
PagerdutyAlertChannelCodegen(16-49)packages/cli/src/constructs/slack-alert-channel-codegen.ts (1)
SlackAlertChannelCodegen(15-44)packages/cli/src/constructs/sms-alert-channel-codegen.ts (1)
SmsAlertChannelCodegen(15-44)packages/cli/src/constructs/webhook-alert-channel-codegen.ts (1)
WebhookAlertChannelCodegen(78-134)packages/cli/src/sourcegen/program.ts (1)
Program(7-53)
packages/cli/src/sourcegen/expr.ts (2)
packages/cli/src/sourcegen/args.ts (1)
ArgumentsValue(4-27)packages/cli/src/sourcegen/output.ts (1)
Output(40-85)
packages/cli/src/constructs/check-codegen.ts (5)
packages/cli/src/constructs/frequency-codegen.ts (2)
FrequencyResource(4-4)valueForFrequency(6-54)packages/cli/src/constructs/alert-escalation-policy-codegen.ts (2)
AlertEscalationResource(4-4)valueForAlertEscalation(6-65)packages/cli/src/constructs/retry-strategy-codegen.ts (2)
RetryStrategyResource(4-4)valueForRetryStrategy(6-77)packages/cli/src/constructs/internal/codegen/index.ts (2)
Context(2-2)Codegen(1-1)packages/cli/src/constructs/key-value-pair-codegen.ts (1)
valueForKeyValuePair(4-17)
packages/cli/src/sourcegen/argsbuilder.ts (3)
packages/cli/src/sourcegen/index.ts (8)
args(2-2)ArgumentsValueBuilder(2-2)ArgumentsValue(1-1)Value(33-33)array(4-4)object(27-27)ExpressionValueBuilder(22-22)expr(22-22)packages/cli/src/sourcegen/exprbuilder.ts (4)
build(39-41)context(34-37)ExpressionValueBuilder(11-42)expr(5-9)packages/cli/src/sourcegen/args.ts (1)
ArgumentsValue(4-27)
packages/cli/src/sourcegen/objectbuilder.ts (9)
packages/cli/src/sourcegen/arraybuilder.ts (7)
object(54-56)build(71-73)value(62-65)ArrayValueBuilder(18-74)array(12-16)array(50-52)expr(58-60)packages/cli/src/sourcegen/exprbuilder.ts (4)
build(39-41)context(34-37)ExpressionValueBuilder(11-42)expr(5-9)packages/cli/src/sourcegen/object.ts (2)
ObjectProperty(4-12)ObjectValue(14-39)packages/cli/src/sourcegen/string.ts (1)
StringValue(6-17)packages/cli/src/sourcegen/boolean.ts (1)
BooleanValue(4-15)packages/cli/src/sourcegen/number.ts (1)
NumberValue(4-15)packages/cli/src/sourcegen/null.ts (1)
NullValue(4-8)packages/cli/src/sourcegen/undefined.ts (1)
UndefinedValue(4-8)packages/cli/src/sourcegen/identifier.ts (1)
IdentifierValue(4-15)
packages/cli/src/sourcegen/exprbuilder.ts (3)
packages/cli/src/sourcegen/index.ts (8)
expr(22-22)Value(33-33)ExpressionValueBuilder(22-22)ExpressionValue(15-15)ArgumentsValueBuilder(2-2)NewExpressionValue(16-16)CallExpressionValue(17-17)MemberExpressionValue(18-18)packages/cli/src/sourcegen/argsbuilder.ts (4)
expr(60-62)build(73-75)value(64-67)ArgumentsValueBuilder(20-76)packages/cli/src/sourcegen/expr.ts (3)
NewExpressionValue(8-24)CallExpressionValue(26-40)MemberExpressionValue(42-57)
packages/cli/src/constructs/sms-alert-channel-codegen.ts (3)
packages/cli/src/constructs/alert-channel-codegen.ts (2)
AlertChannelResource(21-29)buildAlertChannelProps(31-51)packages/cli/src/constructs/internal/codegen/index.ts (2)
Codegen(1-1)Context(2-2)packages/cli/src/constructs/internal/codegen/context.ts (1)
Context(5-121)
packages/cli/src/constructs/internal/codegen/context.ts (1)
packages/cli/src/constructs/internal/codegen/index.ts (2)
MissingContextVariableMappingError(2-2)Context(2-2)
packages/cli/src/constructs/webhook-alert-channel-codegen.ts (8)
packages/cli/src/constructs/alert-channel-codegen.ts (2)
AlertChannelResource(21-29)buildAlertChannelProps(31-51)packages/cli/src/constructs/key-value-pair-codegen.ts (1)
valueForKeyValuePair(4-17)packages/cli/src/constructs/internal/codegen/index.ts (2)
Codegen(1-1)Context(2-2)packages/cli/src/constructs/incidentio-alert-channel-codegen.ts (1)
IncidentioAlertChannelCodegen(29-62)packages/cli/src/constructs/msteams-alert-channel-codegen.ts (1)
MSTeamsAlertChannelCodegen(14-40)packages/cli/src/constructs/telegram-alert-channel-codegen.ts (1)
TelegramAlertChannelCodegen(28-67)packages/cli/src/sourcegen/program.ts (1)
Program(7-53)packages/cli/src/constructs/internal/codegen/context.ts (1)
Context(5-121)
🪛 Biome (1.9.4)
packages/cli/src/constructs/check-codegen.ts
[error] 169-169: The function should not return a value because its return type is void.
The function is here:
'void' signals the absence of value. The returned value is likely to be ignored by the caller.
(lint/correctness/noVoidTypeReturn)
[error] 171-171: The function should not return a value because its return type is void.
The function is here:
'void' signals the absence of value. The returned value is likely to be ignored by the caller.
(lint/correctness/noVoidTypeReturn)
[error] 173-173: The function should not return a value because its return type is void.
The function is here:
'void' signals the absence of value. The returned value is likely to be ignored by the caller.
(lint/correctness/noVoidTypeReturn)
[error] 175-175: The function should not return a value because its return type is void.
The function is here:
'void' signals the absence of value. The returned value is likely to be ignored by the caller.
(lint/correctness/noVoidTypeReturn)
[error] 177-177: The function should not return a value because its return type is void.
The function is here:
'void' signals the absence of value. The returned value is likely to be ignored by the caller.
(lint/correctness/noVoidTypeReturn)
packages/cli/src/constructs/webhook-alert-channel-codegen.ts
[error] 102-102: The function should not return a value because its return type is void.
The function is here:
'void' signals the absence of value. The returned value is likely to be ignored by the caller.
(lint/correctness/noVoidTypeReturn)
[error] 114-114: The function should not return a value because its return type is void.
The function is here:
'void' signals the absence of value. The returned value is likely to be ignored by the caller.
(lint/correctness/noVoidTypeReturn)
⏰ Context from checks skipped due to timeout of 90000ms (2)
- GitHub Check: test - windows-latest
- GitHub Check: test - ubuntu-latest
🔇 Additional comments (76)
packages/cli/src/constructs/private-location-group-assignment-codegen.ts (1)
9-11: LGTM: Appropriate use of context registrationThe
preparemethod correctly registers the private location group assignment with the context using the provided resource properties.packages/cli/src/commands/import/apply.ts (2)
22-31: Consider verifying the presence or validity of the config file before proceeding.If
flags.configis not provided or points to an invalid file,splitConfigFilePathandloadChecklyConfigmay throw an error. Consider either adding a default value or handling this case more gracefully with a user-friendly warning.Would you like me to generate a script to confirm whether
flags.configis being passed and properly validated in other parts of the codebase?
62-65: Fix hardcoded plan numbering.All plans are labeled with
"Plan #1 from ...". This creates ambiguity when multiple plans exist. Update the loop to reference the index or use data from the plan to label them uniquely.Apply a diff similar to the past review comment:
- title: `Plan #1 from ${new Date(plan.createdAt)}`, + title: `Plan #${index + 1} from ${new Date(plan.createdAt)}`,packages/cli/src/constructs/api-check-codegen.ts (2)
21-38: Good use of a switch to handle various assertion sources.The function cleanly maps each
assertion.sourceto an appropriate builder call, and it throws an error for unsupported sources. This is a robust, maintainable approach.
42-153: Check for concurrency or parallel codegen usage.While not strictly an issue here, ensure that this code generation logic will not produce race conditions when used in parallel with other codegen tasks. If codegen resources share state, such as referencing a single
Programinstance across threads, consider adding synchronization or clarifying concurrency assumptions.packages/cli/src/constructs/slack-alert-channel-codegen.ts (1)
15-19: Registering the alert channel at prepare time looks correct.This approach correctly associates the alert channel
physicalIdwith a contextual variable prefixslackAlert. No issues found in the logic.packages/cli/src/constructs/tcp-check-codegen.ts (2)
14-25: Robust error handling for unsupported TCP assertion sources.Throwing an error for an unsupported source ensures undefined behavior is caught early. This is a solid approach.
29-71: Handle edge cases in the request object.If
resource.request.portorresource.request.hostnameis omitted or invalid, the code might break. Ensure that these fields are required or handle them gracefully.packages/cli/src/constructs/sms-alert-channel-codegen.ts (2)
1-4: Imports look clean and follow the established source generation structure.
5-11: Confirm mandatory vs. optional fields for phone number.
It may be beneficial to ensure thatconfig.numberis never empty or null. Since a valid phone number is crucial for SMS-based alerts, consider adding a validation or at least a safeguard to avoid runtime errors.Would you like me to generate a script that searches for references to this interface to confirm that every usage provides a valid
numberfield?packages/cli/src/sourcegen/declbuilder.ts (1)
1-9: Straightforward declaration builder pattern.
This approach nicely encapsulates the creation of declarations, improving readability and maintainability of generated code.packages/cli/src/constructs/msteams-alert-channel-codegen.ts (3)
1-3: Imports look aligned with the existing codegen architecture.
6-10: Resource extension appears appropriate.
Using aWebhookAlertChannelResourcebase for MS Teams is suitable, given it’s a type of webhook with a specificwebhookType.
19-39: Validate the MS Teams webhook details.
Given thatwebhookTypeis'WEBHOOK_MSTEAMS', consider verifying the URL domain format or at least that the URL is not empty to avoid sending incomplete or invalid requests.Would you like me to generate a search script to identify how
urlis used in other places, ensuring consistent handling of webhook URLs for MS Teams?packages/cli/src/constructs/phone-call-alert-channel-codegen.ts (2)
5-13: Interface structure appears correct.The
PhoneCallAlertChannelResourceinterface is suitably extendingAlertChannelResourceand specifying a unique'CALL'type. This aligns well with the existing alert channel setup.
20-43: Recommend adding test coverage.To ensure correctness and prevent regressions, it’s best to add codegen tests for this new alert channel type. You can validate code blocks are correctly generated (logical ID usage, phone number, optional name, etc.).
Would you like me to generate a sample test file to verify the generated code structure for
PhoneCallAlertChannelCodegen?packages/cli/src/constructs/check-codegen.ts (1)
15-33: Interface provides clear coverage of check properties.All relevant fields (e.g.,
activated,muted, etc.) are included. This is comprehensive and easy to extend.packages/cli/src/constructs/pagerduty-alert-channel-codegen.ts (1)
16-19: Looks good
Thepreparemethod correctly registers the alert channel in the context with a clear, descriptive prefix.packages/cli/src/sourcegen/exprbuilder.ts (2)
24-28: LGTM
Thecallmethod’s structure is intuitive and aligns well with the builder pattern.
39-41: Completes the builder pattern
Returning the private#contextstate neatly finishes the expression building flow.packages/cli/src/constructs/incidentio-alert-channel-codegen.ts (2)
7-11: Interface usage
ExtendingWebhookAlertChannelResourcewith a specializedwebhookTypeis a clean approach that maintains generic properties while customizing the incident.io configuration.
29-32: Consistent pattern
Thepreparemethod follows the established approach to register alert channels using a recognizable prefix.packages/cli/src/constructs/alert-channel-codegen.ts (6)
1-10: Imports look consistent and modular.
All imported modules and references appear valid. No issues found with structure or syntax.
12-19: Enum-like union type is clear and exhaustive.
Defining all possible alert channel types in a single union is straightforward and helps prevent invalid inputs at compile time.
21-29: Interface is well-structured.
All required and optional properties are clearly defined. This clearly captures the attributes needed for each alert channel resource.
31-51: Utility function enables easy extension.
buildAlertChannelPropsproperly checks for undefined fields before building them. This is a good pattern to avoid missing or extraneous properties.
53-82: Comprehensive initialization of codegen instances.
Each specific codegen class is instantiated and mapped properly incodegensByType. This enforces full coverage for all supported alert channels.
84-101: Appropriate error handling for unsupported alert channel types.
Throwing an error when encountering an undefined type ensures that silent failures do not occur. This is a robust design decision.packages/cli/src/constructs/check-group-codegen.ts (9)
1-10: Imports refer to relevant modules.
No issues with referencing or structuring these imported classes and functions. They align with the rest of the codebase.
11-19: Config resources capture essential properties.
The browser and multi-step check config resources reflect the expected shape, including optional frequency. This is flexible and future-proof.
21-41:CheckGroupResourcethoroughly covers all properties for check groups.
All known attributes (loyalty, environment variables, concurrency, etc.) are well-defined. Optional fields are properly indicated.
43-48: Function signature is self-explanatory.
buildCheckGroupPropsuses (program, builder, resource, context) as parameters, cleanly separating logic from data.
88-95: Tag array logic is clear.
Looping through tags elegantly handles the possibility of zero or multiple tags.
126-128: Alert escalation policy is clearly integrated.
UsingvalueForAlertEscalationnicely decouples the escalation-specific logic from the main flow.
130-168: Browser and multi-step checks follow consistent patterns.
Frequency and testMatch arrays are properly handled. The code reads cleanly.
222-222: Defaulting retry strategy tovalueForRetryStrategyis robust.
Even if the resource doesn’t specify aretryStrategy, this logic ensures a stable default.
231-253:CheckGroupCodegenextends a solid base.
Usingcontext.registerCheckGroupensures consistent ID tracking. Importing the main construct is done only at gencode time.packages/cli/src/constructs/construct-codegen.ts (6)
1-12: Imports reference the correct codegeneration modules.
No syntactic or logical issues apparent.
14-24:ResourceTypeunion enumerates recognized resource categories.
Useful for controlling the resource handling logic, preventing partial or ambiguous resource types.
31-41: Resource ordering is reversed for higher numbers.
return bo - aosorts descending by default. Confirm that this reversed order is entirely intentional. If you meant an ascending sort, consider swapping.
51-85: Constructor sets up all known resource codegens.
Mapping these resources ensures coverage, just like the approach used inalert-channel-codegen.
88-95: Consistent error-handling approach for unsupported resource types.
By failing fast, you guarantee that the calling code must handle or correct an unknown resource type.
97-104: Delegated generation approach fosters clarity.
Calls to the underlying codegens keep this class minimal and maintainable, avoiding duplication.packages/cli/src/rest/projects.ts (4)
81-83: Looks good.
Creating an import plan with a simple POST request seems straightforward.
103-105: Straightforward cancellation endpoint.
No issues found; the code is concise and clear.
107-109: Straightforward apply endpoint.
Implementation looks correct.
111-113: Straightforward commit endpoint.
Implementation looks correct.packages/cli/src/sourcegen/expr.ts (7)
5-6: Base class approach looks good.
TheExpressionValueclass extendsValueand seems ready for new expression types.
8-24: Constructor and rendering for 'new' expressions.
Implementation is straightforward and consistent with typical AST generation patterns.
26-40: Call expression rendering is correct.
Logic is clean, with the callee followed by arguments.
59-59: Binary operator definition is concise.
Expanding this list in the future is straightforward if you need more operators.
61-80: Binary expression rendering is clear.
No concerns with the spacing and operator usage.
82-82: Unary operator definition is concise.
Additional unary operators can easily be added as needed.
84-98: Unary expression rendering is correct.
Looks good with straightforward usage of theopproperty.packages/cli/src/constructs/webhook-alert-channel-codegen.ts (8)
1-16: New type and interfaces look good.
The introduction ofWebhookTypeis clean, supporting extension with additional webhook integrations in the future.
17-26: Interfaces are well-structured.
WebhookAlertChannelResourceConfigcaptures necessary details for different webhook types.
28-31: Extends AlertChannelResource clearly.
No issues; theWebhookAlertChannelResourcedefinition is concise and easy to maintain.
33-74: Configuration builder is well-implemented.
Conditional checks for optional fields are cleanly handled, and the usage ofObjectValueBuilderis idiomatic.
76-76: Constant declaration is fine.
No concerns with naming or usage ofconstruct.
78-95: Class construction logic is clear.
The mapping ofcodegensByWebhookTypeensures easy extensibility for new webhook types.
97-107: Duplicate comment: remove return in a void function.
As noted previously, returningcodegen.prepare(...)from avoidfunction triggers a static analysis warning. Either remove thereturnor change the function signature.- return codegen.prepare(logicalId, resource, context) + codegen.prepare(logicalId, resource, context) + return🧰 Tools
🪛 Biome (1.9.4)
[error] 102-102: The function should not return a value because its return type is void.
The function is here:
'void' signals the absence of value. The returned value is likely to be ignored by the caller.
(lint/correctness/noVoidTypeReturn)
109-133: Duplicate comment: remove return in a void function.
As noted previously, returningcodegen.gencode(...)from avoidfunction triggers a static analysis warning. Either remove thereturnor change the function signature.- return codegen.gencode(logicalId, resource, context) + codegen.gencode(logicalId, resource, context) + return🧰 Tools
🪛 Biome (1.9.4)
[error] 114-114: The function should not return a value because its return type is void.
The function is here:
'void' signals the absence of value. The returned value is likely to be ignored by the caller.
(lint/correctness/noVoidTypeReturn)
packages/cli/src/sourcegen/objectbuilder.ts (3)
1-10: Good import organization and usage.All imported modules appear relevant and are used appropriately to construct different value types. No redundant or missing imports detected.
12-16: Fluent interface forobject(...)is clear and concise.The builder pattern here allows for clean and intuitive object creation. This method effectively initializes the builder, invokes the consumer's custom logic, and returns the final
ObjectValue.
18-65:✅ Verification successful
Builder pattern implementation is robust. Consider documenting usage.
- The
ObjectValueBuilderprovides a solid API for adding various property types, from primitives to nested objects.- Adding short doc comments or JSDoc annotations for each method could improve maintainability and clarify usage.
- The use of private class fields (
#properties) is modern ES syntax. Validate that your Node/TypeScript environment supports it to avoid unexpected runtime issues.
🌐 Web query:
Which Node.js versions natively support JavaScript private class fields (#private)?💡 Result:
Private class fields using the
#syntax are natively supported in Node.js starting from version 12 and later, enabled by default without requiring command-line flags or transpilers like Babel[1][4][7]. This support was introduced through updates to the V8 JavaScript engine (v7.4+), which powers Node.js[4].Key details:
- Node.js 12 (April 2019): First version with native support for private fields[1][7].
- Node.js 14+: Continues support as the feature became standardized (ES2022)[8].
- Runtime behavior: Private fields are enforced at the language level, making them inaccessible via
Object.keys()or other reflection methods[1][5].class Example { #privateField = 42; // Supported in Node.js ≥12 getValue() { return this.#privateField; } }Earlier Node.js versions (≤11) lack support, and attempts to use the syntax will throw syntax errors. Private fields remain experimental in JavaScript until ES2022 standardization, but Node.js implementations have been stable since v12[4][7].
Citations:
- 1: https://thecodebarbarian.com/nodejs-12-private-class-fields.html
- 2: https://community.grafana.com/t/bug-with-js-classes-that-have-private-fields/98707
- 3: https://jamie.build/javascripts-new-private-class-fields.html
- 4: https://v8.dev/features/class-fields
- 5: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Classes/Private_properties
- 6: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Classes
- 7: https://www.sitepoint.com/javascript-private-class-fields/
- 8: https://dev.to/smitterhane/private-class-fields-in-javascript-es2022-3b8
- 9: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Classes/Public_class_fields
Enhance Documentation & Verify Runtime Environment Compatibility
The implementation of the builder pattern is solid and uses modern ES syntax (e.g., private class fields are supported natively in Node.js v12 and later). To improve maintainability and clarify intended usage:
- Consider adding inline JSDoc or doc comments for each method (e.g.,
string,boolean,number, etc.) to clearly explain parameters and functionality.- Verify that your development/production environments are running on Node.js v12 or later to ensure full support for private class fields.
packages/cli/src/sourcegen/arraybuilder.ts (2)
1-10: Imports look coherent.They align well with the intended functionality (building arrays with various value types).
12-16:array(...)function is well-designed.It mirrors the same fluent pattern found in
object(...), ensuring consistency across builders.packages/cli/src/sourcegen/argsbuilder.ts (2)
1-12: Imports and references are consistent with the builder pattern.The references to
ArgumentsValue,ArrayValueBuilder,ObjectValueBuilder, and others establish a unified approach to constructing arguments.
13-17: Theargs(...)function cleanly encapsulates argument construction.It provides a straightforward interface for generating an
ArgumentsValueinstance, mirroring the style of your other builders.packages/cli/src/constructs/internal/codegen/context.ts (7)
17-30: Looks correct for registering and looking up check groups.The logic for generating a sequential variable name (e.g.,
group1,group2, ...) and retrieving it later is straightforward and consistent with the class’s intended design.
32-45: Alert channel registration and lookup logic appears sound.No significant concerns: the pattern is consistent with how check groups are handled. The variable prefix parameter is a nice touch for naming clarity.
47-60: Code for private location registration and lookup is well-structured.The approach of assigning a simple sequential name for each private location is clear and matches the pattern used above.
62-75: Registering and retrieving private locations for check groups is straightforward.No functional issues spotted. Error handling is consistently done by throwing
MissingContextVariableMappingErrorwhen needed.
77-90: Registering and retrieving private locations for checks is consistent.Good reuse of the approach in the previous method. No immediate issues with performance or correctness.
92-105: Alert channel check subscription logic looks clean.The pattern of appending to an array and retrieving it later is consistent with the existing approach.
107-120: Group alert channel subscription is implemented consistently.The logic closely mirrors earlier patterns, ensuring a uniform API for lookups and assignments. No further concerns.
| case 'LESS_THAN': | ||
| builder.member(ident('lessThan')) | ||
| builder.call(builder => { | ||
| builder.string(assertion.target) | ||
| }) | ||
| break | ||
| case 'GREATER_THAN': | ||
| builder.member(ident('greaterThan')) | ||
| builder.call(builder => { | ||
| builder.string(assertion.target) | ||
| }) | ||
| break |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Refactor suggestion
Handle numeric comparison types correctly in general assertions
The valueForGeneralAssertion function handles LESS_THAN and GREATER_THAN comparisons as string comparisons, which may produce unexpected results when comparing numeric values.
case 'LESS_THAN':
builder.member(ident('lessThan'))
builder.call(builder => {
- builder.string(assertion.target)
+ // Try to determine if target should be treated as a number
+ const numValue = Number(assertion.target)
+ if (!isNaN(numValue)) {
+ builder.number(numValue)
+ } else {
+ builder.string(assertion.target)
+ }
})
breakApply the same approach to the GREATER_THAN case.
Committable suggestion skipped: line range outside the PR's diff.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 2
🧹 Nitpick comments (6)
packages/cli/src/commands/import/apply.ts (2)
22-60: Improve error handling for non-fancy output.The catch block properly handles error visualization for fancy output, but lacks any messaging or feedback for non-fancy mode. Consider adding a log message before throwing the error.
} catch (err) { if (this.fancy) { ux.action.stop('❌') + } else { + this.log('❌ Failed to apply plan') } throw err }
64-65: Use a more user-friendly date format.The date is currently displayed using the default
Dateformatting, which can vary by locale. Consider using a more consistent and readable format.- title: `Plan #${index + 1} from ${new Date(plan.createdAt)}`, + title: `Plan #${index + 1} from ${new Date(plan.createdAt).toLocaleString()}`, value: plan.id,packages/cli/src/constructs/webhook-alert-channel-codegen.ts (4)
79-79: Fix typo in property name.The property name
indicentioCodegenappears to have a typo - it should beincidentioCodegen(missing 't').- indicentioCodegen: IncidentioAlertChannelCodegen + incidentioCodegen: IncidentioAlertChannelCodegen
82-82: Improve type safety by avoidingany.Using
Codegen<any>loses type safety. Consider using a union type of the specific codegen types.- codegensByWebhookType: Record<WebhookType, Codegen<any>> + codegensByWebhookType: Record<WebhookType, IncidentioAlertChannelCodegen | MSTeamsAlertChannelCodegen | TelegramAlertChannelCodegen>
43-43: Remove unnecessary toString() conversion.The
config.urlis defined as a string in the interface, so calling.toString()is redundant.- builder.string('url', config.url.toString()) + builder.string('url', config.url)
97-108: Consider creating a helper method for webhook type codegen lookup.Both
prepare()andgencode()methods have similar code patterns for looking up and delegating to the appropriate codegen. Consider extracting this logic to a helper method.+ private getCodegenForWebhookType(webhookType?: WebhookType): Codegen<any> | undefined { + if (!webhookType) { + return undefined + } + return this.codegensByWebhookType[webhookType] + } prepare (logicalId: string, resource: WebhookAlertChannelResource, context: Context): void { const { webhookType } = resource.config - if (webhookType) { - const codegen = this.codegensByWebhookType[webhookType] - if (codegen) { - codegen.prepare(logicalId, resource, context) - return - } + const codegen = this.getCodegenForWebhookType(webhookType) + if (codegen) { + codegen.prepare(logicalId, resource, context) + return } context.registerAlertChannel(resource.id, 'webhookAlert') }Similarly, update the
gencode()method to use this helper.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (3)
packages/cli/src/commands/import/apply.ts(1 hunks)packages/cli/src/commands/import/commit.ts(1 hunks)packages/cli/src/constructs/webhook-alert-channel-codegen.ts(1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
- packages/cli/src/commands/import/commit.ts
🧰 Additional context used
🧬 Code Definitions (1)
packages/cli/src/constructs/webhook-alert-channel-codegen.ts (7)
packages/cli/src/constructs/alert-channel-codegen.ts (2)
AlertChannelResource(21-29)buildAlertChannelProps(31-51)packages/cli/src/constructs/key-value-pair-codegen.ts (1)
valueForKeyValuePair(4-17)packages/cli/src/constructs/internal/codegen/index.ts (2)
Codegen(1-1)Context(2-2)packages/cli/src/constructs/incidentio-alert-channel-codegen.ts (1)
IncidentioAlertChannelCodegen(29-62)packages/cli/src/constructs/msteams-alert-channel-codegen.ts (1)
MSTeamsAlertChannelCodegen(14-40)packages/cli/src/constructs/telegram-alert-channel-codegen.ts (1)
TelegramAlertChannelCodegen(28-67)packages/cli/src/constructs/internal/codegen/context.ts (1)
Context(5-121)
⏰ Context from checks skipped due to timeout of 90000ms (1)
- GitHub Check: test - windows-latest
There was a problem hiding this 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)
packages/cli/src/constructs/check-codegen.ts (1)
68-82: Consider adding error logging for failed private location lookupsThe code silently ignores errors when looking up private locations. While this might be intentional to make private locations optional, consider at least logging a warning to help with debugging when something unexpected fails.
const privateLocationIds = (() => { try { return context.lookupCheckPrivateLocations(resource.id) } catch (err) { + console.warn(`Failed to lookup private locations for check ${resource.id}:`, err) } })()packages/cli/src/sourcegen/object.ts (2)
8-18: Consider property name and value validation.
The constructor doesn’t validate the property name or value. For added robustness, ensure that invalid or unexpected values do not slip in.
58-88: Watch for trailing commas in rendered output.
The generated code includes a comma after each property. If this output is parsed by tools that disallow trailing commas (e.g., strict JSON parsers), consider conditionally omitting the last comma.packages/cli/src/sourcegen/objectbuilder.ts (2)
12-16: Public helper function is well-structured.
object(...)uses a builder function internally, improving code readability and reusability.
72-74: Consider clarifying structure immutability post-build.
Returning a newObjectValueafter build is typical. Include a note in docs if the resulting object is intended to be immutable or if further modifications can be made.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (4)
packages/cli/src/constructs/check-codegen.ts(1 hunks)packages/cli/src/constructs/retry-strategy-codegen.ts(1 hunks)packages/cli/src/sourcegen/object.ts(1 hunks)packages/cli/src/sourcegen/objectbuilder.ts(1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
- packages/cli/src/constructs/retry-strategy-codegen.ts
🧰 Additional context used
🧬 Code Definitions (2)
packages/cli/src/constructs/check-codegen.ts (5)
packages/cli/src/constructs/frequency-codegen.ts (2)
FrequencyResource(4-4)valueForFrequency(6-54)packages/cli/src/constructs/alert-escalation-policy-codegen.ts (2)
AlertEscalationResource(4-4)valueForAlertEscalation(6-65)packages/cli/src/constructs/retry-strategy-codegen.ts (2)
RetryStrategyResource(4-4)valueForRetryStrategy(6-77)packages/cli/src/constructs/internal/codegen/index.ts (2)
Context(2-2)Codegen(1-1)packages/cli/src/constructs/key-value-pair-codegen.ts (1)
valueForKeyValuePair(4-17)
packages/cli/src/sourcegen/object.ts (3)
packages/cli/src/sourcegen/index.ts (3)
Value(33-33)ObjectValue(26-26)Output(28-28)packages/cli/src/sourcegen/objectbuilder.ts (1)
value(67-70)packages/cli/src/sourcegen/output.ts (1)
Output(40-85)
🪛 Biome (1.9.4)
packages/cli/src/constructs/check-codegen.ts
[error] 169-169: The function should not return a value because its return type is void.
The function is here:
'void' signals the absence of value. The returned value is likely to be ignored by the caller.
(lint/correctness/noVoidTypeReturn)
[error] 171-171: The function should not return a value because its return type is void.
The function is here:
'void' signals the absence of value. The returned value is likely to be ignored by the caller.
(lint/correctness/noVoidTypeReturn)
[error] 173-173: The function should not return a value because its return type is void.
The function is here:
'void' signals the absence of value. The returned value is likely to be ignored by the caller.
(lint/correctness/noVoidTypeReturn)
[error] 175-175: The function should not return a value because its return type is void.
The function is here:
'void' signals the absence of value. The returned value is likely to be ignored by the caller.
(lint/correctness/noVoidTypeReturn)
[error] 177-177: The function should not return a value because its return type is void.
The function is here:
'void' signals the absence of value. The returned value is likely to be ignored by the caller.
(lint/correctness/noVoidTypeReturn)
🔇 Additional comments (26)
packages/cli/src/constructs/check-codegen.ts (7)
15-33: Well-structured interface for check resourcesThe
CheckResourceinterface provides a clean and comprehensive structure for representing different types of check resources. Good use of optional properties to handle various configuration options that might be present in different check types.
35-40: Well-defined function signature with clear parametersThe
buildCheckPropsfunction has a clear purpose with well-typed parameters. The void return type is appropriate since it mutates the passed builder object.
106-113: Good error handling for missing check groupsI appreciate the explicit error handling when a check references a group that isn't being imported. This will provide clear guidance to users about the dependency issue rather than failing silently.
115-143: Robust implementation of alert channel lookup and configurationThe code correctly handles the lookup of alert channels with proper error handling, and conditionally adds configuration properties only when they're defined in the resource.
164-181: Remove "return" statements in a void functionThe function should not return values as its return type is declared as
void. This issue was also identified by static analysis.gencode (logicalId: string, resource: CheckResource, context: Context): void { const { checkType } = resource switch (checkType) { case 'BROWSER': - return this.browserCheckCodegen.gencode(logicalId, resource as BrowserCheckResource, context) + this.browserCheckCodegen.gencode(logicalId, resource as BrowserCheckResource, context) + break case 'API': - return this.apiCheckCodegen.gencode(logicalId, resource as ApiCheckResource, context) + this.apiCheckCodegen.gencode(logicalId, resource as ApiCheckResource, context) + break case 'TCP': - return this.tcpCheckCodegen.gencode(logicalId, resource as TcpCheckResource, context) + this.tcpCheckCodegen.gencode(logicalId, resource as TcpCheckResource, context) + break case 'MULTI_STEP': - return this.multiStepCheckCodegen.gencode(logicalId, resource as MultiStepCheckResource, context) + this.multiStepCheckCodegen.gencode(logicalId, resource as MultiStepCheckResource, context) + break case 'HEARTBEAT': - return this.heartbeatCheckCodegen.gencode(logicalId, resource as HeartbeatCheckResource, context) + this.heartbeatCheckCodegen.gencode(logicalId, resource as HeartbeatCheckResource, context) + break default: throw new Error(`Unable to generate code for unsupported check type '${checkType}'.`) } }🧰 Tools
🪛 Biome (1.9.4)
[error] 169-169: The function should not return a value because its return type is void.
The function is here:
'void' signals the absence of value. The returned value is likely to be ignored by the caller.
(lint/correctness/noVoidTypeReturn)
[error] 171-171: The function should not return a value because its return type is void.
The function is here:
'void' signals the absence of value. The returned value is likely to be ignored by the caller.
(lint/correctness/noVoidTypeReturn)
[error] 173-173: The function should not return a value because its return type is void.
The function is here:
'void' signals the absence of value. The returned value is likely to be ignored by the caller.
(lint/correctness/noVoidTypeReturn)
[error] 175-175: The function should not return a value because its return type is void.
The function is here:
'void' signals the absence of value. The returned value is likely to be ignored by the caller.
(lint/correctness/noVoidTypeReturn)
[error] 177-177: The function should not return a value because its return type is void.
The function is here:
'void' signals the absence of value. The returned value is likely to be ignored by the caller.
(lint/correctness/noVoidTypeReturn)
154-162: Clean initialization of code generators in constructorThe initialization of all the required code generators in the constructor is clean and follows the dependency injection pattern well. This approach makes the code more maintainable and testable.
41-144: Property builder is comprehensive and handles edge casesThe implementation covers all properties from the interface definition and handles conditional properties well. The code is robust in dealing with optional values and includes proper error handling for lookups.
packages/cli/src/sourcegen/object.ts (7)
1-3: Imports look good.
No issues found with these import statements.
4-6: Interface is straightforward.
Definingorder?: numberas an optional property is a clear way to store sorting order.
20-21: Sorter type definition is appropriate.
Declaring a dedicated type for your property sorter helps maintain clarity.
22-24: Options interface is concise.
Optionalsortproperty is well-defined for customizing sorting strategy.
26-36: Name-based comparator is correct.
Simple string comparison logic is fine for alphabetical sorting.
38-51: Order-based comparator is well-implemented.
Leverages the optionalorderproperty and defaults to 0 if missing. This is good.
53-56: Order-then-name sorting is coherent.
Clear fallback to name-based sorting when orders match.packages/cli/src/sourcegen/objectbuilder.ts (12)
1-10: Imports are consistent.
No issues found with module references or import paths.
18-25: Builder constructor is clear.
StoringObjectValueOptionsin a private field is straightforward for controlling how the object is built.
26-28: String property method is concise.
UsesStringValueto encapsulate string data.
30-32: Boolean property method is consistent.
Follows the same pattern, ensuring consistent usage of typed value classes.
34-36: Number property handling is good.
No issues found here; straightforward numeric value usage.
38-40: Null property creation is clear.
Sufficiently indicates a null value.
42-44: Undefined value usage is correct.
Allows for explicit undefined representation in the generated object.
46-48: Identifier reference is well-handled.
Encapsulating an identifier in its ownValuetype is a good practice.
50-52: Array building integration is neat.
Supports nested structures by delegating array creation toarraybuilder.
54-56: Object building integration is straightforward.
Consistently delegates nested object creation to theobject(...)helper.
58-65: Expr building is well-structured.
Uses a dedicatedexpr(...)builder for expressions, aligning with the rest of the pattern.
67-70: Value assignment method looks solid.
Pushing a newObjectPropertyfosters consistent property handling across the builder.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 1
🧹 Nitpick comments (6)
packages/cli/src/constructs/private-location-codegen.ts (1)
1-56: Consider adding documentation to public API elements.While the code is well-structured, adding JSDoc comments to the interface, function, and class would improve developer experience and make the code more maintainable.
+/** + * Interface representing a Private Location resource. + */ export interface PrivateLocationResource { id: string name: string slugName: string icon?: string proxyUrl?: string } const construct = 'PrivateLocation' +/** + * Creates a reference to an existing Private Location using its ID. + * @param program - The program to add imports to + * @param physicalId - The physical ID of the private location + * @returns A Value representing the expression to reference the private location + */ export function valueForPrivateLocationFromId (program: Program, physicalId: string): Value { program.import(construct, 'checkly/constructs') return expr(ident(construct), builder => { builder.member(ident('fromId')) builder.call(builder => { builder.string(physicalId) }) }) } +/** + * Code generator for Private Location resources. + * Handles the generation of TypeScript code for creating Private Location instances. + */ export class PrivateLocationCodegen extends Codegen<PrivateLocationResource> {packages/cli/src/constructs/check-codegen.ts (2)
121-126: Consider enhancing error handling in the lookupCheckAlertChannels call.The current implementation silently catches errors when looking up check alert channels. Consider adding logging or more explicit error handling to help with debugging, especially since this pattern is used for private locations too.
const alertChannelIds = (() => { try { return context.lookupCheckAlertChannels(resource.id) } catch (err) { + // Log or handle the error more explicitly + // console.debug(`No alert channels found for check ${resource.id}`) } })()
70-75: Consider enhancing error handling in the lookupCheckPrivateLocations call.Similar to the alert channels lookup, this code silently catches errors. Adding more explicit error handling or logging would improve debuggability.
const privateLocationIds = (() => { try { return context.lookupCheckPrivateLocations(resource.id) } catch (err) { + // Log or handle the error more explicitly + // console.debug(`No private locations found for check ${resource.id}`) } })()packages/cli/src/constructs/alert-channel-codegen.ts (2)
12-19: Consider using an enum forAlertChannelType.Using a TypeScript enum could help prevent typos and make refactoring or adding new alert channel types more maintainable.
66-95: Consider extracting a helper for retrieving alert channel codegen.Both the
prepareandgencodemethods duplicate the lookup logic inthis.codegensByType[...]. Factoring out a small helper function could simplify code and reduce repetition.packages/cli/src/constructs/check-group-codegen.ts (1)
74-79: Avoid silently ignoring context lookup errors.The code swallows possible
MissingContextVariableMappingErrorwithout logging. If these lookups fail unexpectedly, debugging might be difficult. Consider logging or handling the error more explicitly to surface issues earlier.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (4)
packages/cli/src/constructs/alert-channel-codegen.ts(1 hunks)packages/cli/src/constructs/check-codegen.ts(1 hunks)packages/cli/src/constructs/check-group-codegen.ts(1 hunks)packages/cli/src/constructs/private-location-codegen.ts(1 hunks)
🧰 Additional context used
🧬 Code Definitions (4)
packages/cli/src/constructs/check-codegen.ts (8)
packages/cli/src/constructs/frequency-codegen.ts (2)
FrequencyResource(4-4)valueForFrequency(6-54)packages/cli/src/constructs/retry-strategy-codegen.ts (2)
RetryStrategyResource(4-4)valueForRetryStrategy(6-77)packages/cli/src/constructs/internal/codegen/index.ts (2)
Context(2-2)Codegen(1-1)packages/cli/src/constructs/internal/codegen/context.ts (1)
Context(5-121)packages/cli/src/constructs/private-location-codegen.ts (1)
valueForPrivateLocationFromId(14-23)packages/cli/src/constructs/key-value-pair-codegen.ts (1)
valueForKeyValuePair(4-17)packages/cli/src/constructs/alert-channel-codegen.ts (1)
valueForAlertChannelFromId(55-64)packages/cli/src/constructs/api-check-codegen.ts (2)
ApiCheckCodegen(42-153)ApiCheckResource(8-19)
packages/cli/src/constructs/alert-channel-codegen.ts (10)
packages/cli/src/sourcegen/program.ts (1)
Program(7-53)packages/cli/src/constructs/internal/codegen/index.ts (2)
Codegen(1-1)Context(2-2)packages/cli/src/constructs/phone-call-alert-channel-codegen.ts (1)
PhoneCallAlertChannelCodegen(15-44)packages/cli/src/constructs/email-alert-channel-codegen.ts (1)
EmailAlertChannelCodegen(14-37)packages/cli/src/constructs/opsgenie-alert-channel-codegen.ts (1)
OpsgenieAlertChannelCodegen(17-45)packages/cli/src/constructs/pagerduty-alert-channel-codegen.ts (1)
PagerdutyAlertChannelCodegen(16-49)packages/cli/src/constructs/slack-alert-channel-codegen.ts (1)
SlackAlertChannelCodegen(15-44)packages/cli/src/constructs/sms-alert-channel-codegen.ts (1)
SmsAlertChannelCodegen(15-44)packages/cli/src/constructs/webhook-alert-channel-codegen.ts (1)
WebhookAlertChannelCodegen(78-136)packages/cli/src/constructs/internal/codegen/context.ts (1)
Context(5-121)
packages/cli/src/constructs/check-group-codegen.ts (9)
packages/cli/src/constructs/frequency-codegen.ts (2)
FrequencyResource(4-4)valueForFrequency(6-54)packages/cli/src/constructs/alert-escalation-policy-codegen.ts (2)
AlertEscalationResource(4-4)valueForAlertEscalation(6-65)packages/cli/src/constructs/retry-strategy-codegen.ts (2)
RetryStrategyResource(4-4)valueForRetryStrategy(6-77)packages/cli/src/constructs/internal/codegen/index.ts (2)
Context(2-2)Codegen(1-1)packages/cli/src/constructs/internal/codegen/context.ts (1)
Context(5-121)packages/cli/src/constructs/private-location-codegen.ts (1)
valueForPrivateLocationFromId(14-23)packages/cli/src/constructs/key-value-pair-codegen.ts (1)
valueForKeyValuePair(4-17)packages/cli/src/constructs/alert-channel-codegen.ts (1)
valueForAlertChannelFromId(55-64)packages/cli/src/constructs/api-check-codegen.ts (1)
valueForAssertion(21-38)
packages/cli/src/constructs/private-location-codegen.ts (3)
packages/cli/src/sourcegen/program.ts (1)
Program(7-53)packages/cli/src/constructs/internal/codegen/index.ts (2)
Codegen(1-1)Context(2-2)packages/cli/src/constructs/internal/codegen/context.ts (1)
Context(5-121)
🪛 Biome (1.9.4)
packages/cli/src/constructs/check-codegen.ts
[error] 179-179: The function should not return a value because its return type is void.
The function is here:
'void' signals the absence of value. The returned value is likely to be ignored by the caller.
(lint/correctness/noVoidTypeReturn)
[error] 181-181: The function should not return a value because its return type is void.
The function is here:
'void' signals the absence of value. The returned value is likely to be ignored by the caller.
(lint/correctness/noVoidTypeReturn)
[error] 183-183: The function should not return a value because its return type is void.
The function is here:
'void' signals the absence of value. The returned value is likely to be ignored by the caller.
(lint/correctness/noVoidTypeReturn)
[error] 185-185: The function should not return a value because its return type is void.
The function is here:
'void' signals the absence of value. The returned value is likely to be ignored by the caller.
(lint/correctness/noVoidTypeReturn)
[error] 187-187: The function should not return a value because its return type is void.
The function is here:
'void' signals the absence of value. The returned value is likely to be ignored by the caller.
(lint/correctness/noVoidTypeReturn)
🔇 Additional comments (11)
packages/cli/src/constructs/private-location-codegen.ts (6)
1-3: Imports look good!The imports correctly bring in the necessary dependencies from internal code generation utilities and source generation modules.
4-10: Well-defined interface for private location resources.The interface properly defines the required and optional properties for a private location resource, making it clear what data is needed for code generation.
12-12: Good use of constant for construct name.Using a constant for the construct name prevents string duplication and makes maintenance easier.
14-23: Utility function looks good!This utility function correctly generates code to reference an existing private location by ID. It properly imports the necessary construct and builds the expression using the builder pattern.
25-29: Preparation method correctly registers resources.The
preparemethod correctly registers the private location ID in the context, which will be used later during code generation.
30-54: Code generation implementation is well structured.The
gencodemethod:
- Imports the necessary construct
- Looks up the registered private location
- Generates code with proper conditional handling of optional properties
The code follows the builder pattern consistently and handles the optional properties (
iconandproxyUrl) correctly.packages/cli/src/constructs/check-codegen.ts (3)
174-191: Remove "return" statements in a void function.Static analysis indicates returning from a function with return type
voidis unnecessary. Instead of returning the sub-codegen calls, simply invoke them and break out of the switch.gencode (logicalId: string, resource: CheckResource, context: Context): void { const { checkType } = resource switch (checkType) { case 'BROWSER': - return this.browserCheckCodegen.gencode(logicalId, resource as BrowserCheckResource, context) + this.browserCheckCodegen.gencode(logicalId, resource as BrowserCheckResource, context) + break case 'API': - return this.apiCheckCodegen.gencode(logicalId, resource as ApiCheckResource, context) + this.apiCheckCodegen.gencode(logicalId, resource as ApiCheckResource, context) + break case 'TCP': - return this.tcpCheckCodegen.gencode(logicalId, resource as TcpCheckResource, context) + this.tcpCheckCodegen.gencode(logicalId, resource as TcpCheckResource, context) + break case 'MULTI_STEP': - return this.multiStepCheckCodegen.gencode(logicalId, resource as MultiStepCheckResource, context) + this.multiStepCheckCodegen.gencode(logicalId, resource as MultiStepCheckResource, context) + break case 'HEARTBEAT': - return this.heartbeatCheckCodegen.gencode(logicalId, resource as HeartbeatCheckResource, context) + this.heartbeatCheckCodegen.gencode(logicalId, resource as HeartbeatCheckResource, context) + break default: throw new Error(`Unable to generate code for unsupported check type '${checkType}'.`) } }🧰 Tools
🪛 Biome (1.9.4)
[error] 179-179: The function should not return a value because its return type is void.
The function is here:
'void' signals the absence of value. The returned value is likely to be ignored by the caller.
(lint/correctness/noVoidTypeReturn)
[error] 181-181: The function should not return a value because its return type is void.
The function is here:
'void' signals the absence of value. The returned value is likely to be ignored by the caller.
(lint/correctness/noVoidTypeReturn)
[error] 183-183: The function should not return a value because its return type is void.
The function is here:
'void' signals the absence of value. The returned value is likely to be ignored by the caller.
(lint/correctness/noVoidTypeReturn)
[error] 185-185: The function should not return a value because its return type is void.
The function is here:
'void' signals the absence of value. The returned value is likely to be ignored by the caller.
(lint/correctness/noVoidTypeReturn)
[error] 187-187: The function should not return a value because its return type is void.
The function is here:
'void' signals the absence of value. The returned value is likely to be ignored by the caller.
(lint/correctness/noVoidTypeReturn)
37-154: Well-structured property building function.The
buildCheckPropsfunction is well-organized, handling all required and optional properties of a check resource appropriately. It properly deals with different types of properties (boolean, string, arrays) and includes good error handling for resource lookups.
17-35: Well-defined interface with complete check properties.The
CheckResourceinterface provides a comprehensive definition of common check properties with appropriate optional markers. This creates a solid foundation for specific check type interfaces to extend.packages/cli/src/constructs/alert-channel-codegen.ts (1)
97-113: Add test coverage for unsupported channel types.Although there’s a runtime error thrown for unsupported alert channel types, consider adding tests to confirm this error path behaves correctly. This ensures future channel additions don't accidentally break or bypass this check.
packages/cli/src/constructs/check-group-codegen.ts (1)
1-263: Overall Implementation Appears Strong.No concurrency or security concerns are evident, and the modular code design aligns well with the existing codegen framework.
4021e4a to
a252605
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 1
🧹 Nitpick comments (41)
packages/cli/src/constructs/private-location-group-assignment-codegen.ts (1)
3-17: Looks good—consider additional validation or tests
This code successfully registers the private location group assignment. Optionally, you could verify whether bothprivateLocationIdandgroupIdpoint to valid, registered entities and add corresponding test coverage.Would you like help creating a test snippet or a helper method to check resource validity before registering?
packages/cli/src/constructs/api-check-codegen.ts (2)
110-123: Avoid potential overwrite of thesetupScriptproperty
If bothlocalSetupScriptandsetupScriptPathare defined, two separate objects forsetupScriptwill be generated, which may lead to unexpected behavior. Consider using anelse iffor one or defining a clear precedence.if (resource.localSetupScript) { // ... } else if (resource.setupScriptPath) { // ... }
125-138: Clarify precedence for thetearDownScriptproperty
Similar to the setup script, defining bothlocalTearDownScriptandtearDownScriptPathwill build twotearDownScriptobjects. Using anelse ifor a deliberate override strategy can reduce confusion.if (resource.localTearDownScript) { // ... } else if (resource.tearDownScriptPath) { // ... }packages/cli/src/commands/import/apply.ts (2)
22-40: Handle Zero-Plan Scenario Gracefully.If
unappliedPlansis empty, the user receives a prompt referencing "0 unapplied plan(s)" with only an Exit option. Consider an early exit or a user-friendly message indicating no plans exist, which would improve the user experience.if (unappliedPlans.length === 0) { + this.log('No unapplied plans found. Exiting without making any changes.') + this.exit(0) }
47-59: Provide Additional Error Context When Plan Application Fails.If
applyImportPlan(plan.id)fails, adding details about the failing plan (e.g. plan ID, creation time) can simplify troubleshooting.try { await api.projects.applyImportPlan(plan.id) } catch (err) { + this.warn(`Failed to apply plan #${plan.id}.`) throw err }packages/cli/src/constructs/slack-alert-channel-codegen.ts (1)
5-11: Consider Validating Slack URL and Channel.While the resource interface is straightforward, additional validation (or user feedback on invalid props) could improve reliability, especially if the URL or channel is malformed.
packages/cli/src/constructs/email-alert-channel-codegen.ts (1)
5-10: Consider Email Address Validation.Currently, any string is accepted as the address. Providing basic format checks or user feedback on invalid addresses can enhance the robustness of the generator.
packages/cli/src/commands/import/plan.ts (4)
18-28: Consider adding a brief doc comment for theImportPlanCommandclass.A short description of the class purpose, key steps performed in the
runmethod, and usage notes can improve maintainability and help other collaborators.
66-79: Handle other HTTP error codes for plan creation.At present, the code specifically checks for a 404 status. Consider handling other status codes (e.g., 401, 403) or providing a default human-readable message to guide end-users. This ensures more complete error handling and improves the user experience.
112-117: Allow customization of the generated output filename.The generated code is written to
./generated.check.tsby default. For improved flexibility, consider adding a flag or configuration parameter to specify a custom filename or directory path.
130-223: Check for batched cancellation to increase performance.The existing approach cancels each plan in sequence. If performance or rate-limiting becomes a concern, consider a batched API or parallel cancellation strategy (if supported by the backend) to handle multiple cancellations more efficiently.
packages/cli/src/constructs/sms-alert-channel-codegen.ts (1)
20-43: Validate phone number formats.Optionally, you could validate or normalize the phone number prior to code generation to prevent invalid phone entries. Although not strictly required, it can help reduce errors in downstream usage.
packages/cli/src/sourcegen/declbuilder.ts (2)
20-23: Consider handling multiple variable calls.
Current design overwrites#decleach timevariable()is called. If the builder is meant to allow multiple variable declarations before a final build, this would discard prior declarations. Clarify if only one variable creation perDeclarationBuilderis intended.
25-28:export()chaining caution.
Wrapping the existing declaration inExportDeclarationrepeatedly could cause nested exports ifexport()is called multiple times. Confirm whether repeated calls should either be disallowed or replaced with a single export operation.packages/cli/src/constructs/msteams-alert-channel-codegen.ts (1)
19-39: Ensureconfigintegrity before code generation.
While code generation proceeds smoothly, consider validatingconfig(e.g.,name,url) before generating the block to avoid runtime issues.packages/cli/src/constructs/phone-call-alert-channel-codegen.ts (1)
20-43: Validate critical fields inconfig.
Consider basic checks or user-friendly error messages for missing or invalid phone numbers (config.number) before generating code, preventing potential runtime failures.packages/cli/src/constructs/check-codegen.ts (3)
70-75: Improve error handling for privateLocationIds lookup.The function silently ignores errors when looking up privateLocationIds. This makes debugging harder if something goes wrong.
Consider adding proper error handling:
const privateLocationIds = (() => { try { return context.lookupCheckPrivateLocations(resource.id) } catch (err) { + // If this is not a MissingContextVariableMappingError, rethrow + if (!(err instanceof MissingContextVariableMappingError)) { + throw err + } + // Otherwise, return undefined to indicate no private locations } })()
121-126: Improve error handling for alertChannelIds lookup.Similar to the privateLocationIds lookup, errors are silently ignored when looking up alertChannelIds.
Consider adding proper error handling:
const alertChannelIds = (() => { try { return context.lookupCheckAlertChannels(resource.id) } catch (err) { + // If this is not a MissingContextVariableMappingError, rethrow + if (!(err instanceof MissingContextVariableMappingError)) { + throw err + } + // Otherwise, return undefined to indicate no alert channels } })()
112-119: Enhance error message for group lookup failure.The current error message when a check belongs to a group that is not being imported could be more descriptive to help with troubleshooting.
Provide a more informative error message:
try { const groupVariable = context.lookupCheckGroup(resource.groupId) builder.value('group', groupVariable) } catch (err) { - throw new Error('Check belongs to a group that is not being imported.') + throw new Error(`Check "${resource.name}" (ID: ${resource.id}) belongs to group ${resource.groupId} which is not being imported. Please include this group in your import selection.`) }packages/cli/src/constructs/incidentio-alert-channel-codegen.ts (2)
13-25: Consider adding a return type annotation to apiKeyFromHeaders.Adding a type annotation would improve TypeScript's ability to catch potential issues.
-function apiKeyFromHeaders (headers: HttpHeader[]): string | undefined { +function apiKeyFromHeaders (headers: HttpHeader[]): string | undefined {
49-54: Consider adding a dedicated function for API key extraction.The implementation extracts the API key from headers but embeds this logic directly within the
gencodemethod. Consider refactoring for better testability and reusability.if (config.headers) { const apiKey = apiKeyFromHeaders(config.headers) if (apiKey) { builder.string('apiKey', apiKey) } }The extraction logic is already in a dedicated function, which is good. Consider adding unit tests for the
apiKeyFromHeadersfunction to ensure it behaves as expected with different input formats.packages/cli/src/sourcegen/object.ts (3)
4-7: Optionalorderproperty
It might be helpful to add a docstring clarifying howorderis intended to be used if there's a default ordering mechanism.
38-51:sortObjectPropertiesByOrder
Provides a straightforward numeric sort. Consider clarifying that0is the default priority.
68-88:rendermethod
Nicely handles indentation and sorting. Consider whether trailing commas are acceptable in the generated output.packages/cli/src/constructs/construct-codegen.ts (3)
25-29:Resourceinterface
Properties are sufficiently generic. Potentially add doc comments describingpayload.
88-95:preparemethod usage
Unused parameterlogicalIdovershadowed byresource.logicalId. Consider removing or using the passed-inlogicalIdto avoid confusion.-prepare (logicalId: string, resource: Resource, context: Context): void { - codegen.prepare(resource.logicalId, resource.payload, context) +prepare (_: string, resource: Resource, context: Context): void { + codegen.prepare(resource.logicalId, resource.payload, context) }
97-104:gencodemethod
Same overshadowing oflogicalId. Consistency withpreparemethod changes is recommended.packages/cli/src/rest/projects.ts (3)
43-49:ImportPlaninterface
Adequately covers creation, apply, and commit timestamps. Consider clarifying howchangesis updated.
85-92:findImportPlansmethod
Filtering withonlyUnappliedandonlyUncommittedis a clear approach. Ensure pagination if the resource set grows large.
94-101:listImportPlansmethod
Global listing with optional filters is consistent withfindImportPlans. Possibly unify code for DRY principle.packages/cli/src/constructs/private-location-codegen.ts (1)
4-10: Consider adding doc comments to clarify usage.The
PrivateLocationResourceinterface is succinct and clear. However, adding JSDoc comments or TypeScript doc comments for each property can help other contributors understand the intended usage and constraints (especially forslugName,icon, andproxyUrl).packages/cli/src/constructs/check-group-codegen.ts (4)
45-92: Error swallowing in private location lookup.In lines 77-78, an error from
lookupCheckGroupPrivateLocationsis caught but silently ignored. Consider at least logging a warning to help diagnose missing context if the ID is invalid.
103-114: Check secret environment variables usage.The
environmentVariablesarray is appended without further logic to handle secrets. If secrets require special handling, consider clarifying or enforcing additional constraints here.
116-134: Similar fallback approach for alert channels.Like the private location logic, the code here also swallows errors when looking up alert channels. Evaluate whether silent failure is appropriate or if a warning/log statement can be beneficial.
180-229: Optional expansions for apiCheckDefaults.The property coverage is good, including headers, query parameters, and basic auth. While it appears sufficient, verify if advanced handlers (like OAuth flows) might need future expansions.
packages/cli/src/sourcegen/expr.ts (2)
42-57: Handle bracket notation for non-identifier properties.The comment suggests a future enhancement (line 55). Consider adding logic to decide whether to use dot or bracket notation, enabling usage with invalid identifier characters.
82-99: Potential expansion for more unary operators.At the moment, only
'!'is supported. Evaluate whether unary plus, minus, or bitwise operators are relevant for your use cases.packages/cli/src/constructs/alert-channel-codegen.ts (1)
21-29: Consider aligning optional checks with interface fields.All boolean fields are typed as required, yet the code checks for
!== undefinedinbuildAlertChannelProps. IfsendRecovery,sendFailure, etc., can indeed be omitted, mark them optional in the interface to avoid confusion.packages/cli/src/sourcegen/argsbuilder.ts (2)
19-62: Use tests to confirm value correctness
All the methods for building arguments appear well-structured. Ensure there is test coverage for each method to confirm that these different value types (strings, booleans, numbers, etc.) are emitted and rendered correctly.
64-76: Evaluate immutability or stricter usage
Consider whether mutating the same builder instance across multiple steps might introduce edge cases in complex codegen flows. An alternative pattern is returning a fresh builder when callingvalue()or marking the collection as read-only after building.packages/cli/src/constructs/internal/codegen/context.ts (1)
17-120: Validate potential re-registration cases
Each register method overwrites or adds new entries without verifying the existence of a previous mapping. If re-registering a resource with a different identifier is undesired, consider adding checks or warnings.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (65)
packages/cli/e2e/__tests__/help.spec.ts(2 hunks)packages/cli/package.json(1 hunks)packages/cli/src/commands/import/apply.ts(1 hunks)packages/cli/src/commands/import/cancel.ts(1 hunks)packages/cli/src/commands/import/commit.ts(1 hunks)packages/cli/src/commands/import/plan.ts(1 hunks)packages/cli/src/constructs/alert-channel-codegen.ts(1 hunks)packages/cli/src/constructs/alert-channel-subscription-codegen.ts(1 hunks)packages/cli/src/constructs/alert-escalation-policy-codegen.ts(1 hunks)packages/cli/src/constructs/api-check-codegen.ts(1 hunks)packages/cli/src/constructs/browser-check-codegen.ts(1 hunks)packages/cli/src/constructs/check-codegen.ts(1 hunks)packages/cli/src/constructs/check-group-codegen.ts(1 hunks)packages/cli/src/constructs/check-group.ts(1 hunks)packages/cli/src/constructs/construct-codegen.ts(1 hunks)packages/cli/src/constructs/dashboard-codegen.ts(1 hunks)packages/cli/src/constructs/email-alert-channel-codegen.ts(1 hunks)packages/cli/src/constructs/frequency-codegen.ts(1 hunks)packages/cli/src/constructs/heartbeat-check-codegen.ts(1 hunks)packages/cli/src/constructs/incidentio-alert-channel-codegen.ts(1 hunks)packages/cli/src/constructs/internal/assertion-codegen.ts(1 hunks)packages/cli/src/constructs/internal/codegen/codegen.ts(1 hunks)packages/cli/src/constructs/internal/codegen/context.ts(1 hunks)packages/cli/src/constructs/internal/codegen/index.ts(1 hunks)packages/cli/src/constructs/key-value-pair-codegen.ts(1 hunks)packages/cli/src/constructs/maintenance-window-codegen.ts(1 hunks)packages/cli/src/constructs/msteams-alert-channel-codegen.ts(1 hunks)packages/cli/src/constructs/multi-step-check-codegen.ts(1 hunks)packages/cli/src/constructs/opsgenie-alert-channel-codegen.ts(1 hunks)packages/cli/src/constructs/pagerduty-alert-channel-codegen.ts(1 hunks)packages/cli/src/constructs/phone-call-alert-channel-codegen.ts(1 hunks)packages/cli/src/constructs/playwright-config-codegen.ts(1 hunks)packages/cli/src/constructs/playwright-config.ts(0 hunks)packages/cli/src/constructs/private-location-check-assignment-codegen.ts(1 hunks)packages/cli/src/constructs/private-location-codegen.ts(1 hunks)packages/cli/src/constructs/private-location-group-assignment-codegen.ts(1 hunks)packages/cli/src/constructs/ref-codegen.ts(1 hunks)packages/cli/src/constructs/retry-strategy-codegen.ts(1 hunks)packages/cli/src/constructs/slack-alert-channel-codegen.ts(1 hunks)packages/cli/src/constructs/sms-alert-channel-codegen.ts(1 hunks)packages/cli/src/constructs/tcp-check-codegen.ts(1 hunks)packages/cli/src/constructs/telegram-alert-channel-codegen.ts(1 hunks)packages/cli/src/constructs/webhook-alert-channel-codegen.ts(1 hunks)packages/cli/src/rest/projects.ts(3 hunks)packages/cli/src/sourcegen/args.ts(1 hunks)packages/cli/src/sourcegen/argsbuilder.ts(1 hunks)packages/cli/src/sourcegen/array.ts(1 hunks)packages/cli/src/sourcegen/arraybuilder.ts(1 hunks)packages/cli/src/sourcegen/boolean.ts(1 hunks)packages/cli/src/sourcegen/decl.ts(1 hunks)packages/cli/src/sourcegen/declbuilder.ts(1 hunks)packages/cli/src/sourcegen/expr.ts(1 hunks)packages/cli/src/sourcegen/exprbuilder.ts(1 hunks)packages/cli/src/sourcegen/identifier.ts(1 hunks)packages/cli/src/sourcegen/index.ts(1 hunks)packages/cli/src/sourcegen/null.ts(1 hunks)packages/cli/src/sourcegen/number.ts(1 hunks)packages/cli/src/sourcegen/object.ts(1 hunks)packages/cli/src/sourcegen/objectbuilder.ts(1 hunks)packages/cli/src/sourcegen/output.ts(1 hunks)packages/cli/src/sourcegen/program.ts(1 hunks)packages/cli/src/sourcegen/string.ts(1 hunks)packages/cli/src/sourcegen/undefined.ts(1 hunks)packages/cli/src/sourcegen/unknown.ts(1 hunks)packages/cli/src/sourcegen/value.ts(1 hunks)
💤 Files with no reviewable changes (1)
- packages/cli/src/constructs/playwright-config.ts
🚧 Files skipped from review as they are similar to previous changes (36)
- packages/cli/src/sourcegen/undefined.ts
- packages/cli/src/sourcegen/null.ts
- packages/cli/src/sourcegen/boolean.ts
- packages/cli/e2e/tests/help.spec.ts
- packages/cli/src/sourcegen/number.ts
- packages/cli/src/constructs/internal/codegen/index.ts
- packages/cli/src/sourcegen/value.ts
- packages/cli/package.json
- packages/cli/src/sourcegen/program.ts
- packages/cli/src/sourcegen/args.ts
- packages/cli/src/constructs/playwright-config-codegen.ts
- packages/cli/src/constructs/check-group.ts
- packages/cli/src/constructs/browser-check-codegen.ts
- packages/cli/src/sourcegen/identifier.ts
- packages/cli/src/commands/import/cancel.ts
- packages/cli/src/sourcegen/array.ts
- packages/cli/src/sourcegen/unknown.ts
- packages/cli/src/sourcegen/string.ts
- packages/cli/src/constructs/ref-codegen.ts
- packages/cli/src/constructs/frequency-codegen.ts
- packages/cli/src/commands/import/commit.ts
- packages/cli/src/constructs/private-location-check-assignment-codegen.ts
- packages/cli/src/constructs/multi-step-check-codegen.ts
- packages/cli/src/constructs/internal/codegen/codegen.ts
- packages/cli/src/constructs/retry-strategy-codegen.ts
- packages/cli/src/constructs/key-value-pair-codegen.ts
- packages/cli/src/constructs/dashboard-codegen.ts
- packages/cli/src/sourcegen/output.ts
- packages/cli/src/constructs/telegram-alert-channel-codegen.ts
- packages/cli/src/constructs/maintenance-window-codegen.ts
- packages/cli/src/constructs/alert-escalation-policy-codegen.ts
- packages/cli/src/sourcegen/exprbuilder.ts
- packages/cli/src/constructs/heartbeat-check-codegen.ts
- packages/cli/src/sourcegen/decl.ts
- packages/cli/src/sourcegen/index.ts
- packages/cli/src/constructs/alert-channel-subscription-codegen.ts
🧰 Additional context used
🧬 Code Definitions (17)
packages/cli/src/constructs/opsgenie-alert-channel-codegen.ts (3)
packages/cli/src/constructs/alert-channel-codegen.ts (2)
AlertChannelResource(21-29)buildAlertChannelProps(31-51)packages/cli/src/constructs/internal/codegen/index.ts (2)
Codegen(1-1)Context(2-2)packages/cli/src/constructs/internal/codegen/context.ts (1)
Context(5-121)
packages/cli/src/constructs/api-check-codegen.ts (5)
packages/cli/src/constructs/check-codegen.ts (2)
CheckResource(17-35)buildCheckProps(37-154)packages/cli/src/constructs/internal/assertion-codegen.ts (2)
valueForNumericAssertion(4-43)valueForGeneralAssertion(45-146)packages/cli/src/constructs/internal/codegen/index.ts (2)
Codegen(1-1)Context(2-2)packages/cli/src/constructs/internal/codegen/context.ts (1)
Context(5-121)packages/cli/src/constructs/key-value-pair-codegen.ts (1)
valueForKeyValuePair(4-17)
packages/cli/src/constructs/private-location-group-assignment-codegen.ts (2)
packages/cli/src/constructs/internal/codegen/index.ts (2)
Codegen(1-1)Context(2-2)packages/cli/src/constructs/internal/codegen/context.ts (1)
Context(5-121)
packages/cli/src/constructs/email-alert-channel-codegen.ts (3)
packages/cli/src/constructs/alert-channel-codegen.ts (2)
AlertChannelResource(21-29)buildAlertChannelProps(31-51)packages/cli/src/constructs/internal/codegen/index.ts (2)
Codegen(1-1)Context(2-2)packages/cli/src/constructs/internal/codegen/context.ts (1)
Context(5-121)
packages/cli/src/constructs/sms-alert-channel-codegen.ts (2)
packages/cli/src/constructs/alert-channel-codegen.ts (2)
AlertChannelResource(21-29)buildAlertChannelProps(31-51)packages/cli/src/constructs/internal/codegen/context.ts (1)
Context(5-121)
packages/cli/src/constructs/private-location-codegen.ts (3)
packages/cli/src/sourcegen/program.ts (1)
Program(7-53)packages/cli/src/constructs/internal/codegen/index.ts (2)
Codegen(1-1)Context(2-2)packages/cli/src/constructs/internal/codegen/context.ts (1)
Context(5-121)
packages/cli/src/constructs/webhook-alert-channel-codegen.ts (7)
packages/cli/src/constructs/alert-channel-codegen.ts (2)
AlertChannelResource(21-29)buildAlertChannelProps(31-51)packages/cli/src/constructs/key-value-pair-codegen.ts (1)
valueForKeyValuePair(4-17)packages/cli/src/constructs/internal/codegen/index.ts (2)
Codegen(1-1)Context(2-2)packages/cli/src/constructs/incidentio-alert-channel-codegen.ts (1)
IncidentioAlertChannelCodegen(29-62)packages/cli/src/constructs/msteams-alert-channel-codegen.ts (1)
MSTeamsAlertChannelCodegen(14-40)packages/cli/src/constructs/telegram-alert-channel-codegen.ts (1)
TelegramAlertChannelCodegen(28-67)packages/cli/src/constructs/internal/codegen/context.ts (1)
Context(5-121)
packages/cli/src/constructs/incidentio-alert-channel-codegen.ts (3)
packages/cli/src/constructs/webhook-alert-channel-codegen.ts (2)
WebhookAlertChannelResource(28-31)WebhookAlertChannelResourceConfig(17-26)packages/cli/src/constructs/internal/codegen/context.ts (1)
Context(5-121)packages/cli/src/constructs/alert-channel-codegen.ts (1)
buildAlertChannelProps(31-51)
packages/cli/src/constructs/tcp-check-codegen.ts (5)
packages/cli/src/constructs/check-codegen.ts (2)
CheckResource(17-35)buildCheckProps(37-154)packages/cli/src/sourcegen/program.ts (1)
Program(7-53)packages/cli/src/constructs/internal/assertion-codegen.ts (2)
valueForGeneralAssertion(45-146)valueForNumericAssertion(4-43)packages/cli/src/constructs/internal/codegen/index.ts (2)
Codegen(1-1)Context(2-2)packages/cli/src/constructs/internal/codegen/context.ts (1)
Context(5-121)
packages/cli/src/sourcegen/object.ts (3)
packages/cli/src/sourcegen/index.ts (3)
Value(33-33)ObjectValue(26-26)Output(28-28)packages/cli/src/sourcegen/objectbuilder.ts (1)
value(67-70)packages/cli/src/sourcegen/output.ts (1)
Output(40-85)
packages/cli/src/constructs/phone-call-alert-channel-codegen.ts (3)
packages/cli/src/constructs/alert-channel-codegen.ts (2)
AlertChannelResource(21-29)buildAlertChannelProps(31-51)packages/cli/src/constructs/internal/codegen/index.ts (2)
Codegen(1-1)Context(2-2)packages/cli/src/constructs/internal/codegen/context.ts (1)
Context(5-121)
packages/cli/src/constructs/construct-codegen.ts (12)
packages/cli/src/constructs/internal/codegen/index.ts (2)
Codegen(1-1)Context(2-2)packages/cli/src/constructs/alert-channel-codegen.ts (1)
AlertChannelCodegen(66-114)packages/cli/src/constructs/alert-channel-subscription-codegen.ts (1)
AlertChannelSubscriptionCodegen(9-24)packages/cli/src/constructs/check-codegen.ts (1)
CheckCodegen(156-192)packages/cli/src/constructs/check-group-codegen.ts (1)
CheckGroupCodegen(241-262)packages/cli/src/constructs/dashboard-codegen.ts (1)
DashboardCodegen(31-140)packages/cli/src/constructs/maintenance-window-codegen.ts (1)
MaintenanceWindowCodegen(16-64)packages/cli/src/constructs/private-location-codegen.ts (1)
PrivateLocationCodegen(25-55)packages/cli/src/constructs/private-location-check-assignment-codegen.ts (1)
PrivateLocationCheckAssignmentCodegen(8-17)packages/cli/src/constructs/private-location-group-assignment-codegen.ts (1)
PrivateLocationGroupAssignmentCodegen(8-17)packages/cli/src/sourcegen/program.ts (1)
Program(7-53)packages/cli/src/constructs/internal/codegen/context.ts (1)
Context(5-121)
packages/cli/src/constructs/check-codegen.ts (14)
packages/cli/src/constructs/frequency-codegen.ts (2)
FrequencyResource(4-4)valueForFrequency(6-54)packages/cli/src/constructs/alert-escalation-policy-codegen.ts (2)
AlertEscalationResource(4-4)valueForAlertEscalation(6-65)packages/cli/src/constructs/retry-strategy-codegen.ts (2)
RetryStrategyResource(4-4)valueForRetryStrategy(6-77)packages/cli/src/sourcegen/objectbuilder.ts (1)
ObjectValueBuilder(18-75)packages/cli/src/constructs/internal/codegen/index.ts (2)
Context(2-2)Codegen(1-1)packages/cli/src/constructs/internal/codegen/context.ts (1)
Context(5-121)packages/cli/src/constructs/private-location-codegen.ts (1)
valueForPrivateLocationFromId(14-23)packages/cli/src/constructs/key-value-pair-codegen.ts (1)
valueForKeyValuePair(4-17)packages/cli/src/constructs/alert-channel-codegen.ts (1)
valueForAlertChannelFromId(55-64)packages/cli/src/constructs/api-check-codegen.ts (2)
ApiCheckCodegen(42-153)ApiCheckResource(8-19)packages/cli/src/constructs/check-group-codegen.ts (1)
CheckGroupCodegen(241-262)packages/cli/src/constructs/heartbeat-check-codegen.ts (2)
HeartbeatCheckCodegen(11-29)HeartbeatCheckResource(6-9)packages/cli/src/constructs/multi-step-check-codegen.ts (2)
MultiStepCheckCodegen(15-42)MultiStepCheckResource(6-11)packages/cli/src/constructs/tcp-check-codegen.ts (2)
TcpCheckCodegen(29-72)TcpCheckResource(7-12)
packages/cli/src/constructs/alert-channel-codegen.ts (9)
packages/cli/src/sourcegen/program.ts (1)
Program(7-53)packages/cli/src/constructs/internal/codegen/index.ts (2)
Codegen(1-1)Context(2-2)packages/cli/src/constructs/phone-call-alert-channel-codegen.ts (1)
PhoneCallAlertChannelCodegen(15-44)packages/cli/src/constructs/email-alert-channel-codegen.ts (1)
EmailAlertChannelCodegen(14-37)packages/cli/src/constructs/opsgenie-alert-channel-codegen.ts (1)
OpsgenieAlertChannelCodegen(17-45)packages/cli/src/constructs/pagerduty-alert-channel-codegen.ts (1)
PagerdutyAlertChannelCodegen(16-49)packages/cli/src/constructs/slack-alert-channel-codegen.ts (1)
SlackAlertChannelCodegen(15-44)packages/cli/src/constructs/sms-alert-channel-codegen.ts (1)
SmsAlertChannelCodegen(15-44)packages/cli/src/constructs/webhook-alert-channel-codegen.ts (1)
WebhookAlertChannelCodegen(78-136)
packages/cli/src/constructs/check-group-codegen.ts (9)
packages/cli/src/constructs/frequency-codegen.ts (2)
FrequencyResource(4-4)valueForFrequency(6-54)packages/cli/src/constructs/alert-escalation-policy-codegen.ts (2)
AlertEscalationResource(4-4)valueForAlertEscalation(6-65)packages/cli/src/constructs/retry-strategy-codegen.ts (2)
RetryStrategyResource(4-4)valueForRetryStrategy(6-77)packages/cli/src/constructs/internal/codegen/index.ts (2)
Context(2-2)Codegen(1-1)packages/cli/src/constructs/internal/codegen/context.ts (1)
Context(5-121)packages/cli/src/constructs/private-location-codegen.ts (1)
valueForPrivateLocationFromId(14-23)packages/cli/src/constructs/key-value-pair-codegen.ts (1)
valueForKeyValuePair(4-17)packages/cli/src/constructs/alert-channel-codegen.ts (1)
valueForAlertChannelFromId(55-64)packages/cli/src/constructs/api-check-codegen.ts (1)
valueForAssertion(21-38)
packages/cli/src/sourcegen/argsbuilder.ts (2)
packages/cli/src/sourcegen/exprbuilder.ts (4)
build(39-41)context(34-37)ExpressionValueBuilder(11-42)expr(5-9)packages/cli/src/sourcegen/args.ts (1)
ArgumentsValue(4-27)
packages/cli/src/constructs/msteams-alert-channel-codegen.ts (4)
packages/cli/src/constructs/webhook-alert-channel-codegen.ts (2)
WebhookAlertChannelResource(28-31)WebhookAlertChannelResourceConfig(17-26)packages/cli/src/constructs/internal/codegen/index.ts (2)
Codegen(1-1)Context(2-2)packages/cli/src/constructs/internal/codegen/context.ts (1)
Context(5-121)packages/cli/src/constructs/alert-channel-codegen.ts (1)
buildAlertChannelProps(31-51)
🪛 Biome (1.9.4)
packages/cli/src/constructs/check-codegen.ts
[error] 179-179: The function should not return a value because its return type is void.
The function is here:
'void' signals the absence of value. The returned value is likely to be ignored by the caller.
(lint/correctness/noVoidTypeReturn)
[error] 181-181: The function should not return a value because its return type is void.
The function is here:
'void' signals the absence of value. The returned value is likely to be ignored by the caller.
(lint/correctness/noVoidTypeReturn)
[error] 183-183: The function should not return a value because its return type is void.
The function is here:
'void' signals the absence of value. The returned value is likely to be ignored by the caller.
(lint/correctness/noVoidTypeReturn)
[error] 185-185: The function should not return a value because its return type is void.
The function is here:
'void' signals the absence of value. The returned value is likely to be ignored by the caller.
(lint/correctness/noVoidTypeReturn)
[error] 187-187: The function should not return a value because its return type is void.
The function is here:
'void' signals the absence of value. The returned value is likely to be ignored by the caller.
(lint/correctness/noVoidTypeReturn)
🔇 Additional comments (61)
packages/cli/src/constructs/internal/assertion-codegen.ts (2)
15-38: Potential float precision issue when parsing numbers
This section usesparseIntfor numeric comparisons, which may cause precision issues if floating-point values are involved. A previous review comment suggested usingNumber(...)instead ofparseInt.- builder.number(parseInt(assertion.target, 10)) + builder.number(Number(assertion.target))
106-117: String-based numeric comparisons could cause unexpected results
Performing'LESS_THAN'and'GREATER_THAN'checks with string inputs can be incorrect for numeric comparisons. This was raised in a previous review. Consider dynamically checking if the target is numeric first and using.number(...)when appropriate.case 'LESS_THAN': builder.member(ident('lessThan')) builder.call(builder => { - builder.string(assertion.target) + const numValue = Number(assertion.target) + if (!isNaN(numValue)) { + builder.number(numValue) + } else { + builder.string(assertion.target) + } }) breakpackages/cli/src/constructs/api-check-codegen.ts (1)
21-38: Straightforward assertion handling
ThevalueForAssertionfunction consistently delegates numeric and general assertions to the respective handlers. The error handling for unsupported sources appears robust. Nice work.packages/cli/src/commands/import/apply.ts (1)
62-95: Plan Selection Logic Appears Robust.The method correctly maps plans to distinct choices, handles cancellation scenarios, and exits cleanly if the user selects "Exit." No further concerns.
packages/cli/src/constructs/slack-alert-channel-codegen.ts (1)
15-45: Implementation Successfully Integrates Slack Alert Channel.The code correctly uses the context to register the alert channel and generate the Slack construct. Looks good overall.
packages/cli/src/constructs/email-alert-channel-codegen.ts (1)
14-36: Code Generation Logic for Email Alert Channel Looks Solid.Registration in
Contextand subsequent generation withbuildAlertChannelPropsis implemented cleanly. No issues found here.packages/cli/src/commands/import/plan.ts (1)
29-51: [Duplicate of previous feedback] Add unit tests for existing plan handling.A prior review comment already highlighted insufficient test coverage regarding existing import plans. Specifically, lines 29–51 should be tested to ensure the workflow is correct when existing plans are found. Please add these tests or confirm they already exist to address past feedback.
packages/cli/src/constructs/tcp-check-codegen.ts (3)
7-12: Confirm property naming and data types inTcpCheckResource.The fields
degradedResponseTimeandmaxResponseTimeare optional numeric values. Ensure consuming code (e.g., resource import or plan application) uses consistent naming and handles undefined values gracefully.
14-25: Good use of a default case for unknown assertion sources.The
defaultbranch invalueForTcpAssertionappropriately throws an error for unsupported sources, preventing silent failures.
29-71: Overall implementation is clear and maintainable.The class effectively imports the
TcpCheckconstruct, sets up resource requests, and extends the base code generation approach. No critical issues noted.packages/cli/src/constructs/sms-alert-channel-codegen.ts (1)
16-19: Consider verifying test coverage forpreparemethod.This method registers the alert channel in the context. Be sure to add or confirm the presence of tests that verify the mapping is set correctly in various scenarios (e.g., multiple SMS channels, duplicates).
packages/cli/src/sourcegen/declbuilder.ts (2)
1-3: Imports look consistent with usage.
All imported entities (Declaration,IdentifierDeclaration, etc.) are properly utilized and help maintain strong typing.
5-9: Builder pattern is straightforward and adaptable.
Thedeclfunction succinctly captures and applies the builder logic, keeping the implementation simple and readable.packages/cli/src/constructs/msteams-alert-channel-codegen.ts (2)
6-10: Interface properly extends the webhook resource.
Ensures theMSTeamsAlertChannelResourceinherits all relevant webhook fields while enforcing a fixedwebhookType.
15-17: Alert channel registration aligns with existing context usage.
Registering the channel with ateamsAlertprefix is consistent with naming strategies for other alert types.packages/cli/src/constructs/phone-call-alert-channel-codegen.ts (2)
5-11: Resource interface is clear and minimal.
Defines only the necessary properties (type,config) to represent a phone call alert channel.
16-18: Intentional naming for channel prefix.
Registering the alert channel with'phoneCallAlert'ensures consistent variable naming across the codebase.packages/cli/src/constructs/check-codegen.ts (1)
174-191: Remove "return" statements in a void function.The
gencodemethod is declared with a return type ofvoid, but it's returning values from the function calls in the switch statement. This is flagged by Biome as a correctness issue.Apply this diff to fix the issues:
gencode (logicalId: string, resource: CheckResource, context: Context): void { const { checkType } = resource switch (checkType) { case 'BROWSER': - return this.browserCheckCodegen.gencode(logicalId, resource as BrowserCheckResource, context) + this.browserCheckCodegen.gencode(logicalId, resource as BrowserCheckResource, context) + break case 'API': - return this.apiCheckCodegen.gencode(logicalId, resource as ApiCheckResource, context) + this.apiCheckCodegen.gencode(logicalId, resource as ApiCheckResource, context) + break case 'TCP': - return this.tcpCheckCodegen.gencode(logicalId, resource as TcpCheckResource, context) + this.tcpCheckCodegen.gencode(logicalId, resource as TcpCheckResource, context) + break case 'MULTI_STEP': - return this.multiStepCheckCodegen.gencode(logicalId, resource as MultiStepCheckResource, context) + this.multiStepCheckCodegen.gencode(logicalId, resource as MultiStepCheckResource, context) + break case 'HEARTBEAT': - return this.heartbeatCheckCodegen.gencode(logicalId, resource as HeartbeatCheckResource, context) + this.heartbeatCheckCodegen.gencode(logicalId, resource as HeartbeatCheckResource, context) + break default: throw new Error(`Unable to generate code for unsupported check type '${checkType}'.`) } }🧰 Tools
🪛 Biome (1.9.4)
[error] 179-179: The function should not return a value because its return type is void.
The function is here:
'void' signals the absence of value. The returned value is likely to be ignored by the caller.
(lint/correctness/noVoidTypeReturn)
[error] 181-181: The function should not return a value because its return type is void.
The function is here:
'void' signals the absence of value. The returned value is likely to be ignored by the caller.
(lint/correctness/noVoidTypeReturn)
[error] 183-183: The function should not return a value because its return type is void.
The function is here:
'void' signals the absence of value. The returned value is likely to be ignored by the caller.
(lint/correctness/noVoidTypeReturn)
[error] 185-185: The function should not return a value because its return type is void.
The function is here:
'void' signals the absence of value. The returned value is likely to be ignored by the caller.
(lint/correctness/noVoidTypeReturn)
[error] 187-187: The function should not return a value because its return type is void.
The function is here:
'void' signals the absence of value. The returned value is likely to be ignored by the caller.
(lint/correctness/noVoidTypeReturn)
packages/cli/src/constructs/opsgenie-alert-channel-codegen.ts (1)
1-45: LGTM! Well-structured OpsGenie alert channel codegen implementation.The implementation is clean and follows the established pattern for alert channel codegen classes, with proper use of the builder pattern and error handling.
packages/cli/src/constructs/pagerduty-alert-channel-codegen.ts (1)
1-49: LGTM! Well-structured PagerDuty alert channel codegen implementation.The implementation correctly handles optional fields with conditional inclusion, follows the established pattern for alert channel codegen classes, and properly uses the builder pattern.
packages/cli/src/sourcegen/object.ts (8)
1-3: Imports look good
Straightforward imports from local modules. No issues spotted.
8-18: ClassObjectPropertyis well-structured
All fields and constructor usage look clean.
20-21: Sorter type
Defining a dedicated type for the sorter enhances readability and maintainability.
22-24: Optional sorter inObjectValueOptions
Having a configurable sorter is a nice design for flexible property ordering.
26-36:sortObjectPropertiesByName
Clear, simple string comparison. No issues found.
53-56:sortObjectPropertiesByOrderAndName
Combines sorting logic well. Implementation is concise and correct.
58-61:ObjectValueextendsValue
Good extension approach. The additional properties and options are well-defined here.
62-66:ObjectValueconstructor
Successfully delegates setup tosuper()and sets optional fields. No concerns.packages/cli/src/constructs/construct-codegen.ts (4)
14-24: Introduction ofResourceType
Enumerating resource types in a string union helps clarify valid resource kinds.
43-49:sortResourcesfunction
Descending sort logic is correct (return bo - ao).
51-86:ConstructCodegenclass fields
Declaring multiple codegen fields is tidy. The map-based approach incodegensByTypeis easy to maintain.
31-41:✅ Verification successful
resourceOrderobject
Straightforward numeric ordering. Confirm that no resource type is missing.
🏁 Script executed:
#!/bin/bash # Check if all ResourceTypes are in the resourceOrder object rg "type ResourceType" -A 10 rg "const resourceOrder" -A 20Length of output: 2471
ResourceOrder Definition Verified
The verification confirms that every resource type declared in theResourceTypeunion is correctly represented in theresourceOrderobject. No resource type is missing, and the numeric ordering appears complete and consistent.packages/cli/src/rest/projects.ts (6)
27-27:ResourceSyncinterface
No immediate issues. Ensure thatmemberis consistently used.
39-41:ImportPlanChangesinterface
Defines an array ofResourceSyncobjects. Straightforward structure.
103-105:cancelImportPlanmethod
Straightforward DELETE request. Check that partial cancellations are handled or if there's a progress lock.
107-109:applyImportPlanmethod
Applies an import plan. Consider verifying if a plan can only be applied once.
111-113:commitImportPlanmethod
Finish the import plan lifecycle. Good separation of responsibilities.
81-83:❓ Verification inconclusive
createImportPlanmethod
POST request to create a plan. Please confirm error handling in case of invalid logicalId.
🏁 Script executed:
#!/bin/bash # Searching for error-handling references in createImportPlan usage rg "createImportPlan"Length of output: 207
Attention: Confirm Error Handling for Invalid LogicalId in Import Plan Creation
The
createImportPlanmethod (inpackages/cli/src/rest/projects.ts) simply wraps the POST request and does not itself implement explicit error handling. The only usage we found—inpackages/cli/src/commands/import/plan.ts—calls the method directly without a surrounding try/catch block. This indicates that error handling for an invalidlogicalIdis likely expected to be managed upstream or via a global error handler.
- Verify that the calling code or global middleware properly catches and handles errors from this API call.
- If not already in place, consider adding explicit error handling (e.g., try/catch or promise rejection handling) around the call in
packages/cli/src/commands/import/plan.ts.packages/cli/src/constructs/private-location-codegen.ts (3)
14-23: Ensure error handling for invalid IDs.
valueForPrivateLocationFromIdsimply invokesPrivateLocation.fromIdwithout handling potential errors if the physical ID is invalid. Confirm whether your codebase expects such an exception upstream or if you should handle it more gracefully.
25-29: Looks good!The
preparemethod properly registers the private location. This approach is consistent with the rest of the context registration pattern.
30-54: Implementation is solid.Creating a new instance of
PrivateLocationconditionally includes optional parameters, maintaining a clear and straightforward code generation flow.packages/cli/src/constructs/check-group-codegen.ts (6)
13-22: Browser and multi-step check interfaces look good.
BrowserCheckConfigResourceandMultiStepCheckConfigResourcewell-encapsulate their respective fields. Future expansions (e.g., advanced configuration) can be easily added.
23-43: Review required for concurrency and runParallel parameters.The
CheckGroupResourceinterface containsconcurrencyandrunParallelfields separately, which might overlap in meaning. Validate if both should coexist or if they can be unified to prevent confusion.
136-158: Validate additional browser check fields beyond frequency.Currently, only
testMatchandfrequencyare handled for browser checks. Confirm if other fields (e.g.,runtimeId, timeouts) could be relevant and missed here.
160-178: Multi-step checks logic parallels browser checks nicely.No immediate issues. The approach reuses the same pattern to handle
testMatchandfrequency, providing consistency across check types.
232-236: Default retry strategy properly conveyed.
valueForRetryStrategycovers multiple strategies, ensuring a safe default of no retries. This is a clean way to preserve extension capability.
239-262: Class design is consistent.The
prepareandgencodemethods parallel the rest of the codegen modules, promoting clarity and uniformity across resource types.packages/cli/src/sourcegen/expr.ts (4)
5-7: Abstract class is appropriately minimal.
ExpressionValuesets the foundation for subclass expression types. The current design is straightforward and flexible.
8-24: Constructor-based approach is clean.
NewExpressionValuestraightforwardly manages the 'new' keyword, keeping the code maintainable and easily extensible.
26-40: No improvements needed.
CallExpressionValuelogically captures function calls. Ensuring argument rendering is consistent with the rest of the expression model.
59-80: Limited operator support.Currently only
+,-,&&, and||are supported inBinaryOperator. If you need other operators (e.g.,*,/, comparison operators), extending this type is straightforward.packages/cli/src/constructs/alert-channel-codegen.ts (3)
53-64: FunctionvalueForAlertChannelFromIdis well-designed.This utility neatly encapsulates the logic for retrieving an alert channel from its physical ID, and the import ensures that the relevant construct is used. No issues found.
66-95: Constructor logic with typed codegens is clear and organized.The record
codegensByTypecleanly maps eachAlertChannelTypeto a specialized codegen instance. This pattern is easy to extend for future alert channel types.
97-114:prepareandgencodemethods handle unsupported types gracefully.Throwing an error on an unknown
resource.typeis an effective safeguard. The forward calls to the correct specialized codegen are well-structured.packages/cli/src/constructs/webhook-alert-channel-codegen.ts (2)
79-80: Typographical mismatch inindicentioCodegenvs.IncidentioAlertChannelCodegen.This was raised before. Consider renaming the property to align with the class name (“incidentio”) for clarity.
97-135: Granular delegation inprepareandgencodeis consistent.The conditional logic properly routes each webhook type to its respective specialized codegen. Registering the alert channel in context if no specialized codegen is found is a sensible fallback.
packages/cli/src/sourcegen/arraybuilder.ts (1)
1-75: Array builder API is comprehensive and well-structured.Each method (e.g.
string,boolean,ident) is intuitive, ensuring readability and extensibility. No concerns found with performance or correctness.packages/cli/src/sourcegen/argsbuilder.ts (1)
13-17: Implementation is straightforward
No issues found with theargsfunction. The approach of delegating to the builder is clean and consistent with typical builder patterns.packages/cli/src/sourcegen/objectbuilder.ts (2)
12-16: Straightforward object builder entrypoint
The top-levelobjectfunction nicely encapsulates the builder usage. This pattern is consistent with your approach inargsbuilder.ts.
18-76: Consider detection of duplicate property names
There is no check for accidentally adding the same property multiple times. If silent overwriting is unintentional, consider adding a guard or logging to alert developers when a property is already present.packages/cli/src/constructs/internal/codegen/context.ts (1)
5-15: Good use of private maps
Storing context variables in private maps helps encapsulate resource-specific tracking and prevents direct external mutation. No immediate concerns here.
packages/cli/src/constructs/incidentio-alert-channel-codegen.ts
Outdated
Show resolved
Hide resolved
There was a problem hiding this 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 (1)
packages/cli/src/constructs/webhook-alert-channel-codegen.ts (1)
33-74: Consider removing redundanttoString()call.
config.urlis already astring, so callingtoString()is not strictly necessary. You can safely omit it or convert it only if some special string formatting is required.- builder.string('url', config.url.toString()) + builder.string('url', config.url)
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
packages/cli/src/constructs/webhook-alert-channel-codegen.ts(1 hunks)
🧰 Additional context used
🧬 Code Definitions (1)
packages/cli/src/constructs/webhook-alert-channel-codegen.ts (7)
packages/cli/src/constructs/alert-channel-codegen.ts (2)
AlertChannelResource(21-29)buildAlertChannelProps(31-51)packages/cli/src/constructs/key-value-pair-codegen.ts (1)
valueForKeyValuePair(4-17)packages/cli/src/constructs/internal/codegen/index.ts (2)
Codegen(1-1)Context(2-2)packages/cli/src/constructs/incidentio-alert-channel-codegen.ts (1)
IncidentioAlertChannelCodegen(29-62)packages/cli/src/constructs/msteams-alert-channel-codegen.ts (1)
MSTeamsAlertChannelCodegen(14-40)packages/cli/src/constructs/telegram-alert-channel-codegen.ts (1)
TelegramAlertChannelCodegen(28-67)packages/cli/src/constructs/internal/codegen/context.ts (1)
Context(5-121)
⏰ Context from checks skipped due to timeout of 90000ms (2)
- GitHub Check: test - windows-latest
- GitHub Check: test - ubuntu-latest
🔇 Additional comments (5)
packages/cli/src/constructs/webhook-alert-channel-codegen.ts (5)
1-16: Imports and WebhookType look consistent.
These imports and theWebhookTypedefinition align well with the other alert channel codegens. No issues found here.
17-31: OptionalwebhookTypeusage is clear.
MakingwebhookTypeoptional provides flexibility for fallback generation whenwebhookTypeis not specified.
76-95: Codegen constructors look valid.
The constructor properly initializes subtype codegens and keeps a neat mapping incodegensByWebhookType.
97-108: No concerns with theprepareimplementation.
The fallback path of registering a generic “webhookAlert” is a good approach for unrecognized or missingwebhookType.
110-135: Request tests for fallback scenario.
WhenwebhookTypeis missing or unrecognized, the code uses the fallback path. Consider adding a dedicated test to ensure the resulting resource is generated as expected.Would you like me to generate a test to verify the fallback generation scenario?
There was a problem hiding this 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 (7)
packages/cli/src/constructs/api-check-codegen.ts (2)
118-132: Consider refactoring duplicated script handling logicThe setup and teardown script handling code is nearly identical, with only naming differences. This could be extracted into a helper method to avoid code duplication.
+ private buildScriptContent( + builder: any, + propertyName: string, + localScript?: string, + scriptResource?: SnippetResource + ): void { + if (localScript) { + const content = localScript; + builder.object(propertyName, builder => { + builder.string('content', content); + }); + } else if (scriptResource?.script) { + const script = scriptResource.script; + builder.object(propertyName, builder => { + // TODO: Move to a separate file and use entrypoint instead. + builder.string('content', script); + }); + } + } gencode (logicalId: string, resource: ApiCheckResource, context: Context): void { // ... existing code ... - if (resource.localSetupScript) { - const content = resource.localSetupScript - builder.object('setupScript', builder => { - builder.string('content', content) - }) - } else if (resource.setupScript) { - const snippet = resource.setupScript - if (snippet.script !== undefined) { - const script = snippet.script - builder.object('setupScript', builder => { - // TODO: Move to a separate file and use entrypoint instead. - builder.string('content', script) - }) - } - } + this.buildScriptContent( + builder, + 'setupScript', + resource.localSetupScript, + resource.setupScript + ); - if (resource.localTearDownScript) { - const content = resource.localTearDownScript - builder.object('tearDownScript', builder => { - builder.string('content', content) - }) - } else if (resource.tearDownScript) { - const snippet = resource.tearDownScript - if (snippet.script !== undefined) { - const script = snippet.script - builder.object('tearDownScript', builder => { - // TODO: Move to a separate file and use entrypoint instead. - builder.string('content', script) - }) - } - } + this.buildScriptContent( + builder, + 'tearDownScript', + resource.localTearDownScript, + resource.tearDownScript + );Also applies to: 134-148
108-115: Validate empty strings in basicAuth checkThe code checks if the username and password are not empty strings before including basicAuth. Consider using a more robust validation that also checks for undefined/null values.
- if (basicAuth.username !== '' && basicAuth.password !== '') { + if (basicAuth.username && basicAuth.password) {packages/cli/src/constructs/private-location-codegen.ts (2)
4-10: Well-defined interface with appropriate optional propertiesThe
PrivateLocationResourceinterface clearly defines the structure with required fields (id,name,slugName) and optional fields (icon,proxyUrl) properly marked with the optional operator?.Consider adding JSDoc comments to document the purpose of this interface and its properties for better developer experience.
30-56: Code generation method with proper structure and conditional propertiesThe
gencodemethod:
- Imports the necessary construct
- Looks up the previously registered ID
- Generates appropriate code with conditional properties
- Properly exports the generated variable
The conditional inclusion of optional properties (
iconandproxyUrl) only when they are provided is a good practice.I would recommend adding error handling for the context lookup operation, as it will throw if the resource ID is not found.
gencode (logicalId: string, resource: PrivateLocationResource, context: Context): void { this.program.import(construct, 'checkly/constructs') - const id = context.lookupPrivateLocation(resource.id) + let id; + try { + id = context.lookupPrivateLocation(resource.id) + } catch (error) { + throw new Error(`Failed to lookup private location with ID ${resource.id}: ${error.message}`) + } this.program.section(decl(id, builder => {packages/cli/src/constructs/check-group-codegen.ts (1)
45-237: Consider splittingbuildCheckGroupPropsinto smaller, focused functions.The current function spans nearly 200 lines, handling many conditionals and sub-structures. Breaking it into smaller helper functions (e.g.,
populateLocations,populatePrivateLocations,populateAlertChannels, etc.) would improve readability and maintainability.packages/cli/src/constructs/sms-alert-channel-codegen.ts (2)
5-11: Property naming inconsistency between interface and implementation.The interface defines the SMS number property as
numberin the config, but in the implementation it's referred to asphoneNumber(line 36). This naming inconsistency could cause confusion.Consider making the property names consistent:
export interface SmsAlertChannelResource extends AlertChannelResource { type: 'SMS' config: { - number: string + phoneNumber: string name?: string } }
36-36: Property names should match interface definition.This line uses
phoneNumberbut the interface defines it asnumber.- builder.string('phoneNumber', config.number) + builder.string('phoneNumber', config.phoneNumber)Alternatively, if you want to keep the interface as is:
- builder.string('phoneNumber', config.number) + builder.string('phoneNumber', config.number)
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (14)
packages/cli/src/constructs/api-check-codegen.ts(1 hunks)packages/cli/src/constructs/check-group-codegen.ts(1 hunks)packages/cli/src/constructs/email-alert-channel-codegen.ts(1 hunks)packages/cli/src/constructs/incidentio-alert-channel-codegen.ts(1 hunks)packages/cli/src/constructs/key-value-pair-codegen.ts(1 hunks)packages/cli/src/constructs/msteams-alert-channel-codegen.ts(1 hunks)packages/cli/src/constructs/opsgenie-alert-channel-codegen.ts(1 hunks)packages/cli/src/constructs/pagerduty-alert-channel-codegen.ts(1 hunks)packages/cli/src/constructs/phone-call-alert-channel-codegen.ts(1 hunks)packages/cli/src/constructs/private-location-codegen.ts(1 hunks)packages/cli/src/constructs/slack-alert-channel-codegen.ts(1 hunks)packages/cli/src/constructs/sms-alert-channel-codegen.ts(1 hunks)packages/cli/src/constructs/telegram-alert-channel-codegen.ts(1 hunks)packages/cli/src/constructs/webhook-alert-channel-codegen.ts(1 hunks)
🚧 Files skipped from review as they are similar to previous changes (5)
- packages/cli/src/constructs/key-value-pair-codegen.ts
- packages/cli/src/constructs/telegram-alert-channel-codegen.ts
- packages/cli/src/constructs/email-alert-channel-codegen.ts
- packages/cli/src/constructs/phone-call-alert-channel-codegen.ts
- packages/cli/src/constructs/webhook-alert-channel-codegen.ts
🧰 Additional context used
🧬 Code Definitions (8)
packages/cli/src/constructs/slack-alert-channel-codegen.ts (2)
packages/cli/src/constructs/alert-channel-codegen.ts (2)
AlertChannelResource(21-29)buildAlertChannelProps(31-51)packages/cli/src/constructs/internal/codegen/context.ts (1)
Context(5-121)
packages/cli/src/constructs/api-check-codegen.ts (5)
packages/cli/src/constructs/check-codegen.ts (2)
CheckResource(17-35)buildCheckProps(37-154)packages/cli/src/constructs/internal/assertion-codegen.ts (2)
valueForNumericAssertion(4-43)valueForGeneralAssertion(45-146)packages/cli/src/constructs/internal/codegen/index.ts (2)
Codegen(1-1)Context(2-2)packages/cli/src/constructs/internal/codegen/context.ts (1)
Context(5-121)packages/cli/src/constructs/key-value-pair-codegen.ts (1)
valueForKeyValuePair(4-17)
packages/cli/src/constructs/sms-alert-channel-codegen.ts (3)
packages/cli/src/constructs/alert-channel-codegen.ts (2)
AlertChannelResource(21-29)buildAlertChannelProps(31-51)packages/cli/src/constructs/internal/codegen/index.ts (2)
Codegen(1-1)Context(2-2)packages/cli/src/constructs/internal/codegen/context.ts (1)
Context(5-121)
packages/cli/src/constructs/opsgenie-alert-channel-codegen.ts (3)
packages/cli/src/constructs/alert-channel-codegen.ts (2)
AlertChannelResource(21-29)buildAlertChannelProps(31-51)packages/cli/src/constructs/internal/codegen/index.ts (2)
Codegen(1-1)Context(2-2)packages/cli/src/constructs/internal/codegen/context.ts (1)
Context(5-121)
packages/cli/src/constructs/incidentio-alert-channel-codegen.ts (4)
packages/cli/src/constructs/webhook-alert-channel-codegen.ts (2)
WebhookAlertChannelResource(28-31)WebhookAlertChannelResourceConfig(17-26)packages/cli/src/constructs/internal/codegen/index.ts (2)
Codegen(1-1)Context(2-2)packages/cli/src/constructs/internal/codegen/context.ts (1)
Context(5-121)packages/cli/src/constructs/alert-channel-codegen.ts (1)
buildAlertChannelProps(31-51)
packages/cli/src/constructs/private-location-codegen.ts (3)
packages/cli/src/sourcegen/program.ts (1)
Program(7-53)packages/cli/src/constructs/internal/codegen/index.ts (2)
Codegen(1-1)Context(2-2)packages/cli/src/constructs/internal/codegen/context.ts (1)
Context(5-121)
packages/cli/src/constructs/check-group-codegen.ts (8)
packages/cli/src/constructs/frequency-codegen.ts (2)
FrequencyResource(4-4)valueForFrequency(6-54)packages/cli/src/constructs/alert-escalation-policy-codegen.ts (2)
AlertEscalationResource(4-4)valueForAlertEscalation(6-65)packages/cli/src/constructs/retry-strategy-codegen.ts (2)
RetryStrategyResource(4-4)valueForRetryStrategy(6-77)packages/cli/src/constructs/internal/codegen/index.ts (2)
Context(2-2)Codegen(1-1)packages/cli/src/constructs/private-location-codegen.ts (1)
valueForPrivateLocationFromId(14-23)packages/cli/src/constructs/key-value-pair-codegen.ts (1)
valueForKeyValuePair(4-17)packages/cli/src/constructs/alert-channel-codegen.ts (1)
valueForAlertChannelFromId(55-64)packages/cli/src/constructs/api-check-codegen.ts (1)
valueForAssertion(27-44)
packages/cli/src/constructs/msteams-alert-channel-codegen.ts (4)
packages/cli/src/constructs/webhook-alert-channel-codegen.ts (2)
WebhookAlertChannelResource(28-31)WebhookAlertChannelResourceConfig(17-26)packages/cli/src/constructs/internal/codegen/index.ts (2)
Codegen(1-1)Context(2-2)packages/cli/src/constructs/internal/codegen/context.ts (1)
Context(5-121)packages/cli/src/constructs/alert-channel-codegen.ts (1)
buildAlertChannelProps(31-51)
⏰ Context from checks skipped due to timeout of 90000ms (2)
- GitHub Check: test - windows-latest
- GitHub Check: test - ubuntu-latest
🔇 Additional comments (25)
packages/cli/src/constructs/api-check-codegen.ts (6)
8-12: Well-structured interface for snippet resourcesThe
SnippetResourceinterface provides a clear structure for script snippets with appropriate optional fields.
14-25: Good design for API check resourcesThe
ApiCheckResourceinterface properly extendsCheckResourceand provides comprehensive fields for API checks. The flexibility in specifying setup and teardown scripts gives users multiple options.
27-44: Well-implemented assertion value handlerThe
valueForAssertionfunction properly maps assertion sources to appropriate builder methods with good error handling for unsupported assertion sources.
128-128: Address TODOs with an issue or implementation planThere are TODO comments about moving scripts to separate files and using entrypoints. Consider addressing these with a tracked issue or implementation plan.
Since these TODOs appear to be related to architectural improvements, could you provide more context on when and how these improvements will be implemented? You might want to create tracked issues for these improvements to ensure they're not forgotten.
Also applies to: 144-144
48-163: Well-implemented code generation for API checksThe
ApiCheckCodegenclass thoroughly handles all aspects of API check configuration with proper conditional handling of optional properties. The use of the builder pattern ensures clean code generation.
1-7: Well-organized importsThe imports are properly structured, importing only what's needed from the relevant modules.
packages/cli/src/constructs/private-location-codegen.ts (5)
1-3: Imports follow the project's module structureThe imports correctly reference internal modules for code generation utilities, showing good organization.
12-12: Good use of constant for construct nameUsing a constant for the construct name avoids string duplication and enables easier refactoring.
14-23: Well-structured utility function for generating PrivateLocation referencesThe function properly:
- Adds the necessary import
- Returns an expression that creates a reference to an existing PrivateLocation by ID
This will be useful when linking resources that reference private locations.
25-29: Codegen class extends base class with proper type parameterThe
preparemethod correctly registers the private location ID in the context for later reference, following the pattern established in other codegen classes.
1-58:❓ Verification inconclusive
Overall implementation fits well in the import command architecture
This code generator follows the established patterns for other resource types, maintaining consistency with the rest of the codebase. It will allow users to import their existing private locations as part of the new CLI import command.
Consider implementing tests for this code generator to ensure it produces the expected output for various input configurations.
🏁 Script executed:
#!/bin/bash # Look for tests of similar codegen classes to understand test patterns echo "Searching for existing codegen test files..." fd -e ts test.*codegen packages/cli/srcLength of output: 142
Attention: Consistency and Test Coverage Verification
The implementation is consistent with established patterns for CLI import commands. However, the codebase does not currently include tests for similar code generation classes (as indicated by the absence of matching test files in the search). To ensure ongoing reliability and correctness, please implement tests for this code generator that validate its output for various input configurations.
- File Impacted:
packages/cli/src/constructs/private-location-codegen.ts- Recommendation: Add tests modeled on testing patterns from similar features or resource types to cover edge cases and generated output.
packages/cli/src/constructs/check-group-codegen.ts (3)
13-27: Solid introduction of new resource interfaces.The interfaces
BrowserCheckConfigResource,MultiStepCheckConfigResource, andCheckGroupResourcecomprehensively capture the properties needed for check group configurations, leveraging typed fields to ensure clarity in usage.
28-33:doubleCheckandconcurrencyremain unused in the code generation.Despite being defined in the
CheckGroupResource, these properties are never set inbuildCheckGroupProps. This can lead to incomplete code generation.As a follow-up, apply this diff in
buildCheckGroupPropsto include these properties:+ if (resource.doubleCheck !== undefined) { + builder.boolean('doubleCheck', resource.doubleCheck) + } + if (resource.concurrency !== undefined) { + builder.number('concurrency', resource.concurrency) + }
75-79: Emptycatchblocks swallow potential errors silently.In both the
lookupCheckGroupPrivateLocationsandlookupCheckGroupAlertChannelscalls, any lookup errors are caught and ignored. This behavior might make diagnosing errors more difficult, as issues could fail silently.Could you confirm if this is intentional? If not, consider logging or handling these errors more explicitly to surface potential problems.
Also applies to: 116-121
packages/cli/src/constructs/slack-alert-channel-codegen.ts (1)
1-47: Implementation looks good with a well-structured code generation pattern.The code follows a clean pattern for generating Slack alert channel code. The interface properly extends
AlertChannelResource, and the code generation logic correctly handles both required and optional properties.packages/cli/src/constructs/sms-alert-channel-codegen.ts (1)
15-47: Overall implementation follows the standard alert channel code generation pattern.The code is well-structured with proper separation of preparation and code generation phases. The conditional property handling for the optional name property is implemented correctly.
packages/cli/src/constructs/msteams-alert-channel-codegen.ts (2)
6-10: Clean extension of WebhookAlertChannelResource for MS Teams.The interface properly constrains the webhook type to 'WEBHOOK_MSTEAMS', ensuring type safety for MS Teams alert channels.
14-42: Well-structured code generation for MS Teams alert channel.The implementation follows the standard pattern and properly generates the MS Teams alert channel code with the required properties.
packages/cli/src/constructs/opsgenie-alert-channel-codegen.ts (3)
5-13: Comprehensive config properties for Opsgenie integration.The interface properly defines all required properties for Opsgenie integration including name, apiKey, region, and priority.
33-40: All Opsgenie properties correctly mapped in the generated code.The implementation properly maps all the configuration properties needed for the Opsgenie alert channel.
17-47: Overall implementation follows consistent alert channel pattern.The class implements the standard alert channel code generation pattern with proper preparation and code generation phases.
packages/cli/src/constructs/pagerduty-alert-channel-codegen.ts (2)
5-12: Interface definition looks sound.The optional fields and required
serviceKeyproperty are appropriately declared, and their types appear correct.
21-50: Ensure test coverage for new alert channel code generation.While the logic here is straightforward, consider adding or verifying tests to ensure that
gencodecorrectly generates aPagerdutyAlertChannelwith various valid and edge-case input configurations.packages/cli/src/constructs/incidentio-alert-channel-codegen.ts (2)
13-25: API key extraction logic appears correct.This function cleanly filters headers and extracts the Bearer token. It should work well for the intended use case.
47-47: Redundant.toString()call onconfig.url.
15ca798 to
2c43245
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 4
♻️ Duplicate comments (1)
packages/cli/src/commands/import/apply.ts (1)
77-83:⚠️ Potential issueHandle prompt cancellation scenarios
The current implementation doesn't account for what happens if the user cancels the prompt (by pressing Esc). In such cases,
planIdwould beundefinedand execution would proceed with a potential error.const { planId } = await prompts({ name: 'planId', type: 'select', message: `Found ${plans.length} unapplied plan(s). Which one to apply?`, choices, + onCancel: () => { + this.log('Operation cancelled by user') + this.exit(0) + return false + } }) + if (planId === undefined) { + this.log('Operation cancelled') + this.exit(0) + }
🧹 Nitpick comments (32)
packages/cli/src/commands/import/apply.ts (1)
47-59: Add error handling for empty unapplied plans listThe code doesn't handle the case where
unappliedPlansis empty (but not encountering the existing code path for zero length). Consider adding error handling for this scenario.const { data: unappliedPlans } = await api.projects.findImportPlans(logicalId, { onlyUnapplied: true, }) + if (unappliedPlans.length === 0) { + this.log('No unapplied plans found. Please create a plan first using `checkly import plan`') + this.exit(0) + } const plan = await this.#selectPlan(unappliedPlans) if (this.fancy) { ux.action.start('Applying plan') }packages/cli/src/constructs/slack-alert-channel-codegen.ts (1)
32-37: Add type checking for channel property before usageWhile the code correctly checks if the channel property exists before using it, there's no validation that the channel is a non-empty string. This could lead to unexpected behavior if the channel is provided but is an empty string.
if (config.channel) { + // Ensure channel is a non-empty string + if (typeof config.channel === 'string' && config.channel.trim() !== '') { builder.string('channel', config.channel) + } }packages/cli/src/commands/import/plan.ts (3)
97-105: Avoid type assertions with 'any'Using
as anytype assertions can lead to type safety issues and potential runtime errors. Consider defining proper types for the resources.- sortResources(plan.changes.resources as any) + // Define a proper type or interface for resources + interface ResourceWithLogicalId { + logicalId: string; + [key: string]: any; + } + sortResources(plan.changes.resources as ResourceWithLogicalId[]) for (const resource of plan.changes.resources) { - codegen.prepare(resource.logicalId, resource as any, context) + codegen.prepare(resource.logicalId, resource as ResourceWithLogicalId, context) } for (const resource of plan.changes.resources) { - codegen.gencode(resource.logicalId, resource as any, context) + codegen.gencode(resource.logicalId, resource as ResourceWithLogicalId, context) }
115-116: Address the TODO comment about file structureThere's a pending TODO comment about file structure, but the code directly writes to
./generated.check.ts. Consider implementing a more flexible file structure or removing the TODO if the current approach is intentional.- // TODO: file structure - const filename = './generated.check.ts' + // Generate output with a structured path based on config + const filename = `${configDirectory}/generated.check.ts`
130-223: Add prompt cancellation handling in #handleExistingPlansSimilar to the issue in the apply command, this method doesn't handle the case where the user cancels the prompt using Esc key, which would leave
actionas undefined.Add appropriate cancellation handlers to the prompts:
const { action } = await prompts({ name: 'action', type: 'select', message: `Found ${plans.length} existing uncommitted plan(s). How do you want to proceed?`, choices, + onCancel: () => { + this.log('Operation cancelled by user') + this.exit(0) + return false + } }) + if (action === undefined) { + this.log('Operation cancelled') + this.exit(0) + return + }Apply similar changes to the second prompt at line 172.
packages/cli/src/constructs/api-check-codegen.ts (1)
48-163: Potential improvement for script handling.
Whilegencodeproperly accounts for local vs. snippet scripts, the logic is fairly dense. Consider extracting repeated script-building logic into helper methods for maintainability.packages/cli/src/constructs/sms-alert-channel-codegen.ts (1)
20-45: Export logic is neatly implemented.
gencodecomposes theSmsAlertChannelobject with extra props frombuildAlertChannelProps. Consider input validation for the phone number if the constructor is user-facing.packages/cli/src/constructs/status-page-codegen.ts (2)
6-10: Consider adding JSDoc comments for clarity.
Interfaces are essential for readability and maintainability. Adding brief JSDoc comments describing each field—especially arrays likeservices—helps provide context for future contributors.
37-53: Improve error messaging when referencing missing services.
Currently, the error message'Status page refers to a service that is not being imported.'does not specify which service ID caused the issue. Including the missingservice.idin the message can expedite debugging.- throw new Error('Status page refers to a service that is not being imported.') + throw new Error(`Status page refers to a missing service with ID: ${service.id}`)packages/cli/src/sourcegen/declbuilder.ts (4)
5-9: Ensure type checks for builder functions.
Thedeclfunction relies on the user-provided builder to modify state. Consider enforcing type checks or error handling to prevent misuse in more complex scenarios.
15-18: Add JSDoc or docstring for the constructor.
Providing a docstring explaining the purpose of#identifierand#declwill help maintainers follow your logic more easily.
20-23: Consider allowing multiple variable declarations.
If future enhancements require multiple variables within the same builder, you might refactor to handle an array of variables or a chainable approach, instead of replacing the current declaration.
25-28: Optional: Provide anunexportor revert mechanism.
Once you applyexport(), there’s no way to revert. If a future codegen scenario requires toggling export state, consider adding anunexport()method or keeping track of prior states.packages/cli/src/constructs/msteams-alert-channel-codegen.ts (1)
19-41: Ensure the CLI usage is documented.
This generation logic looks correct for producing an MSTeams alert channel resource. However, confirm that end-users know how to specifywebhookType: 'WEBHOOK_MSTEAMS'in the CLI or config file.packages/cli/src/constructs/phone-call-alert-channel-codegen.ts (2)
5-11: Clarify thetype: 'CALL'usage.
Explicitly documenting what'CALL'signifies (e.g., phone calls, including acceptable country codes) ensures new contributors can quickly adopt or extend this resource type.
20-45: Confirm phone number format validation.
Although the code setsphoneNumber, consider validating or normalizing the phone string. If the code is used in production, it might need to handle user input robustly.packages/cli/src/constructs/check-codegen.ts (2)
70-85: Consider adding error logging in empty catch blocks.The empty catch block silently ignores any errors that occur during the lookup of private locations. While it appears to be intentional based on the following conditional logic, adding a debug log could help with troubleshooting.
try { return context.lookupCheckPrivateLocations(resource.id) } catch (err) { + // Silently continue if no private locations found for this check }
121-126: Consider adding error logging in empty catch blocks.Similar to the previous comment, the empty catch block silently ignores any errors during alert channel lookup. While this appears to be intentional based on the following conditional logic, adding a debug log could help with troubleshooting.
try { return context.lookupCheckAlertChannels(resource.id) } catch (err) { + // Silently continue if no alert channels found for this check }packages/cli/src/sourcegen/exprbuilder.ts (1)
11-42: Consider renaming thenewmethod to avoid confusion.Naming a method as
newmight be confusing given that it clashes with thenewkeyword in JavaScript/TypeScript. A more explicit name such asnewExpressionorcreateNewcan improve clarity and maintainability.Here's a sample diff to rename and update references:
- new (build: (builder: ArgumentsValueBuilder) => void): this { + newExpression(build: (builder: ArgumentsValueBuilder) => void): this { const builder = new ArgumentsValueBuilder() build(builder) return this.context(new NewExpressionValue(this.#context, builder.build())) }packages/cli/src/rest/projects.ts (1)
94-101: Possible need for pagination onlistImportPlans.
If the number of import plans grows large, consider supporting server-side pagination or other limiting mechanisms.packages/cli/src/constructs/check-group-codegen.ts (1)
45-237:buildCheckGroupPropsis large but logical.
All relevant fields (frequency, tags, environment variables, etc.) are handled in a systematic manner. Consider modularizing some sections if the function grows further.packages/cli/src/constructs/alert-channel-codegen.ts (1)
12-19: Consider using an enum for alert channel types.
DefiningAlertChannelTypeas a string-literal union is perfectly valid. However, using a TypeScript enum can enhance readability and minimize string typos.packages/cli/src/constructs/webhook-alert-channel-codegen.ts (1)
43-43: Redundant call to.toString().
Sinceconfig.urlis already typed asstring,toString()is unnecessary. You can safely remove it for clarity.- builder.string('url', config.url.toString()) + builder.string('url', config.url)packages/cli/src/sourcegen/argsbuilder.ts (4)
19-22: Avoid potential confusion with the comment.
The comment "Avoid extending ArrayValueBuilder due to circular dependencies" is helpful but could be expanded. Consider briefly explaining the reason, e.g., which modules or references would cause the cycle, to guide future maintainers.
23-26: Consider clarifying the purpose ofempty().
Theempty()method reinitializes#elements. It might be beneficial to clarify its intended usage in comments or docs, particularly if chained with other methods.
52-54: Consider advanced validation for nested builders.
Forarray,object, andexprcalls, it may be beneficial to validate the resulting objects or expressions if misuse is possible. Currently, there's no defense if the build callback is malformed. Might be acceptable given expected usage.Also applies to: 56-58, 60-62
64-67: Method naming clarity.
The methodvalueis direct and works well, but a more explicit name such aspushValueoraddValuecould be more descriptive of its operation. This is optional but might improve readability.packages/cli/src/sourcegen/objectbuilder.ts (3)
12-16: Add usage guidance for theobjectfunction.
This top-level function is a convenient entry point for creating object values. For clarity, consider adding a short doc comment to explain its purpose and typical usage, similar to theargsfunction pattern.
18-21: Optional: clarify object building options.
Storing#optionsis helpful for advanced rendering (e.g., sorting). Verifying that future expansions toObjectValueOptionsproperly integrate intoObjectValueBuilderwould be wise.
58-65: Expression property handling might need error context.
expr(name, context, build)raises no errors by default if something goes wrong inbuild. Consider capturing or testing potential errors since expressions can get complex.packages/cli/src/constructs/internal/codegen/context.ts (2)
3-4: Provide an error message inMissingContextVariableMappingError.
Consider including a descriptive message or the missing ID in the error. Right now, it throws a blank error, which might hinder debugging in large codebases.
5-138: Overall context management appears correct.
TheContextclass effectively manages mappings for various physical IDs. Eachregister*method sets up a new identifier or association, and eachlookup*method throws if the mapping doesn't exist. This is a straightforward and organized approach.
- Redundant registration checks: Re-registering the same ID doesn't appear to be disallowed, possibly causing unexpected overshadowing. Consider clarifying expected usage or adding checks.
- Custom error messages: As noted, referencing physical IDs in the thrown error can help with debugging.
- Future expansions: Because the approach is
Map-based, you might want to ensure cleaning or disposal steps if the context grows large, though that may be scenario-dependent.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (67)
packages/cli/e2e/__tests__/help.spec.ts(2 hunks)packages/cli/package.json(1 hunks)packages/cli/src/commands/import/apply.ts(1 hunks)packages/cli/src/commands/import/cancel.ts(1 hunks)packages/cli/src/commands/import/commit.ts(1 hunks)packages/cli/src/commands/import/plan.ts(1 hunks)packages/cli/src/constructs/alert-channel-codegen.ts(1 hunks)packages/cli/src/constructs/alert-channel-subscription-codegen.ts(1 hunks)packages/cli/src/constructs/alert-escalation-policy-codegen.ts(1 hunks)packages/cli/src/constructs/api-check-codegen.ts(1 hunks)packages/cli/src/constructs/browser-check-codegen.ts(1 hunks)packages/cli/src/constructs/check-codegen.ts(1 hunks)packages/cli/src/constructs/check-group-codegen.ts(1 hunks)packages/cli/src/constructs/check-group.ts(1 hunks)packages/cli/src/constructs/construct-codegen.ts(1 hunks)packages/cli/src/constructs/dashboard-codegen.ts(1 hunks)packages/cli/src/constructs/email-alert-channel-codegen.ts(1 hunks)packages/cli/src/constructs/frequency-codegen.ts(1 hunks)packages/cli/src/constructs/heartbeat-check-codegen.ts(1 hunks)packages/cli/src/constructs/incidentio-alert-channel-codegen.ts(1 hunks)packages/cli/src/constructs/internal/assertion-codegen.ts(1 hunks)packages/cli/src/constructs/internal/codegen/codegen.ts(1 hunks)packages/cli/src/constructs/internal/codegen/context.ts(1 hunks)packages/cli/src/constructs/internal/codegen/index.ts(1 hunks)packages/cli/src/constructs/key-value-pair-codegen.ts(1 hunks)packages/cli/src/constructs/maintenance-window-codegen.ts(1 hunks)packages/cli/src/constructs/msteams-alert-channel-codegen.ts(1 hunks)packages/cli/src/constructs/multi-step-check-codegen.ts(1 hunks)packages/cli/src/constructs/opsgenie-alert-channel-codegen.ts(1 hunks)packages/cli/src/constructs/pagerduty-alert-channel-codegen.ts(1 hunks)packages/cli/src/constructs/phone-call-alert-channel-codegen.ts(1 hunks)packages/cli/src/constructs/playwright-config-codegen.ts(1 hunks)packages/cli/src/constructs/playwright-config.ts(0 hunks)packages/cli/src/constructs/private-location-check-assignment-codegen.ts(1 hunks)packages/cli/src/constructs/private-location-codegen.ts(1 hunks)packages/cli/src/constructs/private-location-group-assignment-codegen.ts(1 hunks)packages/cli/src/constructs/ref-codegen.ts(1 hunks)packages/cli/src/constructs/retry-strategy-codegen.ts(1 hunks)packages/cli/src/constructs/slack-alert-channel-codegen.ts(1 hunks)packages/cli/src/constructs/sms-alert-channel-codegen.ts(1 hunks)packages/cli/src/constructs/status-page-codegen.ts(1 hunks)packages/cli/src/constructs/status-page-service-codegen.ts(1 hunks)packages/cli/src/constructs/tcp-check-codegen.ts(1 hunks)packages/cli/src/constructs/telegram-alert-channel-codegen.ts(1 hunks)packages/cli/src/constructs/webhook-alert-channel-codegen.ts(1 hunks)packages/cli/src/rest/projects.ts(3 hunks)packages/cli/src/sourcegen/args.ts(1 hunks)packages/cli/src/sourcegen/argsbuilder.ts(1 hunks)packages/cli/src/sourcegen/array.ts(1 hunks)packages/cli/src/sourcegen/arraybuilder.ts(1 hunks)packages/cli/src/sourcegen/boolean.ts(1 hunks)packages/cli/src/sourcegen/decl.ts(1 hunks)packages/cli/src/sourcegen/declbuilder.ts(1 hunks)packages/cli/src/sourcegen/expr.ts(1 hunks)packages/cli/src/sourcegen/exprbuilder.ts(1 hunks)packages/cli/src/sourcegen/identifier.ts(1 hunks)packages/cli/src/sourcegen/index.ts(1 hunks)packages/cli/src/sourcegen/null.ts(1 hunks)packages/cli/src/sourcegen/number.ts(1 hunks)packages/cli/src/sourcegen/object.ts(1 hunks)packages/cli/src/sourcegen/objectbuilder.ts(1 hunks)packages/cli/src/sourcegen/output.ts(1 hunks)packages/cli/src/sourcegen/program.ts(1 hunks)packages/cli/src/sourcegen/string.ts(1 hunks)packages/cli/src/sourcegen/undefined.ts(1 hunks)packages/cli/src/sourcegen/unknown.ts(1 hunks)packages/cli/src/sourcegen/value.ts(1 hunks)
💤 Files with no reviewable changes (1)
- packages/cli/src/constructs/playwright-config.ts
🚧 Files skipped from review as they are similar to previous changes (39)
- packages/cli/src/sourcegen/undefined.ts
- packages/cli/src/sourcegen/number.ts
- packages/cli/src/sourcegen/args.ts
- packages/cli/src/sourcegen/value.ts
- packages/cli/src/sourcegen/boolean.ts
- packages/cli/src/constructs/key-value-pair-codegen.ts
- packages/cli/src/sourcegen/null.ts
- packages/cli/src/commands/import/commit.ts
- packages/cli/package.json
- packages/cli/src/constructs/browser-check-codegen.ts
- packages/cli/src/constructs/ref-codegen.ts
- packages/cli/src/sourcegen/string.ts
- packages/cli/src/sourcegen/array.ts
- packages/cli/e2e/tests/help.spec.ts
- packages/cli/src/constructs/internal/codegen/codegen.ts
- packages/cli/src/constructs/multi-step-check-codegen.ts
- packages/cli/src/sourcegen/unknown.ts
- packages/cli/src/constructs/check-group.ts
- packages/cli/src/constructs/playwright-config-codegen.ts
- packages/cli/src/constructs/alert-escalation-policy-codegen.ts
- packages/cli/src/sourcegen/identifier.ts
- packages/cli/src/commands/import/cancel.ts
- packages/cli/src/sourcegen/program.ts
- packages/cli/src/sourcegen/output.ts
- packages/cli/src/constructs/frequency-codegen.ts
- packages/cli/src/constructs/telegram-alert-channel-codegen.ts
- packages/cli/src/constructs/private-location-check-assignment-codegen.ts
- packages/cli/src/constructs/dashboard-codegen.ts
- packages/cli/src/constructs/alert-channel-subscription-codegen.ts
- packages/cli/src/constructs/private-location-group-assignment-codegen.ts
- packages/cli/src/sourcegen/decl.ts
- packages/cli/src/constructs/heartbeat-check-codegen.ts
- packages/cli/src/constructs/internal/codegen/index.ts
- packages/cli/src/constructs/retry-strategy-codegen.ts
- packages/cli/src/constructs/maintenance-window-codegen.ts
- packages/cli/src/constructs/incidentio-alert-channel-codegen.ts
- packages/cli/src/constructs/email-alert-channel-codegen.ts
- packages/cli/src/sourcegen/object.ts
- packages/cli/src/sourcegen/expr.ts
🧰 Additional context used
🧬 Code Definitions (22)
packages/cli/src/constructs/sms-alert-channel-codegen.ts (3)
packages/cli/src/constructs/alert-channel-codegen.ts (2)
AlertChannelResource(21-29)buildAlertChannelProps(31-51)packages/cli/src/constructs/internal/codegen/index.ts (2)
Codegen(1-1)Context(2-2)packages/cli/src/constructs/internal/codegen/context.ts (1)
Context(5-138)
packages/cli/src/constructs/api-check-codegen.ts (5)
packages/cli/src/constructs/check-codegen.ts (2)
CheckResource(17-35)buildCheckProps(37-154)packages/cli/src/constructs/internal/assertion-codegen.ts (2)
valueForNumericAssertion(4-43)valueForGeneralAssertion(45-146)packages/cli/src/constructs/internal/codegen/index.ts (2)
Codegen(1-1)Context(2-2)packages/cli/src/constructs/internal/codegen/context.ts (1)
Context(5-138)packages/cli/src/constructs/key-value-pair-codegen.ts (1)
valueForKeyValuePair(4-17)
packages/cli/src/sourcegen/exprbuilder.ts (3)
packages/cli/src/sourcegen/index.ts (8)
expr(22-22)Value(33-33)ExpressionValueBuilder(22-22)ExpressionValue(15-15)ArgumentsValueBuilder(2-2)NewExpressionValue(16-16)CallExpressionValue(17-17)MemberExpressionValue(18-18)packages/cli/src/sourcegen/argsbuilder.ts (4)
expr(60-62)build(73-75)value(64-67)ArgumentsValueBuilder(20-76)packages/cli/src/sourcegen/expr.ts (3)
NewExpressionValue(8-24)CallExpressionValue(26-40)MemberExpressionValue(42-57)
packages/cli/src/constructs/check-codegen.ts (8)
packages/cli/src/constructs/frequency-codegen.ts (2)
FrequencyResource(4-4)valueForFrequency(6-54)packages/cli/src/constructs/retry-strategy-codegen.ts (2)
RetryStrategyResource(4-4)valueForRetryStrategy(6-77)packages/cli/src/constructs/internal/codegen/context.ts (1)
Context(5-138)packages/cli/src/constructs/internal/codegen/index.ts (2)
Context(2-2)Codegen(1-1)packages/cli/src/constructs/private-location-codegen.ts (1)
valueForPrivateLocationFromId(14-23)packages/cli/src/constructs/key-value-pair-codegen.ts (1)
valueForKeyValuePair(4-17)packages/cli/src/constructs/alert-channel-codegen.ts (1)
valueForAlertChannelFromId(55-64)packages/cli/src/constructs/api-check-codegen.ts (2)
ApiCheckCodegen(48-163)ApiCheckResource(14-25)
packages/cli/src/constructs/status-page-service-codegen.ts (1)
packages/cli/src/constructs/internal/codegen/context.ts (1)
Context(5-138)
packages/cli/src/constructs/tcp-check-codegen.ts (5)
packages/cli/src/constructs/check-codegen.ts (2)
CheckResource(17-35)buildCheckProps(37-154)packages/cli/src/sourcegen/program.ts (1)
Program(7-53)packages/cli/src/constructs/internal/assertion-codegen.ts (2)
valueForGeneralAssertion(45-146)valueForNumericAssertion(4-43)packages/cli/src/constructs/internal/codegen/index.ts (2)
Codegen(1-1)Context(2-2)packages/cli/src/constructs/internal/codegen/context.ts (1)
Context(5-138)
packages/cli/src/constructs/slack-alert-channel-codegen.ts (2)
packages/cli/src/constructs/alert-channel-codegen.ts (2)
AlertChannelResource(21-29)buildAlertChannelProps(31-51)packages/cli/src/constructs/internal/codegen/context.ts (1)
Context(5-138)
packages/cli/src/constructs/phone-call-alert-channel-codegen.ts (3)
packages/cli/src/constructs/alert-channel-codegen.ts (2)
AlertChannelResource(21-29)buildAlertChannelProps(31-51)packages/cli/src/constructs/internal/codegen/index.ts (2)
Codegen(1-1)Context(2-2)packages/cli/src/constructs/internal/codegen/context.ts (1)
Context(5-138)
packages/cli/src/constructs/alert-channel-codegen.ts (8)
packages/cli/src/constructs/internal/codegen/index.ts (2)
Codegen(1-1)Context(2-2)packages/cli/src/constructs/phone-call-alert-channel-codegen.ts (1)
PhoneCallAlertChannelCodegen(15-46)packages/cli/src/constructs/email-alert-channel-codegen.ts (1)
EmailAlertChannelCodegen(14-39)packages/cli/src/constructs/opsgenie-alert-channel-codegen.ts (1)
OpsgenieAlertChannelCodegen(17-47)packages/cli/src/constructs/pagerduty-alert-channel-codegen.ts (1)
PagerdutyAlertChannelCodegen(16-51)packages/cli/src/constructs/slack-alert-channel-codegen.ts (1)
SlackAlertChannelCodegen(15-46)packages/cli/src/constructs/sms-alert-channel-codegen.ts (1)
SmsAlertChannelCodegen(15-46)packages/cli/src/constructs/webhook-alert-channel-codegen.ts (1)
WebhookAlertChannelCodegen(78-138)
packages/cli/src/constructs/check-group-codegen.ts (8)
packages/cli/src/constructs/frequency-codegen.ts (2)
FrequencyResource(4-4)valueForFrequency(6-54)packages/cli/src/constructs/alert-escalation-policy-codegen.ts (2)
AlertEscalationResource(4-4)valueForAlertEscalation(6-65)packages/cli/src/constructs/retry-strategy-codegen.ts (2)
RetryStrategyResource(4-4)valueForRetryStrategy(6-77)packages/cli/src/constructs/internal/codegen/index.ts (2)
Context(2-2)Codegen(1-1)packages/cli/src/constructs/private-location-codegen.ts (1)
valueForPrivateLocationFromId(14-23)packages/cli/src/constructs/key-value-pair-codegen.ts (1)
valueForKeyValuePair(4-17)packages/cli/src/constructs/alert-channel-codegen.ts (1)
valueForAlertChannelFromId(55-64)packages/cli/src/constructs/api-check-codegen.ts (1)
valueForAssertion(27-44)
packages/cli/src/sourcegen/declbuilder.ts (2)
packages/cli/src/sourcegen/index.ts (6)
decl(11-11)IdentifierValue(23-23)DeclarationBuilder(12-12)Value(33-33)VariableDeclaration(7-7)ExportDeclaration(8-8)packages/cli/src/sourcegen/decl.ts (4)
IdentifierDeclaration(9-20)VariableDeclarationOptions(22-24)VariableDeclaration(26-51)ExportDeclaration(53-65)
packages/cli/src/constructs/opsgenie-alert-channel-codegen.ts (2)
packages/cli/src/constructs/alert-channel-codegen.ts (2)
AlertChannelResource(21-29)buildAlertChannelProps(31-51)packages/cli/src/constructs/internal/codegen/context.ts (1)
Context(5-138)
packages/cli/src/commands/import/plan.ts (4)
packages/cli/src/rest/projects.ts (1)
ImportPlan(43-49)packages/cli/src/sourcegen/index.ts (2)
Program(29-29)Output(28-28)packages/cli/src/constructs/construct-codegen.ts (2)
ConstructCodegen(57-117)sortResources(49-55)packages/cli/src/constructs/internal/codegen/context.ts (1)
Context(5-138)
packages/cli/src/constructs/webhook-alert-channel-codegen.ts (7)
packages/cli/src/constructs/alert-channel-codegen.ts (2)
AlertChannelResource(21-29)buildAlertChannelProps(31-51)packages/cli/src/constructs/key-value-pair-codegen.ts (1)
valueForKeyValuePair(4-17)packages/cli/src/constructs/internal/codegen/index.ts (2)
Codegen(1-1)Context(2-2)packages/cli/src/constructs/incidentio-alert-channel-codegen.ts (1)
IncidentioAlertChannelCodegen(29-64)packages/cli/src/constructs/msteams-alert-channel-codegen.ts (1)
MSTeamsAlertChannelCodegen(14-42)packages/cli/src/constructs/telegram-alert-channel-codegen.ts (1)
TelegramAlertChannelCodegen(28-69)packages/cli/src/constructs/internal/codegen/context.ts (1)
Context(5-138)
packages/cli/src/constructs/pagerduty-alert-channel-codegen.ts (2)
packages/cli/src/constructs/alert-channel-codegen.ts (2)
AlertChannelResource(21-29)buildAlertChannelProps(31-51)packages/cli/src/constructs/internal/codegen/context.ts (1)
Context(5-138)
packages/cli/src/constructs/private-location-codegen.ts (3)
packages/cli/src/sourcegen/program.ts (1)
Program(7-53)packages/cli/src/constructs/internal/codegen/index.ts (2)
Codegen(1-1)Context(2-2)packages/cli/src/constructs/internal/codegen/context.ts (1)
Context(5-138)
packages/cli/src/sourcegen/arraybuilder.ts (7)
packages/cli/src/sourcegen/array.ts (1)
ArrayValue(4-31)packages/cli/src/sourcegen/string.ts (1)
StringValue(6-17)packages/cli/src/sourcegen/boolean.ts (1)
BooleanValue(4-15)packages/cli/src/sourcegen/number.ts (1)
NumberValue(4-15)packages/cli/src/sourcegen/null.ts (1)
NullValue(4-8)packages/cli/src/sourcegen/undefined.ts (1)
UndefinedValue(4-8)packages/cli/src/sourcegen/identifier.ts (1)
IdentifierValue(4-15)
packages/cli/src/constructs/construct-codegen.ts (14)
packages/cli/src/constructs/internal/codegen/index.ts (2)
Codegen(1-1)Context(2-2)packages/cli/src/constructs/alert-channel-codegen.ts (1)
AlertChannelCodegen(66-114)packages/cli/src/constructs/alert-channel-subscription-codegen.ts (1)
AlertChannelSubscriptionCodegen(9-24)packages/cli/src/constructs/check-codegen.ts (1)
CheckCodegen(156-192)packages/cli/src/constructs/check-group-codegen.ts (1)
CheckGroupCodegen(241-264)packages/cli/src/constructs/dashboard-codegen.ts (1)
DashboardCodegen(31-140)packages/cli/src/constructs/maintenance-window-codegen.ts (1)
MaintenanceWindowCodegen(16-64)packages/cli/src/constructs/private-location-codegen.ts (1)
PrivateLocationCodegen(25-57)packages/cli/src/constructs/private-location-check-assignment-codegen.ts (1)
PrivateLocationCheckAssignmentCodegen(8-17)packages/cli/src/constructs/private-location-group-assignment-codegen.ts (1)
PrivateLocationGroupAssignmentCodegen(8-17)packages/cli/src/constructs/status-page-codegen.ts (1)
StatusPageCodegen(26-78)packages/cli/src/constructs/status-page-service-codegen.ts (1)
StatusPageServiceCodegen(11-34)packages/cli/src/sourcegen/program.ts (1)
Program(7-53)packages/cli/src/constructs/internal/codegen/context.ts (1)
Context(5-138)
packages/cli/src/constructs/msteams-alert-channel-codegen.ts (4)
packages/cli/src/constructs/webhook-alert-channel-codegen.ts (2)
WebhookAlertChannelResource(28-31)WebhookAlertChannelResourceConfig(17-26)packages/cli/src/constructs/internal/codegen/index.ts (2)
Codegen(1-1)Context(2-2)packages/cli/src/constructs/internal/codegen/context.ts (1)
Context(5-138)packages/cli/src/constructs/alert-channel-codegen.ts (1)
buildAlertChannelProps(31-51)
packages/cli/src/sourcegen/objectbuilder.ts (9)
packages/cli/src/sourcegen/arraybuilder.ts (7)
object(54-56)build(71-73)value(62-65)ArrayValueBuilder(18-74)array(12-16)array(50-52)expr(58-60)packages/cli/src/sourcegen/exprbuilder.ts (4)
build(39-41)context(34-37)ExpressionValueBuilder(11-42)expr(5-9)packages/cli/src/sourcegen/object.ts (3)
ObjectValueOptions(22-24)ObjectProperty(8-18)ObjectValue(58-88)packages/cli/src/sourcegen/string.ts (1)
StringValue(6-17)packages/cli/src/sourcegen/boolean.ts (1)
BooleanValue(4-15)packages/cli/src/sourcegen/number.ts (1)
NumberValue(4-15)packages/cli/src/sourcegen/null.ts (1)
NullValue(4-8)packages/cli/src/sourcegen/undefined.ts (1)
UndefinedValue(4-8)packages/cli/src/sourcegen/identifier.ts (1)
IdentifierValue(4-15)
packages/cli/src/constructs/internal/codegen/context.ts (1)
packages/cli/src/constructs/internal/codegen/index.ts (2)
MissingContextVariableMappingError(2-2)Context(2-2)
packages/cli/src/sourcegen/argsbuilder.ts (2)
packages/cli/src/sourcegen/exprbuilder.ts (4)
build(39-41)context(34-37)ExpressionValueBuilder(11-42)expr(5-9)packages/cli/src/sourcegen/args.ts (1)
ArgumentsValue(4-27)
🪛 Biome (1.9.4)
packages/cli/src/constructs/check-codegen.ts
[error] 179-179: The function should not return a value because its return type is void.
The function is here:
'void' signals the absence of value. The returned value is likely to be ignored by the caller.
(lint/correctness/noVoidTypeReturn)
[error] 181-181: The function should not return a value because its return type is void.
The function is here:
'void' signals the absence of value. The returned value is likely to be ignored by the caller.
(lint/correctness/noVoidTypeReturn)
[error] 183-183: The function should not return a value because its return type is void.
The function is here:
'void' signals the absence of value. The returned value is likely to be ignored by the caller.
(lint/correctness/noVoidTypeReturn)
[error] 185-185: The function should not return a value because its return type is void.
The function is here:
'void' signals the absence of value. The returned value is likely to be ignored by the caller.
(lint/correctness/noVoidTypeReturn)
[error] 187-187: The function should not return a value because its return type is void.
The function is here:
'void' signals the absence of value. The returned value is likely to be ignored by the caller.
(lint/correctness/noVoidTypeReturn)
⏰ Context from checks skipped due to timeout of 90000ms (1)
- GitHub Check: test - windows-latest
🔇 Additional comments (69)
packages/cli/src/constructs/internal/assertion-codegen.ts (2)
4-43: Convert string to number with Number() instead of parseInt()The
valueForNumericAssertionfunction usesparseInt(assertion.target, 10)for numeric conversions, which may cause precision issues with floating-point values. UsingNumber(assertion.target)would be more appropriate.case 'EQUALS': builder.member(ident('equals')) builder.call(builder => { - builder.number(parseInt(assertion.target, 10)) + builder.number(Number(assertion.target)) }) breakApply the same change to all other cases in this function (lines 24, 30, and 36).
106-117: Handle numeric comparison types correctly in general assertionsThe
valueForGeneralAssertionfunction handlesLESS_THANandGREATER_THANcomparisons as string comparisons, which may produce unexpected results when comparing numeric values.case 'LESS_THAN': builder.member(ident('lessThan')) builder.call(builder => { - builder.string(assertion.target) + // Try to determine if target should be treated as a number + const numValue = Number(assertion.target) + if (!isNaN(numValue)) { + builder.number(numValue) + } else { + builder.string(assertion.target) + } }) breakApply the same approach to the
GREATER_THANcase below.packages/cli/src/constructs/slack-alert-channel-codegen.ts (2)
5-11: LGTM - SlackAlertChannelResource interface is well definedThe interface extends AlertChannelResource properly and clearly defines the expected structure for Slack alert channel configurations, with appropriate type specification and optional fields.
16-18: LGTM - Alert channel registration is well implementedThe prepare method correctly registers the alert channel using a consistent naming convention with the resource ID.
packages/cli/src/commands/import/plan.ts (1)
18-28: Add unit tests for ImportPlanCommandBased on past review comments, there are no unit tests for handling existing import plans. Please add tests to verify the user flow and ensure all code paths are covered.
#!/bin/bash # Check for existing tests for ImportPlanCommand find packages/cli/tests -type f -name "*.ts" -o -name "*.js" | xargs grep -l "ImportPlanCommand" # Find test patterns in the codebase find packages/cli/tests -type f -name "*.ts" -o -name "*.js" | xargs grep -l "Command.*test"packages/cli/src/constructs/tcp-check-codegen.ts (4)
1-6: Imports and baseline setup look good.
The new imports are consistent with other codegen references, ensuring the necessary modules are brought into scope.
7-12: Consider clarifying thecheckTypederivation.
While hardcoding'TCP'in the interface ensures consistency, verify that it's correctly set throughout the codebase and that no dynamic assignment is needed.
14-25: Well-structured assertion mapping.
valueForTcpAssertionproperly delegates to existing numeric and general assertion builders. This approach is consistent and concise.
29-73: Confirm behavior for empty or undefined request fields.
TcpCheckCodegenmethodgencoderelies onresource.requesthaving valid fields. Consider verifying or guarding against emptyhostnameorport.Would you like a quick check or script to scan usage sites and confirm that
requestis always defined?packages/cli/src/constructs/api-check-codegen.ts (3)
8-12:SnippetResourceinterface is neatly defined.
This structure is straightforward and readable. No issues found.
14-25: Interface structure aligns with existing check patterns.
ApiCheckResourceextendsCheckResourcecleanly, incorporating optional scripts and thresholds.
27-44: Comprehensive assertion coverage.
valueForAssertionhandles multiple sources correctly, including status codes, headers, JSON body, etc. and throws for unsupported.packages/cli/src/constructs/sms-alert-channel-codegen.ts (2)
5-11: SMS configuration is straightforward.
Properties are minimal and typed. Make surenumberis always a valid phone number string.
15-19: Context registration aligns with other alert channels.
prepareeffectively ties the alert channel ID to the context. No immediate concerns.packages/cli/src/constructs/status-page-codegen.ts (1)
55-73:❓ Verification inconclusive
Verify theme applicability.
ThedefaultThemeproperty is conditionally added but not validated or used elsewhere. Confirm whether additional logic is required to properly set themes in the generated code or if the property alone suffices.
🏁 Script executed:
#!/bin/bash # Searching for usage references to 'defaultTheme' to confirm it is properly handled. rg -A 5 "defaultTheme"Length of output: 2535
Attention: Verify proper handling of
defaultTheme.
The code inpackages/cli/src/constructs/status-page-codegen.tsconditionally addsdefaultThemeusingbuilder.string('defaultTheme', resource.defaultTheme), and the property is subsequently assigned and forwarded inpackages/cli/src/constructs/status-page.ts. TypeScript ensures that only values of typeStatusPageThemeare allowed, but no additional runtime validation is performed. Please confirm whether this behavior is intentional—that is, if basic type-checking is sufficient—or if additional validation or transformation logic is needed to ensure that the generated theme configuration is correct.
- Location:
packages/cli/src/constructs/status-page-codegen.ts(conditional addition ofdefaultTheme)- Location:
packages/cli/src/constructs/status-page.ts(assignment and propagation in synthesis)packages/cli/src/sourcegen/declbuilder.ts (1)
30-32:build()method is well-structured.
This straightforward design keeps the builder logic clean and final. No issues found here.packages/cli/src/constructs/msteams-alert-channel-codegen.ts (2)
15-17: Great use ofpreparefor registration.
This method properly registers the alert channel. A straightforward approach that improves the maintainability and organization of the code.
6-10:✅ Verification successful
Align naming conventions with other alert channels.
Confirm that thewebhookType: 'WEBHOOK_MSTEAMS'naming and field structure are consistent with similarly implemented alert channels (e.g., Slack). This helps maintain uniformity in the codebase.
🏁 Script executed:
#!/bin/bash # Searching for other alert channels with 'webhookType' rg -A 5 "webhookType"Length of output: 9313
Naming Conventions are Consistent Across Alert Channels
TheMSTeamsAlertChannelResourceinterface’s configuration ofwebhookType: 'WEBHOOK_MSTEAMS'follows the same pattern as seen in the incident.io (WEBHOOK_INCIDENTIO) and Telegram (WEBHOOK_TELEGRAM) implementations. This uniform naming via theWEBHOOK_prefix ensures consistency across alert channels. No changes are required here.packages/cli/src/constructs/phone-call-alert-channel-codegen.ts (1)
15-18: Good approach to generating phone call alert identifiers.
Thepreparemethod effectively differentiates phone alert channels by registering them with'phoneCallAlert'.packages/cli/src/constructs/check-codegen.ts (3)
17-35: Good interface design for CheckResource.The CheckResource interface is well-structured with clear property definitions. The optional properties are appropriately marked, making it easy for consumers to understand what's required and what's optional.
112-119: Good error handling for missing check groups.The error message clearly communicates the issue when a check references a group that's not part of the import, which will help users understand what's missing and how to fix it.
174-191: Remove "return" statements in a void function.Static analysis indicates returning from a function with return type
voidis unnecessary. Instead of returning the sub-codegen calls, simply invoke them and break out of the switch.gencode (logicalId: string, resource: CheckResource, context: Context): void { const { checkType } = resource switch (checkType) { case 'BROWSER': - return this.browserCheckCodegen.gencode(logicalId, resource as BrowserCheckResource, context) + this.browserCheckCodegen.gencode(logicalId, resource as BrowserCheckResource, context) + break case 'API': - return this.apiCheckCodegen.gencode(logicalId, resource as ApiCheckResource, context) + this.apiCheckCodegen.gencode(logicalId, resource as ApiCheckResource, context) + break case 'TCP': - return this.tcpCheckCodegen.gencode(logicalId, resource as TcpCheckResource, context) + this.tcpCheckCodegen.gencode(logicalId, resource as TcpCheckResource, context) + break case 'MULTI_STEP': - return this.multiStepCheckCodegen.gencode(logicalId, resource as MultiStepCheckResource, context) + this.multiStepCheckCodegen.gencode(logicalId, resource as MultiStepCheckResource, context) + break case 'HEARTBEAT': - return this.heartbeatCheckCodegen.gencode(logicalId, resource as HeartbeatCheckResource, context) + this.heartbeatCheckCodegen.gencode(logicalId, resource as HeartbeatCheckResource, context) + break default: throw new Error(`Unable to generate code for unsupported check type '${checkType}'.`) } }🧰 Tools
🪛 Biome (1.9.4)
[error] 179-179: The function should not return a value because its return type is void.
The function is here:
'void' signals the absence of value. The returned value is likely to be ignored by the caller.
(lint/correctness/noVoidTypeReturn)
[error] 181-181: The function should not return a value because its return type is void.
The function is here:
'void' signals the absence of value. The returned value is likely to be ignored by the caller.
(lint/correctness/noVoidTypeReturn)
[error] 183-183: The function should not return a value because its return type is void.
The function is here:
'void' signals the absence of value. The returned value is likely to be ignored by the caller.
(lint/correctness/noVoidTypeReturn)
[error] 185-185: The function should not return a value because its return type is void.
The function is here:
'void' signals the absence of value. The returned value is likely to be ignored by the caller.
(lint/correctness/noVoidTypeReturn)
[error] 187-187: The function should not return a value because its return type is void.
The function is here:
'void' signals the absence of value. The returned value is likely to be ignored by the caller.
(lint/correctness/noVoidTypeReturn)
packages/cli/src/constructs/opsgenie-alert-channel-codegen.ts (3)
5-13: Good interface design for OpsgenieAlertChannelResource.The interface properly extends AlertChannelResource and defines the Opsgenie-specific configuration with appropriate required properties.
17-20: Well-implemented preparation method.The prepare method correctly registers the alert channel with a descriptive prefix that will help identify the variable in the generated code.
22-46: Clean and consistent gencode implementation.The gencode method follows a good pattern for code generation:
- Importing necessary constructs
- Looking up the registered alert channel
- Destructuring the config object
- Building and exporting the code section with proper configuration
This implementation aligns well with other alert channel codegen classes.
packages/cli/src/constructs/pagerduty-alert-channel-codegen.ts (3)
5-12: Good interface design with appropriate optional properties.The interface correctly extends AlertChannelResource and properly marks account and serviceName as optional while keeping serviceKey required.
33-39: Well-handled optional properties.The code correctly checks for the existence of optional properties before adding them to the builder, ensuring clean generated code without undefined values.
16-51: Consistent implementation with other alert channel codegens.The implementation follows the same pattern as other alert channel codegen classes, maintaining consistency across the codebase which improves maintainability.
packages/cli/src/constructs/status-page-service-codegen.ts (2)
4-7: Simple and clear resource interface.The StatusPageServiceResource interface is concise with just the essential properties needed.
11-34: Clean implementation of the codegen class.The StatusPageServiceCodegen follows the established pattern for code generation, with proper integration with the Context system for registration and lookup.
packages/cli/src/sourcegen/exprbuilder.ts (2)
1-3: Imports usage approved.All imported entities appear to be referenced correctly in the code below. No issues found in these import statements.
5-9: Builder approach is clear and concise.The
exprfunction neatly encapsulates creation of an expression builder. No major concerns here.packages/cli/src/sourcegen/index.ts (1)
1-34: Export entries are consistent.All exports cleanly re-export the necessary classes and helpers. Nothing problematic here.
packages/cli/src/constructs/construct-codegen.ts (6)
1-14: Import statements look good.No issues with the imported modules; they are all used appropriately later in the code.
16-27: ResourceType union is well-defined.The union type clearly enumerates all recognized resource types. Looks good.
29-33: Resource interface is straightforward.This simple interface for
Resourceis clear and effective. No improvements needed.
35-47: Confirm the ordering logic.The
resourceOrderobject assigns a higher numeric value for resources that appear earlier when sorted, given the descending sort logic. Verify that this is the intended priority/design (i.e., higher numeric values come first).
49-55: Descending sort verification.Because the sort function subtracts
aofrombo, resources with higher numeric values will appear first. Ensure this is the desired order of generation.
57-98: Aggregator constructor is well-structured.Constructors for each resource codegen are properly initialized and neatly stored in
codegensByType.packages/cli/src/rest/projects.ts (7)
39-41: Use ofResourceSync[]is straightforward.
No immediate issues spotted; the property nameresourcesis clear, and the type matches the existingResourceSyncinterface.
43-49: Consider typing date fields.
Currently,createdAt,appliedAt, andcommittedAtare typed asstring. If these values always represent ISO date/time strings or timestamps from the backend, you might consider usingDateobjects or clarifying that these are strictly ISO strings for improved type safety.
81-83:createImportPlanmethod looks good.
The POST call and endpoint path appear consistent.
85-92:findImportPlansmethod appears correct.
Filtering via query parameters is well-structured. Handle potential pagination or large result sets in the future if needed.
103-105:cancelImportPlanmethod is straightforward.
No issues detected.
107-109:applyImportPlanmethod looks fine.
No issues detected.
111-113:commitImportPlanmethod is consistent.
Implementation aligns with the existing pattern.packages/cli/src/constructs/private-location-codegen.ts (5)
1-2: Import statements are correct.
No issues with module references or naming.
4-10:PrivateLocationResourceinterface definition is clear.
Optional propertiesiconandproxyUrlare properly indicated, and fields match typical usage.
12-12: Constant naming is consistent.
Using'PrivateLocation'here aligns with the codegen pattern.
14-23:valueForPrivateLocationFromIdlogic mirrors the existing pattern.
No issues found. The function imports the construct, invokesfromId, and calls it with the correct parameter.
25-58:PrivateLocationCodegencorrectly registers and generates code.
Implementation follows the establishedprepare/gencodepattern, and the usage ofcontext.registerPrivateLocationis consistent.packages/cli/src/constructs/check-group-codegen.ts (3)
28-32: PropertiesdoubleCheckandconcurrencyremain unused.
This issue was noted in a previous review. If these properties are meant to be part of the generated check group props, ensure they are applied inbuildCheckGroupProps; otherwise, consider removing them if they are not needed.
13-43: Interfaces for browser, multi-step, and check-group resources are comprehensive.
They cover the key fields needed for configuration.
239-264:CheckGroupCodegenmatches the existing codegen pattern well.
Implementation follows the typical “prepare” + “gencode” flow, with correct usage of context lookups and the builder pattern.packages/cli/src/constructs/alert-channel-codegen.ts (4)
31-51: Validate presence of optional fields before building.
Though this function checks forundefinedbefore setting properties, it might be beneficial to confirm that any upstream or default values are validated correctly elsewhere (e.g., for numeric fields likesslExpiryThreshold).
66-95: Good modular design mapping alert channel types to codegens.
This dictionary-based approach cleanly extends support for new alert channel types without code duplication.
97-104: Exception thrown for unsupported alert channel types is appropriate.
Returning early for valid channel types, then throwing an error for unsupported types, is consistent. No changes needed.
106-113: Consistent pattern in 'gencode' method.
Mirroring the 'prepare' method with a dictionary lookup keeps the code DRY and straightforward.packages/cli/src/constructs/webhook-alert-channel-codegen.ts (3)
28-31: Appropriate use of interface extension for 'WEBHOOK' resource.
DefiningWebhookAlertChannelResourceto extendAlertChannelResourceclarifies required and optional fields for this channel type.
97-108: 'prepare' method properly avoids returning a value in void function.
This implementation complies with TypeScript's type signature and addresses previous concerns about returning the nested call.
110-137: Fallback path for unrecognized webhook type is well-handled.
If thewebhookTypeis absent or undefined, the code gracefully sets up a generic webhook alert channel.packages/cli/src/sourcegen/arraybuilder.ts (2)
12-16: Builder function cleanly abstracts array creation.
Using thearray(...)top-level function to drive theArrayValueBuilderfosters readability and modularity.
18-74: Robust suite of typed builder methods for array elements.
Exposing methods for different data types (e.g.,string,boolean,ident) ensures flexible and type-safe array construction.packages/cli/src/sourcegen/argsbuilder.ts (3)
13-17: Validate the builder callback usage.
Theargsfunction entirely relies on thebuildcallback. If the callback fails or is not provided, this could raise runtime errors. Consider adding a brief safety check or default noop function for robustness.
28-30: Builder methods are straightforward and consistent.
All the typed builder methods (string,boolean,number,null,undefined,ident) neatly returnthisfor chaining and push their respective value objects into#elements. This design appears both consistent and extensible.Also applies to: 32-34, 36-38, 40-42, 44-46, 48-50
73-75: Potential usage note forbuild().
The builder pattern is well-implemented. However, ensure callers understand that oncebuild()is called, further modifications to the builder’s state do not affect the returnedArgumentsValueinstance.packages/cli/src/sourcegen/objectbuilder.ts (3)
26-28: Builder methods look correct and consistent.
String, boolean, number, null, undefined, and identifier property methods consistently forward tothis.value(). This is consistent with typical builder patterns. No issues found.Also applies to: 30-32, 34-36, 38-40, 42-44, 46-48
50-52: Support for nested arrays and objects is well-designed.
Thearrayandobjectmethods enable nesting within objects, which seems essential for your codegen requirements. Good job ensuring a uniform approach consistent with the other builders.Also applies to: 54-56
72-74: Finalize object creation.
Thebuild()method is straightforward and returns a newObjectValue. Just note that modifying#propertiesafterward won't affect the returnedObjectValue. That approach is consistent with typical builder patterns.
There was a problem hiding this 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 (4)
packages/cli/src/commands/import/plan.ts (3)
66-79: Consider covering additional error codes for better resilience.You currently handle
404errors by printing specific messages. However, server responses like401and403can also occur. Consider adding similar handling for these error codes to offer clearer feedback and gracefully exit or retry.
116-118: Warn users before overwriting the output file.Writing the code to
./generated.check.tswithout confirmation might overwrite an existing file. Consider adding checks or a user prompt if the file already exists.const filename = './generated.check.ts' +// Consider checking if the file exists. If yes, prompt the user for confirmation writeFileSync(filename, output.finalize())
216-217: Remove the useless switch case for'exit'.The
'exit'case falls through to thedefaultbranch, which already handles exiting. This is flagged by the linter as a useless case.- case 'exit': - // falls through default: { this.log('Exiting without making any changes.') this.exit(0) }🧰 Tools
🪛 Biome (1.9.4)
[error] 216-217: Useless case clause.
because the default clause is present:
Unsafe fix: Remove the useless case.
(lint/complexity/noUselessSwitchCase)
packages/cli/src/commands/import/cancel.ts (1)
67-71: Differentiate plan titles in the user prompt.All plans are labeled "Plan #1 from …," which may confuse users if multiple plans exist. Include an index or other unique identifier to differentiate each plan.
-const choices: prompts.Choice[] = plans.map(plan => ({ - title: `Plan #1 from ${new Date(plan.createdAt)}`, +const choices: prompts.Choice[] = plans.map((plan, index) => ({ + title: `Plan #${index + 1} from ${new Date(plan.createdAt)}`, value: plan.id, description: `ID: ${plan.id}`, }))
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (4)
packages/cli/src/commands/import/apply.ts(1 hunks)packages/cli/src/commands/import/cancel.ts(1 hunks)packages/cli/src/commands/import/commit.ts(1 hunks)packages/cli/src/commands/import/plan.ts(1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
- packages/cli/src/commands/import/commit.ts
🧰 Additional context used
🧬 Code Definitions (1)
packages/cli/src/commands/import/plan.ts (4)
packages/cli/src/rest/projects.ts (1)
ImportPlan(43-49)packages/cli/src/sourcegen/index.ts (2)
Program(29-29)Output(28-28)packages/cli/src/constructs/construct-codegen.ts (2)
ConstructCodegen(57-117)sortResources(49-55)packages/cli/src/constructs/internal/codegen/context.ts (1)
Context(5-138)
🪛 Biome (1.9.4)
packages/cli/src/commands/import/plan.ts
[error] 216-217: Useless case clause.
because the default clause is present:
Unsafe fix: Remove the useless case.
(lint/complexity/noUselessSwitchCase)
⏰ Context from checks skipped due to timeout of 90000ms (2)
- GitHub Check: test - windows-latest
- GitHub Check: test - ubuntu-latest
🔇 Additional comments (2)
packages/cli/src/commands/import/plan.ts (1)
29-51: Add unit tests to handle existing import plans scenario.This comment matches a previously raised concern about missing tests when existing import plans are detected. Please ensure that you thoroughly test the flow through
#handleExistingPlans, covering all user interactions and edge cases.packages/cli/src/commands/import/apply.ts (1)
62-95: Great job addressing previous feedback.You have correctly differentiated plan titles and handle the
planId === undefinedscenario. This makes the user experience clearer and avoids accidental errors.
There was a problem hiding this 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 (6)
packages/cli/src/constructs/check-codegen.ts (4)
70-75: Improve error handling for context lookups.This code silently catches errors from
lookupCheckPrivateLocationswithout logging or handling them. This could hide issues where context lookups fail, making debugging difficult.Consider adding logging or a more explicit error handling strategy:
const privateLocationIds = (() => { try { return context.lookupCheckPrivateLocations(resource.id) } catch (err) { + // Explicitly return undefined when no private locations found + // console.debug(`No private locations found for check ${resource.id}`) return undefined } })()
121-126: Improve error handling for alert channel lookups.Similar to private location lookups, this code silently catches errors without any logging or explicit handling. Consider a more robust error handling approach.
Add explicit return and optional logging:
const alertChannelIds = (() => { try { return context.lookupCheckAlertChannels(resource.id) } catch (err) { + // Explicitly return undefined when no alert channels found + // console.debug(`No alert channels found for check ${resource.id}`) + return undefined } })()
177-193: Add runtime type validation before casting resources.The code assumes resources can be safely cast to specific check types. Consider validating the resource structure before casting to ensure type safety at runtime.
Consider adding validation before casting:
switch (checkType) { case 'BROWSER': + // Validate resource has browser-specific properties before casting + if ('script' in resource || 'scriptPath' in resource) { this.browserCheckCodegen.gencode(logicalId, resource as BrowserCheckResource, context) return + } else { + throw new Error(`Invalid BROWSER check: missing required properties`) + } case 'API':The same approach can be applied to other check types to ensure they have the required properties before casting.
149-149: Handle case when retryStrategy is undefined.The
retryStrategyproperty is optional in theCheckResourceinterface, but the code always callsvalueForRetryStrategywithout checking if it's undefined.Consider making this conditional:
- builder.value('retryStrategy', valueForRetryStrategy(program, resource.retryStrategy)) + if (resource.retryStrategy !== undefined || resource.retryStrategy === null) { + builder.value('retryStrategy', valueForRetryStrategy(program, resource.retryStrategy)) + }However, if the implementation of
valueForRetryStrategyalready handles undefined values properly, this change may not be necessary.packages/cli/src/sourcegen/objectbuilder.ts (2)
26-28: Consider validating property names as JavaScript identifiers.The builder doesn't validate that property names are valid JavaScript identifiers, which could lead to generated code that doesn't compile.
Add validation for property names:
string (name: string, value: string, options?: ObjectPropertyOptions): this { + this.validatePropertyName(name); return this.value(name, new StringValue(value), options) } + private validatePropertyName(name: string): void { + // Basic validation for JS identifiers or string literals + if (!/^[a-zA-Z_$][\w$]*$/.test(name) && !name.startsWith("'") && !name.startsWith('"')) { + console.warn(`Warning: '${name}' may not be a valid JavaScript property identifier`); + } + }This suggestion applies to all property-adding methods, so the validation should be centralized in one place.
18-75: Consider supporting computed property names.The current implementation does not support computed property names (e.g.,
[expression]: value), which might be needed for some code generation use cases.Add support for computed property names:
computedProperty( expression: Value, value: Value, options?: ObjectPropertyOptions ): this { // Create a special type of property that renders as [expression]: value this.#properties.set(`__computed_${this.#properties.size}`, { name: expression, value, isComputed: true, options }); return this; }This would require extending the
ObjectPropertyclass to support computed names.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (3)
packages/cli/src/constructs/check-codegen.ts(1 hunks)packages/cli/src/sourcegen/decl.ts(1 hunks)packages/cli/src/sourcegen/objectbuilder.ts(1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
- packages/cli/src/sourcegen/decl.ts
🧰 Additional context used
🧬 Code Definitions (2)
packages/cli/src/constructs/check-codegen.ts (12)
packages/cli/src/constructs/frequency-codegen.ts (2)
FrequencyResource(4-4)valueForFrequency(6-54)packages/cli/src/constructs/retry-strategy-codegen.ts (2)
RetryStrategyResource(4-4)valueForRetryStrategy(6-77)packages/cli/src/constructs/internal/codegen/context.ts (1)
Context(5-138)packages/cli/src/constructs/internal/codegen/index.ts (2)
Context(2-2)Codegen(1-1)packages/cli/src/constructs/private-location-codegen.ts (1)
valueForPrivateLocationFromId(14-23)packages/cli/src/constructs/key-value-pair-codegen.ts (1)
valueForKeyValuePair(4-17)packages/cli/src/constructs/alert-channel-codegen.ts (1)
valueForAlertChannelFromId(55-64)packages/cli/src/constructs/api-check-codegen.ts (2)
ApiCheckCodegen(48-163)ApiCheckResource(14-25)packages/cli/src/constructs/check-group-codegen.ts (1)
CheckGroupCodegen(241-264)packages/cli/src/constructs/heartbeat-check-codegen.ts (2)
HeartbeatCheckCodegen(11-29)HeartbeatCheckResource(6-9)packages/cli/src/constructs/multi-step-check-codegen.ts (2)
MultiStepCheckCodegen(15-42)MultiStepCheckResource(6-11)packages/cli/src/constructs/tcp-check-codegen.ts (2)
TcpCheckCodegen(29-72)TcpCheckResource(7-12)
packages/cli/src/sourcegen/objectbuilder.ts (8)
packages/cli/src/sourcegen/exprbuilder.ts (4)
build(39-41)context(34-37)ExpressionValueBuilder(11-42)expr(5-9)packages/cli/src/sourcegen/object.ts (3)
ObjectValueOptions(22-24)ObjectProperty(8-18)ObjectValue(58-88)packages/cli/src/sourcegen/string.ts (1)
StringValue(6-17)packages/cli/src/sourcegen/boolean.ts (1)
BooleanValue(4-15)packages/cli/src/sourcegen/number.ts (1)
NumberValue(4-15)packages/cli/src/sourcegen/null.ts (1)
NullValue(4-8)packages/cli/src/sourcegen/undefined.ts (1)
UndefinedValue(4-8)packages/cli/src/sourcegen/identifier.ts (1)
IdentifierValue(4-15)
⏰ Context from checks skipped due to timeout of 90000ms (2)
- GitHub Check: test - windows-latest
- GitHub Check: test - ubuntu-latest
🔇 Additional comments (3)
packages/cli/src/constructs/check-codegen.ts (1)
174-196: Remove "return" statements in a void function.The
gencodemethod is declared to returnvoidbut usesreturnstatements after delegating to specific check codegen methods. Since the function doesn't return a value, thesereturnstatements are unnecessary.Apply this diff to fix the issue:
gencode (logicalId: string, resource: CheckResource, context: Context): void { const { checkType } = resource switch (checkType) { case 'BROWSER': - this.browserCheckCodegen.gencode(logicalId, resource as BrowserCheckResource, context) - return + this.browserCheckCodegen.gencode(logicalId, resource as BrowserCheckResource, context) + break case 'API': - this.apiCheckCodegen.gencode(logicalId, resource as ApiCheckResource, context) - return + this.apiCheckCodegen.gencode(logicalId, resource as ApiCheckResource, context) + break case 'TCP': - this.tcpCheckCodegen.gencode(logicalId, resource as TcpCheckResource, context) - return + this.tcpCheckCodegen.gencode(logicalId, resource as TcpCheckResource, context) + break case 'MULTI_STEP': - this.multiStepCheckCodegen.gencode(logicalId, resource as MultiStepCheckResource, context) - return + this.multiStepCheckCodegen.gencode(logicalId, resource as MultiStepCheckResource, context) + break case 'HEARTBEAT': - this.heartbeatCheckCodegen.gencode(logicalId, resource as HeartbeatCheckResource, context) - return + this.heartbeatCheckCodegen.gencode(logicalId, resource as HeartbeatCheckResource, context) + break default: throw new Error(`Unable to generate code for unsupported check type '${checkType}'.`) } }packages/cli/src/sourcegen/objectbuilder.ts (2)
67-70: LGTM: Property overwriting behavior is appropriate.The implementation correctly overwrites properties with the same name when they're added multiple times. This follows JavaScript's object property behavior and allows for property overrides in a builder pattern.
12-16: Support for immutability and method chaining.The builder pattern implementation follows good practices for fluent interfaces with method chaining and appropriate immutability. The factory function
object()provides a clean API for creating object values.
There was a problem hiding this 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
♻️ Duplicate comments (2)
packages/cli/src/constructs/status-page-codegen.ts (1)
12-22: Validate optional properties with fallback defaults.While
customDomain,logo,redirectTo, etc., are marked optional, consider adding basic validation or fallback handling. For example, you might ensure that any absent optional properties have safe defaults to avoid runtime errors.packages/cli/src/constructs/check-group-codegen.ts (1)
23-43: Inconsistent usage ofdoubleCheckandconcurrency.These fields are declared in the
CheckGroupResourceinterface but never used insidebuildCheckGroupProps. This can lead to incomplete or incorrect code generation.
🧹 Nitpick comments (7)
packages/cli/src/constructs/status-page-codegen.ts (4)
43-49: Improve error handling in service lookup.The try-catch block catches all errors but doesn't distinguish between a missing service and other potential errors that might occur during lookup. Consider adding more specific error handling or validating the service existence before attempting to look it up.
- try { - const serviceVariable = context.lookupStatusPageService(service.id) - builder.value(serviceVariable) - } catch (err) { - throw new Error(`Status page '${resource.id}' refers to service '${service.id}' which is not being imported.`) - } + if (context.hasStatusPageService(service.id)) { + const serviceVariable = context.lookupStatusPageService(service.id) + builder.value(serviceVariable) + } else { + throw new Error(`Status page '${resource.id}' refers to service '${service.id}' which is not being imported.`) + }This assumes a
hasStatusPageServicemethod exists or could be added to the Context class.
71-73: Validate the defaultTheme value.The code doesn't validate if the provided
defaultThemevalue is one of the allowed themes from theStatusPageThemeenum. Consider adding validation to ensure the theme is valid before using it.if (resource.defaultTheme) { + // Ensure the theme is valid + if (!Object.values(StatusPageTheme).includes(resource.defaultTheme)) { + throw new Error(`Invalid theme '${resource.defaultTheme}' for status page '${resource.id}'.`) + } builder.string('defaultTheme', resource.defaultTheme) }
55-73: Consider refactoring conditional property assignments.The repeated conditional blocks for optional properties follow the same pattern and could be refactored to reduce duplication. This would make the code more maintainable if additional optional properties are added in the future.
- if (resource.customDomain) { - builder.string('customDomain', resource.customDomain) - } - - if (resource.logo) { - builder.string('logo', resource.logo) - } - - if (resource.redirectTo) { - builder.string('redirectTo', resource.redirectTo) - } - - if (resource.favicon) { - builder.string('favicon', resource.favicon) - } - - if (resource.defaultTheme) { - builder.string('defaultTheme', resource.defaultTheme) - } + // Handle optional properties + const optionalProps = [ + { key: 'customDomain', value: resource.customDomain }, + { key: 'logo', value: resource.logo }, + { key: 'redirectTo', value: resource.redirectTo }, + { key: 'favicon', value: resource.favicon }, + { key: 'defaultTheme', value: resource.defaultTheme }, + ] + + for (const { key, value } of optionalProps) { + if (value !== undefined) { + builder.string(key, value) + } + }
27-77: Consider breaking down the gencode method.The
gencodemethod is quite long and handles multiple responsibilities. Consider extracting parts of it into helper methods for better readability and maintainability, such as a separate method for generating the cards section.gencode (logicalId: string, resource: StatusPageResource, context: Context): void { this.program.import(construct, 'checkly/constructs') this.program.section(expr(ident(construct), builder => { builder.new(builder => { builder.string(logicalId) builder.object(builder => { builder.string('name', resource.name) builder.string('url', resource.url) - builder.array('cards', builder => { - for (const card of resource.cards) { - builder.object(builder => { - builder.string('name', card.name) - builder.array('services', builder => { - for (const service of card.services) { - try { - const serviceVariable = context.lookupStatusPageService(service.id) - builder.value(serviceVariable) - } catch (err) { - throw new Error(`Status page '${resource.id}' refers to service '${service.id}' which is not being imported.`) - } - } - }) - }) - } - }) + this.generateCards(builder, resource, context) // Handle optional properties if (resource.customDomain) { builder.string('customDomain', resource.customDomain) } // ... other optional properties }) }) })) } + /** + * Generate the cards section of the status page + */ + private generateCards(builder: any, resource: StatusPageResource, context: Context): void { + builder.array('cards', builder => { + for (const card of resource.cards) { + builder.object(builder => { + builder.string('name', card.name) + builder.array('services', builder => { + for (const service of card.services) { + try { + const serviceVariable = context.lookupStatusPageService(service.id) + builder.value(serviceVariable) + } catch (err) { + throw new Error(`Status page '${resource.id}' refers to service '${service.id}' which is not being imported.`) + } + } + }) + }) + } + }) + }packages/cli/src/constructs/tcp-check-codegen.ts (1)
29-73: Optional validation for TCP port
Thegencodemethod correctly constructs a TCP check object. As a minor improvement, consider validatingresource.request.portor defaulting if the port is out of typical range to safeguard user errors.packages/cli/src/constructs/check-codegen.ts (1)
162-204: Check routing viagencode
TheCheckCodegenclass routes checks to specific code generators based on thecheckType. This design is modular and maintainable. However, note that returning early from a function typed asvoidcan conflict with certain static analyzers.Consider removing the early
returnstatements and usebreakclauses in the switch to align with “no-return-in-void” guidelines.packages/cli/src/constructs/check-group-codegen.ts (1)
45-251: Consider splitting the function into smaller subroutines.The
buildCheckGroupPropsfunction is quite large (~200 lines). Splitting it into separate helper functions (e.g.buildLocationProps,buildApiCheckDefaultsProps, etc.) would improve readability and make future maintenance more manageable.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (8)
packages/cli/src/constructs/api-check-codegen.ts(1 hunks)packages/cli/src/constructs/check-codegen.ts(1 hunks)packages/cli/src/constructs/check-group-codegen.ts(1 hunks)packages/cli/src/constructs/dashboard-codegen.ts(1 hunks)packages/cli/src/constructs/status-page-codegen.ts(1 hunks)packages/cli/src/constructs/tcp-check-codegen.ts(1 hunks)packages/cli/src/constructs/webhook-alert-channel-codegen.ts(1 hunks)packages/cli/src/sourcegen/objectbuilder.ts(1 hunks)
🚧 Files skipped from review as they are similar to previous changes (2)
- packages/cli/src/constructs/dashboard-codegen.ts
- packages/cli/src/constructs/webhook-alert-channel-codegen.ts
🧰 Additional context used
🧬 Code Graph Analysis (5)
packages/cli/src/constructs/tcp-check-codegen.ts (3)
packages/cli/src/constructs/check-codegen.ts (1)
CheckResource(17-35)packages/cli/src/constructs/tcp-check.ts (2)
TcpRequest(20-46)TcpAssertion(8-8)packages/cli/src/constructs/internal/assertion-codegen.ts (2)
valueForGeneralAssertion(45-146)valueForNumericAssertion(4-43)
packages/cli/src/constructs/api-check-codegen.ts (5)
packages/cli/src/constructs/check-codegen.ts (1)
CheckResource(17-35)packages/cli/src/constructs/api-check.ts (2)
Request(79-95)headers(29-31)packages/cli/src/constructs/internal/assertion-codegen.ts (1)
valueForNumericAssertion(4-43)packages/cli/src/constructs/internal/codegen/index.ts (2)
Codegen(1-1)Context(2-2)packages/cli/src/constructs/internal/codegen/context.ts (1)
Context(5-138)
packages/cli/src/constructs/check-codegen.ts (12)
packages/cli/src/constructs/frequency-codegen.ts (2)
FrequencyResource(4-4)valueForFrequency(6-54)packages/cli/src/constructs/retry-strategy-codegen.ts (2)
RetryStrategyResource(4-4)valueForRetryStrategy(6-77)packages/cli/src/constructs/internal/codegen/context.ts (1)
Context(5-138)packages/cli/src/constructs/internal/codegen/index.ts (2)
Context(2-2)Codegen(1-1)packages/cli/src/constructs/private-location-codegen.ts (1)
valueForPrivateLocationFromId(14-23)packages/cli/src/constructs/key-value-pair-codegen.ts (1)
valueForKeyValuePair(4-17)packages/cli/src/constructs/alert-channel-codegen.ts (1)
valueForAlertChannelFromId(55-64)packages/cli/src/constructs/api-check-codegen.ts (2)
ApiCheckCodegen(48-169)ApiCheckResource(14-25)packages/cli/src/constructs/check-group-codegen.ts (1)
CheckGroupCodegen(255-278)packages/cli/src/constructs/heartbeat-check-codegen.ts (2)
HeartbeatCheckCodegen(11-29)HeartbeatCheckResource(6-9)packages/cli/src/constructs/multi-step-check-codegen.ts (2)
MultiStepCheckCodegen(15-42)MultiStepCheckResource(6-11)packages/cli/src/constructs/tcp-check-codegen.ts (2)
TcpCheckCodegen(29-74)TcpCheckResource(7-12)
packages/cli/src/constructs/check-group-codegen.ts (5)
packages/cli/src/constructs/frequency-codegen.ts (1)
FrequencyResource(4-4)packages/cli/src/constructs/alert-escalation-policy-codegen.ts (1)
AlertEscalationResource(4-4)packages/cli/src/constructs/api-check.ts (2)
ApiCheckDefaultConfig(71-77)headers(29-31)packages/cli/src/constructs/retry-strategy-codegen.ts (1)
RetryStrategyResource(4-4)packages/cli/src/constructs/internal/codegen/index.ts (2)
Context(2-2)Codegen(1-1)
packages/cli/src/sourcegen/objectbuilder.ts (9)
packages/cli/src/sourcegen/object.ts (4)
ObjectValueOptions(22-24)ObjectProperty(8-18)ObjectPropertyOptions(4-6)ObjectValue(58-88)packages/cli/src/sourcegen/arraybuilder.ts (7)
object(54-56)build(71-73)value(62-65)ArrayValueBuilder(18-74)array(12-16)array(50-52)expr(58-60)packages/cli/src/sourcegen/exprbuilder.ts (4)
build(39-41)context(34-37)ExpressionValueBuilder(11-42)expr(5-9)packages/cli/src/sourcegen/string.ts (1)
StringValue(6-17)packages/cli/src/sourcegen/boolean.ts (1)
BooleanValue(4-15)packages/cli/src/sourcegen/number.ts (1)
NumberValue(4-15)packages/cli/src/sourcegen/null.ts (1)
NullValue(4-8)packages/cli/src/sourcegen/undefined.ts (1)
UndefinedValue(4-8)packages/cli/src/sourcegen/identifier.ts (1)
IdentifierValue(4-15)
⏰ Context from checks skipped due to timeout of 90000ms (2)
- GitHub Check: test - windows-latest
- GitHub Check: test - ubuntu-latest
🔇 Additional comments (21)
packages/cli/src/sourcegen/objectbuilder.ts (9)
1-11: Imports are well-structured.
All imported modules appear relevant to this file’s builder logic. No concerns.
12-16: Effective extension ofObjectValueOptions.
The additionalimplicitOrderproperties cleanly enable auto-ordering of object properties. This design is flexibly optional, so no immediate suggestions.
18-22: Builder pattern elegantly initiated.
Theobjectfunction provides a concise entry point for constructing a wrappedObjectValue. Good approach for consistent usage throughout the codebase.
24-30: Solid private fields for builder state.
Storing properties in#propertiesavoids duplication and leverages a Map’s overwrite behavior. No issues found.
31-47: Constructor is clear and extensible.
Merging user-provided options and setting defaults is straightforward. Consider whether negative or zero step values need special handling; otherwise, this is well done.Would you like to verify that negative or zero
implicitOrderStepworks as intended?
49-79: Type-specific property setters are well-defined.
These methods reinforce clarity and strongly type the object’s properties. The fluid chainable design is consistent.
81-88: Expression builder integration looks sound.
Exposingexprwith acontextvalue plus a builder function seamlessly aligns with the rest of the pattern. No concerns.
90-103: Overwriting existing properties addresses prior feedback.
UsingMap.setensures each key is unique, resolving the older concern about stacking multipleObjectPropertyinstances. Nicely handled.
105-108:build()finalizes correctly.
Returning anObjectValuewith sorted properties is consistent with other sourcegen patterns. This sealed approach is maintainable.packages/cli/src/constructs/tcp-check-codegen.ts (2)
7-12: Adequate extension ofCheckResourcefor TCP checks
TheTcpCheckResourceinterface properly extendsCheckResourceand designates thecheckTypeas'TCP', which aligns with howcheckTypeis handled in the central code generation logic.
14-25: Assertion source coverage verification
The function gracefully covers'RESPONSE_DATA'and'RESPONSE_TIME'sources. Confirm that these are the only necessary assertion sources for TCP checks.Do you plan to add support for any additional assertion sources in TCP? If not, this coverage is fine.
packages/cli/src/constructs/api-check-codegen.ts (4)
8-12: SnippetResource interface design
TheSnippetResourceinterface is straightforward and captures snippet details correctly.
14-25: Robust API check interface
ApiCheckResourceextends the baseCheckResourcewell, adding essential fields like request configs and optional scripts. The naming is intuitive.
27-44: Comprehensive assertion handling
valueForAssertionhandles numeric and general assertions. This logic is consistent with the underlyingassertion-codegenpattern and covers typical assertion sources (e.g.,STATUS_CODE,JSON_BODY,HEADERS,TEXT_BODY,RESPONSE_TIME).
48-169: Well-structured code generation for API checks
TheApiCheckCodegenclass thoroughly constructs API check objects with optional script references, request headers, query parameters, and authentication. This design is consistent across other check codegen classes. No major improvements are needed.packages/cli/src/constructs/check-codegen.ts (2)
17-35: Clear base check interface
CheckResourceprovides a robust and consistent base for all check types. The optional fields align well with the different check type requirements.
37-160: Sound assembly of check properties
buildCheckPropscorrectly assembles all relevant fields, including groups, locations, environment variables, tags, and alert settings, while gracefully handling missing resources with well-defined error messages. This approach effectively centralizes shared property logic.packages/cli/src/constructs/check-group-codegen.ts (4)
76-81: Avoid silently ignoring errors.Catching the error here without logging or further handling may mask possible issues. Consider either logging the error or re-throwing it.
122-127: Avoid silently ignoring errors.Similar to the earlier try-catch block, consider logging or handling the error in some way to keep visibility into unexpected failures.
223-231: Validate partialbasicAuthinstead of skipping it entirely.Currently, if either
usernameorpasswordis blank, the entirebasicAuthblock is unused. Confirm whether this is intentional or if partial credentials need to be supported or flagged.
256-279: Confirm error handling forlookupCheckGroup.
context.lookupCheckGroup(resource.id)may throw ifresource.idis invalid or not found. Verify that the calling code or upstream logic guarantees a valid ID, or consider adding error handling here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 7
♻️ Duplicate comments (3)
packages/cli/src/constructs/status-page-codegen.ts (1)
12-22: Validate optional properties with fallback defaults.While
customDomain,logo,redirectTo, etc., are marked optional, consider adding basic validation or fallback handling. For example, you might ensure that any absent optional properties have safe defaults to avoid runtime errors.packages/cli/src/constructs/incidentio-alert-channel-codegen.ts (1)
51-51: Remove redundant.toString()call.This comment mirrors a previous review remark: since
config.urlis already a string, calling.toString()introduces unnecessary overhead and potential confusion.packages/cli/src/constructs/check-group-codegen.ts (1)
28-33: Unused propertiesdoubleCheckandconcurrency.These properties appear in the
CheckGroupResourceinterface but aren’t used inbuildCheckGroupProps. If they’re needed, include them in the generated object; otherwise, remove them. This reiterates a prior suggestion.
🧹 Nitpick comments (21)
packages/cli/src/constructs/retry-strategy-codegen.ts (1)
30-37: Consider consolidating duplicate no-retries logic.There's code duplication between this null/undefined handling block and the 'NO_RETRIES' case later in the switch statement. Consider extracting this logic to a helper function.
if (strategy === null || strategy === undefined) { - return expr(ident('RetryStrategyBuilder'), builder => { - builder.member(ident('noRetries')) - builder.call(builder => { - builder.empty() - }) - }) + return buildNoRetriesExpression() } +function buildNoRetriesExpression(): Value { + return expr(ident('RetryStrategyBuilder'), builder => { + builder.member(ident('noRetries')) + builder.call(builder => { + builder.empty() + }) + }) +}packages/cli/src/constructs/maintenance-window-codegen.ts (3)
4-12: Remove unnecessary comma after tags property for consistency.There's an inconsistent use of commas in the interface definition. The property
tagshas a trailing comma while other properties don't.export interface MaintenanceWindowResource { name: string - tags: Array<string>, + tags: Array<string> startsAt: string endsAt: string repeatInterval?: number repeatUnit?: string repeatEndsAt?: string }
54-61: Simplify by removing unnecessary variable assignment.The temporary
repeatEndsAtvariable doesn't add value and can be removed to simplify the code.if (resource.repeatEndsAt) { - const repeatEndsAt = resource.repeatEndsAt builder.expr('repeatEndsAt', ident('Date'), builder => { builder.new(builder => { - builder.string(repeatEndsAt) + builder.string(resource.repeatEndsAt) }) }) }
34-44: Consider validating date string formats.The code assumes that
startsAtandendsAtare valid date strings that can be parsed by theDateconstructor. Consider adding validation to ensure these are in a valid format to prevent runtime issues.+ // Add at the beginning of the gencode method + function validateDateString(value: string, fieldName: string): void { + const date = new Date(value) + if (isNaN(date.getTime())) { + throw new Error(`Invalid date format for ${fieldName}: ${value}`) + } + } + + validateDateString(resource.startsAt, 'startsAt') + validateDateString(resource.endsAt, 'endsAt') + if (resource.repeatEndsAt) { + validateDateString(resource.repeatEndsAt, 'repeatEndsAt') + }packages/cli/src/constructs/slack-alert-channel-codegen.ts (1)
5-11: Consider adding validation for the Slackurl.Although this interface is part of the generation logic, you might still consider throwing an error if
urlis empty or malformed. This can prevent accidental misconfigurations.packages/cli/src/constructs/status-page-codegen.ts (1)
44-53: Consider extracting the service lookup logic to a separate method.The try-catch block for service lookup could be extracted to a helper method to improve code maintainability and readability.
+ private lookupServiceWithErrorHandling(context: Context, statusPageId: string, service: StatusPageServiceResource): VariableLocator { + try { + const serviceVariable = context.lookupStatusPageService(service.id) + return serviceVariable + } catch (err) { + throw new Error(`Status page '${statusPageId}' refers to service '${service.id}' which is not being imported. Please ensure the service is included in your import plan or remove it from the status page.`) + } + } gencode (logicalId: string, resource: StatusPageResource, context: Context): void { // ...existing code... builder.array('cards', builder => { for (const card of resource.cards) { builder.object(builder => { builder.string('name', card.name) builder.array('services', builder => { for (const service of card.services) { - try { - const serviceVariable = context.lookupStatusPageService(service.id) - context.importVariable(serviceVariable, file) - builder.value(serviceVariable.id) - } catch (err) { - throw new Error(`Status page '${resource.id}' refers to service '${service.id}' which is not being imported.`) - } + const serviceVariable = this.lookupServiceWithErrorHandling(context, resource.id, service) + context.importVariable(serviceVariable, file) + builder.value(serviceVariable.id) } }) }) } })packages/cli/src/commands/import/plan.ts (2)
237-239: Remove useless case clause.The
case 'exit':is immediately followed by a fall-through to the default case, making it redundant.- case 'exit': - // falls through default: { this.log('Exiting without making any changes.') this.exit(0) }🧰 Tools
🪛 Biome (1.9.4)
[error] 238-238: Useless case clause.
because the default clause is present:
Unsafe fix: Remove the useless case.
(lint/complexity/noUselessSwitchCase)
167-244: Add a safety mechanism to prevent infinite loops.The while loop used for handling user interactions has no explicit termination condition other than returning or exiting. Consider adding a maximum iteration count or a more explicit way to break out of the loop.
+ let attempts = 0; + const MAX_ATTEMPTS = 5; while (true) { + if (attempts >= MAX_ATTEMPTS) { + this.log('Maximum number of attempts reached. Exiting without making changes.'); + this.exit(1); + return; + } + attempts++; const { action } = await prompts({ // ...existing code... }) // ...existing code... }🧰 Tools
🪛 Biome (1.9.4)
[error] 238-238: Useless case clause.
because the default clause is present:
Unsafe fix: Remove the useless case.
(lint/complexity/noUselessSwitchCase)
packages/cli/src/constructs/msteams-alert-channel-codegen.ts (1)
6-10: Consider using a more specific type forwebhookType.The
webhookTypeproperty is set to the string literal 'WEBHOOK_MSTEAMS', but it could be more flexible and type-safe to use a predefined enum or string union type that includes 'WEBHOOK_MSTEAMS'.+ // Add this where WebhookType is defined or import it + export type MSTeamsWebhookType = 'WEBHOOK_MSTEAMS'; export interface MSTeamsAlertChannelResource extends WebhookAlertChannelResource { config: WebhookAlertChannelResourceConfig & { - webhookType: 'WEBHOOK_MSTEAMS' + webhookType: MSTeamsWebhookType } }packages/cli/src/constructs/check-codegen.ts (3)
75-77: Avoid silently swallowing errors.
The emptycatchblock makes debugging difficult. At minimum, log the error or handle it explicitly so that unexpected issues do not pass silently.const privateLocationIds = (() => { try { return context.lookupCheckPrivateLocations(resource.id) } catch (err) { - + console.error("Failed to lookup private locations:", err); } })()
129-133: Repeated silent error handling.
Similar to the previous comment, consider logging or handling the error to maintain visibility into the resolution path for missing alert channels.const alertChannelIds = (() => { try { return context.lookupCheckAlertChannels(resource.id) } catch (err) { - + console.warn("Could not retrieve alert channels:", err); } })()
186-202: Consider a consistent approach to flow control.
Multiple return statements in a void method are valid but can reduce readability. As an alternative, each case could end withbreak. Continue returning if you prefer the early exit style, but be aware of potential confusion in larger functions.packages/cli/src/constructs/opsgenie-alert-channel-codegen.ts (1)
26-50: Validateconfigfields if used outside codegen.
Everything looks fine for generating code, but be surename,apiKey,region, andpriorityalign with Opsgenie’s requirements if your tooling later depends on them being non-empty or valid enumerations.packages/cli/src/constructs/pagerduty-alert-channel-codegen.ts (1)
25-54: Consider optional validation for the 'serviceKey' property.
If your code depends on a valid non-empty key, ensure a presence check or additional validations happen upstream to avoid misconfiguration.packages/cli/src/constructs/status-page-service-codegen.ts (1)
4-7: Consider adding JSDoc comments.While the
StatusPageServiceResourceinterface is straightforward, adding JSDoc comments or usage examples can improve clarity for future maintainers and consumers of this interface.packages/cli/src/constructs/check-group-codegen.ts (2)
76-81: Avoid silently swallowing errors.The
try/catchblocks in these ranges discard errors without logging or handling them. This can obscure debugging efforts and create uncertainty about the presence of genuine failures. At a minimum, consider logging or otherwise managing the caught errors.Also applies to: 123-128
45-253: Consider splittingbuildCheckGroupPropsfor readability.The function spans over 200 lines and handles a wide array of properties and logic. Splitting it into smaller helper functions (e.g., dedicated handling for alerts, private locations, environment variables, etc.) would improve maintainability and test coverage.
packages/cli/src/constructs/alert-channel-codegen.ts (1)
31-51: Consider default handling for optional fields.
While this function conditionally sets properties, consider documenting or handling defaults for boolean and numeric fields when undefined, if needed.packages/cli/src/sourcegen/program.ts (1)
52-78: Consider error handling on file writes.
IfwriteFilefails (e.g., due to permissions or disk errors), the process will throw, but the code does not handle it. Consider adding logging or structured error handling to provide robust feedback.packages/cli/src/constructs/internal/codegen/context.ts (2)
31-35: Watch out for duplicate imports.
When callingimportVariable, if a file is repeatedly imported from multiple places, it may accumulate references in#imports. Not necessarily harmful, but it’s worth noting if duplicates become large. You can consider checking if an import is already present before adding it again.
37-51: Group ID collisions.
registerCheckGroupgenerates an identifier based on the map’s size. If a re-registration for the same ID occurs, it might produce inconsistent results. Ensure each group is registered exactly once or handle collisions.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (32)
packages/cli/src/commands/import/plan.ts(1 hunks)packages/cli/src/constructs/alert-channel-codegen.ts(1 hunks)packages/cli/src/constructs/alert-escalation-policy-codegen.ts(1 hunks)packages/cli/src/constructs/api-check-codegen.ts(1 hunks)packages/cli/src/constructs/browser-check-codegen.ts(1 hunks)packages/cli/src/constructs/check-codegen.ts(1 hunks)packages/cli/src/constructs/check-group-codegen.ts(1 hunks)packages/cli/src/constructs/codegen.nots(1 hunks)packages/cli/src/constructs/dashboard-codegen.ts(1 hunks)packages/cli/src/constructs/email-alert-channel-codegen.ts(1 hunks)packages/cli/src/constructs/frequency-codegen.ts(1 hunks)packages/cli/src/constructs/heartbeat-check-codegen.ts(1 hunks)packages/cli/src/constructs/incidentio-alert-channel-codegen.ts(1 hunks)packages/cli/src/constructs/internal/codegen/context.ts(1 hunks)packages/cli/src/constructs/maintenance-window-codegen.ts(1 hunks)packages/cli/src/constructs/msteams-alert-channel-codegen.ts(1 hunks)packages/cli/src/constructs/multi-step-check-codegen.ts(1 hunks)packages/cli/src/constructs/opsgenie-alert-channel-codegen.ts(1 hunks)packages/cli/src/constructs/pagerduty-alert-channel-codegen.ts(1 hunks)packages/cli/src/constructs/phone-call-alert-channel-codegen.ts(1 hunks)packages/cli/src/constructs/private-location-codegen.ts(1 hunks)packages/cli/src/constructs/ref-codegen.ts(1 hunks)packages/cli/src/constructs/retry-strategy-codegen.ts(1 hunks)packages/cli/src/constructs/slack-alert-channel-codegen.ts(1 hunks)packages/cli/src/constructs/sms-alert-channel-codegen.ts(1 hunks)packages/cli/src/constructs/status-page-codegen.ts(1 hunks)packages/cli/src/constructs/status-page-service-codegen.ts(1 hunks)packages/cli/src/constructs/tcp-check-codegen.ts(1 hunks)packages/cli/src/constructs/telegram-alert-channel-codegen.ts(1 hunks)packages/cli/src/constructs/webhook-alert-channel-codegen.ts(1 hunks)packages/cli/src/sourcegen/index.ts(1 hunks)packages/cli/src/sourcegen/program.ts(1 hunks)
🚧 Files skipped from review as they are similar to previous changes (10)
- packages/cli/src/constructs/telegram-alert-channel-codegen.ts
- packages/cli/src/constructs/dashboard-codegen.ts
- packages/cli/src/constructs/multi-step-check-codegen.ts
- packages/cli/src/constructs/browser-check-codegen.ts
- packages/cli/src/constructs/alert-escalation-policy-codegen.ts
- packages/cli/src/constructs/frequency-codegen.ts
- packages/cli/src/constructs/heartbeat-check-codegen.ts
- packages/cli/src/constructs/sms-alert-channel-codegen.ts
- packages/cli/src/constructs/webhook-alert-channel-codegen.ts
- packages/cli/src/sourcegen/index.ts
🧰 Additional context used
🧬 Code Graph Analysis (20)
packages/cli/src/constructs/ref-codegen.ts (3)
packages/cli/src/sourcegen/index.ts (4)
GeneratedFile(29-29)Value(33-33)expr(22-22)ident(23-23)packages/cli/src/sourcegen/program.ts (1)
GeneratedFile(92-151)packages/cli/src/constructs/ref.ts (1)
Ref(1-10)
packages/cli/src/constructs/maintenance-window-codegen.ts (3)
packages/cli/src/constructs/internal/codegen/index.ts (2)
Codegen(1-1)Context(2-2)packages/cli/src/constructs/internal/codegen/context.ts (1)
Context(17-160)packages/cli/src/sourcegen/index.ts (2)
expr(22-22)ident(23-23)
packages/cli/src/constructs/api-check-codegen.ts (9)
packages/cli/src/constructs/check-codegen.ts (1)
CheckResource(17-35)packages/cli/src/constructs/api-check.ts (2)
Request(79-95)headers(29-31)packages/cli/src/sourcegen/index.ts (3)
GeneratedFile(29-29)Value(33-33)expr(22-22)packages/cli/src/sourcegen/program.ts (1)
GeneratedFile(92-151)packages/cli/src/constructs/internal/assertion-codegen.ts (2)
valueForNumericAssertion(4-43)valueForGeneralAssertion(45-146)packages/cli/src/constructs/internal/codegen/index.ts (2)
Codegen(1-1)Context(2-2)packages/cli/src/sourcegen/exprbuilder.ts (1)
context(34-37)packages/cli/src/constructs/internal/codegen/context.ts (1)
Context(17-160)packages/cli/src/constructs/key-value-pair-codegen.ts (1)
valueForKeyValuePair(4-17)
packages/cli/src/constructs/tcp-check-codegen.ts (6)
packages/cli/src/constructs/check-codegen.ts (2)
CheckResource(17-35)buildCheckProps(37-163)packages/cli/src/constructs/tcp-check.ts (2)
TcpRequest(20-46)TcpAssertion(8-8)packages/cli/src/sourcegen/index.ts (4)
GeneratedFile(29-29)Value(33-33)expr(22-22)ident(23-23)packages/cli/src/constructs/internal/assertion-codegen.ts (2)
valueForGeneralAssertion(45-146)valueForNumericAssertion(4-43)packages/cli/src/constructs/internal/codegen/index.ts (2)
Codegen(1-1)Context(2-2)packages/cli/src/constructs/internal/codegen/context.ts (1)
Context(17-160)
packages/cli/src/constructs/opsgenie-alert-channel-codegen.ts (4)
packages/cli/src/constructs/alert-channel-codegen.ts (2)
AlertChannelResource(21-29)buildAlertChannelProps(31-51)packages/cli/src/constructs/internal/codegen/index.ts (2)
Codegen(1-1)Context(2-2)packages/cli/src/constructs/internal/codegen/context.ts (1)
Context(17-160)packages/cli/src/sourcegen/index.ts (3)
decl(11-11)expr(22-22)ident(23-23)
packages/cli/src/constructs/retry-strategy-codegen.ts (3)
packages/cli/src/constructs/retry-strategy.ts (3)
RetryStrategy(3-21)RetryStrategyOptions(23-23)RetryStrategyType(1-1)packages/cli/src/sourcegen/index.ts (5)
GeneratedFile(29-29)Value(33-33)ObjectValueBuilder(27-27)expr(22-22)ident(23-23)packages/cli/src/sourcegen/program.ts (1)
GeneratedFile(92-151)
packages/cli/src/constructs/phone-call-alert-channel-codegen.ts (4)
packages/cli/src/constructs/alert-channel-codegen.ts (2)
AlertChannelResource(21-29)buildAlertChannelProps(31-51)packages/cli/src/constructs/internal/codegen/index.ts (2)
Codegen(1-1)Context(2-2)packages/cli/src/constructs/internal/codegen/context.ts (1)
Context(17-160)packages/cli/src/sourcegen/index.ts (3)
decl(11-11)expr(22-22)ident(23-23)
packages/cli/src/commands/import/plan.ts (5)
packages/cli/src/services/util.ts (1)
splitConfigFilePath(126-138)packages/cli/src/services/checkly-config-loader.ts (1)
loadChecklyConfig(123-149)packages/cli/src/rest/projects.ts (1)
ImportPlan(43-49)packages/cli/src/sourcegen/program.ts (1)
Program(15-78)packages/cli/src/constructs/internal/codegen/context.ts (1)
Context(17-160)
packages/cli/src/constructs/status-page-codegen.ts (5)
packages/cli/src/constructs/status-page-service-codegen.ts (1)
StatusPageServiceResource(4-7)packages/cli/src/constructs/status-page.ts (1)
StatusPageTheme(17-17)packages/cli/src/constructs/internal/codegen/index.ts (1)
Codegen(1-1)packages/cli/src/constructs/internal/codegen/context.ts (1)
Context(17-160)packages/cli/src/sourcegen/index.ts (2)
expr(22-22)ident(23-23)
packages/cli/src/constructs/check-codegen.ts (7)
packages/cli/src/constructs/frequency-codegen.ts (2)
FrequencyResource(4-4)valueForFrequency(6-54)packages/cli/src/constructs/retry-strategy-codegen.ts (2)
RetryStrategyResource(4-4)valueForRetryStrategy(6-77)packages/cli/src/sourcegen/index.ts (3)
GeneratedFile(29-29)ObjectValueBuilder(27-27)Program(29-29)packages/cli/src/constructs/internal/codegen/index.ts (2)
Context(2-2)Codegen(1-1)packages/cli/src/constructs/private-location-codegen.ts (1)
valueForPrivateLocationFromId(14-23)packages/cli/src/constructs/key-value-pair-codegen.ts (1)
valueForKeyValuePair(4-17)packages/cli/src/constructs/alert-channel-codegen.ts (1)
valueForAlertChannelFromId(55-64)
packages/cli/src/constructs/slack-alert-channel-codegen.ts (3)
packages/cli/src/constructs/alert-channel-codegen.ts (2)
AlertChannelResource(21-29)buildAlertChannelProps(31-51)packages/cli/src/constructs/internal/codegen/index.ts (2)
Codegen(1-1)Context(2-2)packages/cli/src/sourcegen/index.ts (3)
decl(11-11)expr(22-22)ident(23-23)
packages/cli/src/constructs/status-page-service-codegen.ts (3)
packages/cli/src/constructs/internal/codegen/index.ts (1)
Codegen(1-1)packages/cli/src/constructs/internal/codegen/context.ts (1)
Context(17-160)packages/cli/src/sourcegen/index.ts (3)
decl(11-11)expr(22-22)ident(23-23)
packages/cli/src/constructs/email-alert-channel-codegen.ts (4)
packages/cli/src/constructs/alert-channel-codegen.ts (2)
AlertChannelResource(21-29)buildAlertChannelProps(31-51)packages/cli/src/constructs/internal/codegen/index.ts (2)
Codegen(1-1)Context(2-2)packages/cli/src/constructs/internal/codegen/context.ts (1)
Context(17-160)packages/cli/src/sourcegen/index.ts (3)
decl(11-11)expr(22-22)ident(23-23)
packages/cli/src/constructs/private-location-codegen.ts (4)
packages/cli/src/sourcegen/index.ts (5)
GeneratedFile(29-29)Value(33-33)expr(22-22)ident(23-23)decl(11-11)packages/cli/src/sourcegen/program.ts (1)
GeneratedFile(92-151)packages/cli/src/constructs/internal/codegen/index.ts (2)
Codegen(1-1)Context(2-2)packages/cli/src/constructs/internal/codegen/context.ts (1)
Context(17-160)
packages/cli/src/sourcegen/program.ts (2)
packages/cli/src/sourcegen/index.ts (5)
Value(33-33)Program(29-29)GeneratedFile(29-29)AuxiliaryFile(29-29)Output(28-28)packages/cli/src/sourcegen/output.ts (1)
Output(40-85)
packages/cli/src/constructs/pagerduty-alert-channel-codegen.ts (4)
packages/cli/src/constructs/alert-channel-codegen.ts (2)
AlertChannelResource(21-29)buildAlertChannelProps(31-51)packages/cli/src/constructs/internal/codegen/index.ts (2)
Codegen(1-1)Context(2-2)packages/cli/src/constructs/internal/codegen/context.ts (1)
Context(17-160)packages/cli/src/sourcegen/index.ts (3)
decl(11-11)expr(22-22)ident(23-23)
packages/cli/src/constructs/check-group-codegen.ts (7)
packages/cli/src/constructs/frequency-codegen.ts (2)
FrequencyResource(4-4)valueForFrequency(6-54)packages/cli/src/constructs/alert-escalation-policy-codegen.ts (2)
AlertEscalationResource(4-4)valueForAlertEscalation(6-65)packages/cli/src/constructs/api-check.ts (2)
ApiCheckDefaultConfig(71-77)headers(29-31)packages/cli/src/constructs/retry-strategy-codegen.ts (2)
RetryStrategyResource(4-4)valueForRetryStrategy(6-77)packages/cli/src/sourcegen/index.ts (5)
GeneratedFile(29-29)ObjectValueBuilder(27-27)decl(11-11)expr(22-22)ident(23-23)packages/cli/src/constructs/internal/codegen/index.ts (2)
Context(2-2)Codegen(1-1)packages/cli/src/constructs/key-value-pair-codegen.ts (1)
valueForKeyValuePair(4-17)
packages/cli/src/constructs/alert-channel-codegen.ts (2)
packages/cli/src/sourcegen/index.ts (6)
ObjectValueBuilder(27-27)GeneratedFile(29-29)Value(33-33)expr(22-22)ident(23-23)Program(29-29)packages/cli/src/constructs/internal/codegen/index.ts (2)
Codegen(1-1)Context(2-2)
packages/cli/src/constructs/msteams-alert-channel-codegen.ts (5)
packages/cli/src/constructs/webhook-alert-channel-codegen.ts (2)
WebhookAlertChannelResource(28-31)WebhookAlertChannelResourceConfig(17-26)packages/cli/src/constructs/internal/codegen/index.ts (2)
Codegen(1-1)Context(2-2)packages/cli/src/constructs/internal/codegen/context.ts (1)
Context(17-160)packages/cli/src/sourcegen/index.ts (3)
decl(11-11)expr(22-22)ident(23-23)packages/cli/src/constructs/alert-channel-codegen.ts (1)
buildAlertChannelProps(31-51)
packages/cli/src/constructs/internal/codegen/context.ts (3)
packages/cli/src/constructs/internal/codegen/index.ts (2)
MissingContextVariableMappingError(2-2)Context(2-2)packages/cli/src/sourcegen/index.ts (2)
IdentifierValue(23-23)GeneratedFile(29-29)packages/cli/src/sourcegen/program.ts (1)
GeneratedFile(92-151)
🪛 Biome (1.9.4)
packages/cli/src/commands/import/plan.ts
[error] 238-238: Useless case clause.
because the default clause is present:
Unsafe fix: Remove the useless case.
(lint/complexity/noUselessSwitchCase)
🔇 Additional comments (58)
packages/cli/src/constructs/private-location-codegen.ts (4)
1-10: Interface definition for PrivateLocationResource looks good.The interface properly defines the structure with required and optional properties. This will serve well as the contract for private location resources.
14-23: Well-structured utility function for referencing private locations by ID.This function follows the established pattern for value generators, correctly importing the necessary construct and building the expression with proper nesting.
25-31: LGTM: Prepare method handles registration correctly.The prepare method properly registers the private location in the context, allowing it to be referenced later in the import process.
33-59:❓ Verification inconclusive
Consider adding error handling for missing resource lookups.
The
gencodemethod currently doesn't handle potential errors iflookupPrivateLocationfails to find the resource by ID. While the Context class likely throws an error, it would be good to handle this case explicitly or document the expected behavior.
🏁 Script executed:
#!/bin/bash # Check how Context.lookupPrivateLocation handles errors ast-grep --pattern 'lookupPrivateLocation(physicalId: string): VariableLocator { $$$ if ($$ === undefined) { $$$ } $$$ }'Length of output: 135
Explicit error handling for missing resource lookups in gencode
In
packages/cli/src/constructs/private-location-codegen.ts(lines 33–59), thegencodemethod immediately destructures the result ofcontext.lookupPrivateLocation(resource.id)without verifying that a valid lookup occurred. Even if theContextclass is designed to throw an error when a lookup fails, it would improve code clarity and robustness to either explicitly handle a potential undefined result or document that error behavior clearly. Please manually verify that thelookupPrivateLocationmethod includes sufficient error handling and consider adding an explicit check (or appropriate documentation) if it does not.packages/cli/src/constructs/ref-codegen.ts (1)
1-13: Clean implementation for generating reference values.The function correctly imports the
Refconstruct and builds an expression to create a reference usingRef.from(). This follows the same pattern as other value generators in the codebase and doesn't have any obvious issues.packages/cli/src/constructs/retry-strategy-codegen.ts (3)
4-5: Type alias for RetryStrategy is appropriate.This provides a clear separation between the domain model and the codegen resource, which could be useful if they diverge in the future.
9-28: Helper function efficiently reuses common option setup.The
buildCommonOptionsfunction correctly handles conditional properties, only adding them to the builder when they exist. This reduces code duplication when used across different strategy types.
39-76: Comprehensive handling of all retry strategy types.The switch statement correctly handles all defined retry strategy types and throws an appropriate error for unsupported types. This makes the code robust to changes in the enum.
packages/cli/src/constructs/maintenance-window-codegen.ts (1)
16-24:❓ Verification inconclusive
Missing prepare method that might be needed for resource registration.
Unlike
PrivateLocationCodegen, this class doesn't have apreparemethod. Consider whether maintenance windows need to be registered in the context for later reference by other resources.
🏁 Script executed:
#!/bin/bash # Check if other resources reference maintenance windows rg "maintenanceWindow|maintenance-window" --type tsLength of output: 1556
Attention: Verify Resource Registration for Maintenance Windows
The current implementation of
MaintenanceWindowCodegen(in packages/cli/src/constructs/maintenance-window-codegen.ts, lines 16–24) doesn’t contain apreparemethod likePrivateLocationCodegendoes. While our search confirms that maintenance window resources are referenced in various parts of the codebase, there is no evidence that apreparemethod is invoked or necessary for their registration in the context. Please double-check whether maintenance windows should be registered (as with other resource types) and, if so, consider adding apreparemethod to ensure consistency with resource registration logic.packages/cli/src/constructs/slack-alert-channel-codegen.ts (4)
1-4: Imports look correct.These imports are coherent with the rest of the codebase, and they properly reference the code generation utilities and context.
13-13: Construct naming is clear.Declaring a distinct constant for the construct name aids readability and consistency.
15-22:preparemethod usage is consistent.The
preparemethod correctly registers the alert channel in the context. This approach is consistent with the rest of the codebase’s pattern for scanning resource IDs and references.
24-49: Leverage optional Slack channel property.The logic clearly sets the
channelproperty only when it is defined, which aligns with Slack's optional usage of channels. The usage ofbuildAlertChannelPropsis also coherent with AlertChannelResource expansions.packages/cli/src/constructs/tcp-check-codegen.ts (5)
1-6: Imports look consistent.The references to
Codegen,Context, and the source generation utilities are appropriate.
7-12: Sufficient extension ofCheckResource.
TcpCheckResourcecaptures the TCP-specific fields for this check type without overlap.
14-25: Switch statement for TCP assertions is thorough.The
valueForTcpAssertionfunction handles the supported assertion sources (RESPONSE_DATA,RESPONSE_TIME) and clearly errors out if something unexpected arises. This design ensures explicit coverage of valid assertion sources.
27-29: Construct naming aligns with usage.Designating
'TcpCheck'as the construct name is consistent with the rest of the codegen approach.
30-75:gencodemethod effectively builds the resource.
- The creation of a dedicated file for these TCP checks under
resources/tcp-checks/${logicalId}is clear.- Conditionals for optional fields (
ipFamily,data,assertions, etc.) properly exclude unused fields.- Inclusion of
buildCheckPropsensures consistent coverage of base check properties.Everything looks solid.
packages/cli/src/constructs/email-alert-channel-codegen.ts (5)
1-4: Imports and references are correct.No issues with referencing the codegen and context files.
5-11:EmailAlertChannelResourceapproach is straightforward.This interface properly extends
AlertChannelResourceand defines the email-specific config.
12-13: Clear naming for theEmailAlertChannel.Consistent naming with the rest of the alert channel codegen files.
14-22:preparemethod usage.It matches the established pattern for registering an alert channel with the
'emailAlert'variable prefix.
23-42:gencodemethod is consistent with existing patterns.
- Accurately imports the construct and retrieves the file and ID from the context.
- Correctly references
addressand appliesbuildAlertChannelPropsfor optional attributes.- Code remains clear and follows the standard builder pattern.
packages/cli/src/constructs/api-check-codegen.ts (10)
1-7: Imports are well-structured.References to
context,expr,ident, and the assertion helpers are aligned with common usage.
8-12:SnippetResourceis a helpful abstraction.Centralizing snippet metadata (including
idandscript) makes code generation more flexible.
14-25:ApiCheckResourceextension is correct.Adding fields for scripts and response time parameters extends
CheckResourcesuitably for API checks.
27-44:valueForAssertionis robust.Correctly delegates to numeric or general assertion builders based on the
assertion.source. Unrecognized sources throw an error, preventing silent failures.
46-47: Descriptive construct name.
ApiCheckis a fitting construct identifier.
48-54: Class definition andgencodemethod signature.The structure extends
Codegen<ApiCheckResource>consistently, matching the typical pattern.
55-72: Clarity in the outernewbuilder.Creating a new check instance with
ApiCheckand storing it in a dedicated generated file (resources/api-checks/${logicalId}) is a clean and consistent approach.
74-124: Comprehensive handling of request fields.
- Optional fields are correctly guarded by conditionals.
- Headers and query parameters are assembled using
valueForKeyValuePair.- Basic auth is validated to avoid empty credentials.
All are well-handled for a robust API check definition.
126-164: Setup and teardown script logic is clear.
- You toggle between local inline scripts and snippet references properly.
- The TODO remark for eventually storing scripts in a separate file is a good note for future refactoring.
166-170: Additional fields and final build.Degraded and max response times are conditionally set, followed by a standardized call to
buildCheckProps. This ensures consistent final property population for the check.packages/cli/src/constructs/check-codegen.ts (1)
17-35: Interface definition looks solid.
The structure ofCheckResourceprovides clear optional and required fields for different check attributes. This is well-organized for code generation needs.packages/cli/src/constructs/opsgenie-alert-channel-codegen.ts (2)
5-13: Interface structure is consistent and clear.
TheOpsgenieAlertChannelResourceextendsAlertChannelResourcecleanly, ensuring type distinctions while inheriting common fields.
17-24:✅ Verification successful
Verify alert channel variable naming.
When registering the alert channel withvariablePrefix: 'opsgenieAlert', confirm that no other codegen uses the same prefix to avoid naming collisions.
🏁 Script executed:
#!/bin/bash # Searching for existing code that uses the same prefix "opsgenieAlert" rg "opsgenieAlert"Length of output: 103
Unique variable naming verified for Opsgenie alert channel
The search shows that the prefix'opsgenieAlert'is used only inpackages/cli/src/constructs/opsgenie-alert-channel-codegen.ts. No naming collisions exist.packages/cli/src/constructs/pagerduty-alert-channel-codegen.ts (2)
5-12: Interface extension is appropriate.
PagerdutyAlertChannelResourceproperly extendsAlertChannelResourceand specializes the configuration for PagerDuty.
17-23:✅ Verification successful
Confirm unique variable naming.
Similar to other alert-channel codegens, ensure'pagerdutyAlert'is unique and does not conflict with other variables in the context.
🏁 Script executed:
#!/bin/bash # Searching for existing code that uses the same prefix "pagerdutyAlert" rg "pagerdutyAlert"Length of output: 106
Unique Identifier Confirmed
The search confirms that'pagerdutyAlert'is only used withinpackages/cli/src/constructs/pagerduty-alert-channel-codegen.ts. There are no duplicate occurrences or conflicts with other alert-channel implementations.packages/cli/src/constructs/status-page-service-codegen.ts (2)
12-17: Well-structured registration logic.The
preparemethod cleanly registers the resource in the code generation context. No issues spotted regarding correctness or maintainability.
19-36: Implementation looks good.The
gencodemethod properly looks up the resource, imports the required construct, and declares the new status page service. This adheres to the established code generation patterns.packages/cli/src/constructs/codegen.nots (1)
1-23: All exports appear appropriate.These exports neatly consolidate different code generation classes. No issues spotted regarding performance, correctness, or maintainability.
packages/cli/src/constructs/alert-channel-codegen.ts (6)
1-2: Imports look clean and consistent.
No issues identified with the import locations or references.
12-20: Enum-like union type is well-defined.
All alert channel types are clearly enumerated, making it less prone to typos or invalid values.
21-29: Interface captures all necessary fields.
TheAlertChannelResourceinterface looks comprehensive. Just ensure the numericidfield aligns with the rest of the codebase’s schema (e.g., the same IDs used elsewhere).
66-95: Centralizing codegen instances is a solid approach.
The constructor neatly aggregates specialized code generators for each alert channel type, reducing repetition and improving maintainability.
97-114: Delegation logic is clear and cohesive.
Usingprepareandgencodemethods on the respective codegen instance is clean and keeps the code organized.
55-64:❓ Verification inconclusive
Validate named import.
Verify that'AlertChannel'is indeed the correct export from'checkly/constructs'. Otherwise, consider adjusting the import logic or rename to match the actual identifier.
🏁 Script executed:
#!/bin/bash rg -A 5 "export class AlertChannel"Length of output: 1880
Action: Verify the Imported Alert Channel Identifier
It appears that the module
'checkly/constructs'does not export an identifier namedAlertChannel—instead, classes such asAlertChannelCodegen(and related ones) are being exported. Please double-check if the intended export should actually beAlertChannelor whether the import/usage should be updated to reference the correct, existing export (e.g.,AlertChannelCodegen). Adjust the import logic accordingly.packages/cli/src/sourcegen/program.ts (7)
1-2: Imports are straightforward and necessary.
No concerns with basic Node.js imports.
10-13: Program options are concise.
TheProgramOptionsinterface is minimal and readable.
15-41: Paths gathering is efficient and well-scoped.
Thepathsgetter returns a sorted list, which can simplify file operations. Implementation appears correct.
42-50: Confirm parallel usage handling.
If multiple calls togeneratedFilehappen in parallel for the same path, the code might race while creating or retrieving the same file. Verify if concurrency is relevant or if the usage is strictly sequential.
80-86: Base program file implementation is correct.
Maintaining apathproperty is enough for usage by derived classes.
92-151: Import logic and rendering appear sound.
The approach ensures imports are aggregated neatly, and direct.tsextensions are converted to.js. This is consistent with modern JS bundling requirements.
153-161: Auxiliary file class is straightforward.
Storing raw content in a separate file class is a good separation of concerns.packages/cli/src/constructs/internal/codegen/context.ts (4)
5-5: Custom error class is appropriate.
MissingContextVariableMappingErrorcleanly expresses the missing context variable scenario.
7-15: Locator design is clear.
Encapsulating both the identifier and file intoVariableLocatorhelps maintain cohesive references in code generation.
53-67: Alert channel registration is straightforward.
Mapping a physical ID to a code generation variable is consistent with the approach taken for check groups and private locations.
69-160: Overall context design is cohesive.
The repeated pattern for private locations, checks, status pages, and alert channels maintains consistency. All lookups and registrations appear systematically handled.
| const context = new Context() | ||
|
|
||
| if (plan.changes) { | ||
| sortResources(plan.changes.resources as any) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Refactor suggestion
Avoid using any type for better type safety.
Using any for type casting loses TypeScript's type checking benefits and can lead to runtime errors. Consider creating a proper type or interface for the resources.
- sortResources(plan.changes.resources as any)
+ // Define an appropriate interface for your resources
+ type ImportPlanResource = {
+ logicalId: string;
+ // Add other properties as needed
+ };
+ sortResources(plan.changes.resources as ImportPlanResource[])📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| sortResources(plan.changes.resources as any) | |
| // Define an appropriate interface for your resources | |
| type ImportPlanResource = { | |
| logicalId: string; | |
| // Add other properties as needed | |
| }; | |
| sortResources(plan.changes.resources as ImportPlanResource[]) |
| async run (): Promise<void> { | ||
| const { flags } = await this.parse(ImportPlanCommand) | ||
| const { | ||
| config: configFilename, | ||
| root: rootDirectory, | ||
| } = flags | ||
|
|
||
| const { configDirectory, configFilenames } = splitConfigFilePath(configFilename) | ||
| const { | ||
| config: checklyConfig, | ||
| } = await loadChecklyConfig(configDirectory, configFilenames) | ||
|
|
||
| const { | ||
| logicalId, | ||
| } = checklyConfig | ||
|
|
||
| const { data: existingPlans } = await api.projects.findImportPlans(logicalId, { | ||
| onlyUncommitted: true, | ||
| }) | ||
|
|
||
| if (existingPlans.length !== 0) { | ||
| await this.#handleExistingPlans(existingPlans) | ||
| } | ||
|
|
||
| if (this.fancy) { | ||
| ux.action.start('Creating a new plan', undefined, { stdout: true }) | ||
| } | ||
|
|
||
| let plan: ImportPlan | ||
|
|
||
| try { | ||
| const { data } = await api.projects.createImportPlan(logicalId) | ||
| plan = data | ||
|
|
||
| if (this.fancy) { | ||
| ux.action.stop('✅ ') | ||
| } | ||
| } catch (err) { | ||
| if (this.fancy) { | ||
| ux.action.stop('❌') | ||
| } | ||
|
|
||
| if (isAxiosError(err)) { | ||
| if (err.response?.status === 404) { | ||
| const message = err.response?.data.message | ||
| if (message) { | ||
| this.log(chalk.red(message)) | ||
| return | ||
| } | ||
| } | ||
| } | ||
|
|
||
| throw err | ||
| } | ||
|
|
||
| const program = new Program({ | ||
| rootDirectory, | ||
| ext: '.check.ts', | ||
| }) | ||
|
|
||
| this.#generateCode(plan, program) | ||
|
|
||
| if (this.fancy) { | ||
| ux.action.start('Writing files', undefined, { stdout: true }) | ||
| } | ||
|
|
||
| try { | ||
| await program.realize() | ||
|
|
||
| if (this.fancy) { | ||
| ux.action.stop('✅ ') | ||
| } | ||
| } catch (err) { | ||
| if (this.fancy) { | ||
| ux.action.stop('❌') | ||
| } | ||
|
|
||
| throw err | ||
| } | ||
|
|
||
| this.log(`${logSymbols.success} Successfully generated the following files for your import plan:`) | ||
| for (const filePath of program.paths) { | ||
| this.log(` - ${chalk.green(filePath)}`) | ||
| } | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
💡 Verification agent
🧩 Analysis chain
Add unit tests for handling existing import plans.
The code for handling existing import plans is complex with multiple paths, but there's no indication of unit tests to verify that all scenarios work as expected.
Would you like me to help create unit tests for the various paths in the #handleExistingPlans method?
🏁 Script executed:
#!/bin/bash
# Search for existing tests related to this command
echo "Searching for tests related to ImportPlanCommand..."
rg -A 5 "ImportPlanCommand" --type ts
echo "Searching for test files related to import functionality..."
rg -l "import.*plan" --type ts testsLength of output: 1203
Action Required: Implement comprehensive unit tests for handling existing import plans
The logic for managing existing import plans (specifically within the #handleExistingPlans method) involves multiple execution paths—error handling (e.g., the 404 response from api.projects.createImportPlan), conditional logging, and the behavior of the fancy UX actions. Our codebase search did not return any related unit tests, so it appears this functionality isn’t currently covered by tests.
- Missing unit tests: There are no unit tests present for this command or for verifying the multiple conditions in the existing plans handling logic.
- Key areas to cover:
- The scenario where
existingPlans.length !== 0triggers the handling routine. - Error responses, particularly when Axios returns a 404 with a valid message.
- The UX feedback (using
ux.action.startandux.action.stop) in both success and error cases.
- The scenario where
Would you like assistance in creating unit tests that cover these scenarios?
| } catch (err) { | ||
| if (this.fancy) { | ||
| ux.action.stop('❌') | ||
| } | ||
|
|
||
| if (isAxiosError(err)) { | ||
| if (err.response?.status === 404) { | ||
| const message = err.response?.data.message | ||
| if (message) { | ||
| this.log(chalk.red(message)) | ||
| return | ||
| } | ||
| } | ||
| } | ||
|
|
||
| throw err | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Refactor suggestion
Enhance error handling with specific error messages.
The error handling in the catch block could be improved by providing more specific error messages for different types of errors, not just 404s.
try {
// ...existing code...
} catch (err) {
if (this.fancy) {
ux.action.stop('❌')
}
if (isAxiosError(err)) {
if (err.response?.status === 404) {
const message = err.response?.data.message
if (message) {
this.log(chalk.red(message))
return
}
}
+ // Handle other status codes
+ if (err.response?.status === 401) {
+ this.log(chalk.red('Authentication error. Please check your API credentials.'))
+ return
+ }
+ if (err.response?.status === 403) {
+ this.log(chalk.red('You do not have permission to create import plans.'))
+ return
+ }
+ // Log other response errors
+ if (err.response?.data?.message) {
+ this.log(chalk.red(`API error: ${err.response.data.message}`))
+ return
+ }
}
+
+ // Log non-API errors in a user-friendly way
+ this.log(chalk.red(`Failed to create import plan: ${err.message || 'Unknown error'}`))
throw err
}📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| } catch (err) { | |
| if (this.fancy) { | |
| ux.action.stop('❌') | |
| } | |
| if (isAxiosError(err)) { | |
| if (err.response?.status === 404) { | |
| const message = err.response?.data.message | |
| if (message) { | |
| this.log(chalk.red(message)) | |
| return | |
| } | |
| } | |
| } | |
| throw err | |
| } | |
| } catch (err) { | |
| if (this.fancy) { | |
| ux.action.stop('❌') | |
| } | |
| if (isAxiosError(err)) { | |
| if (err.response?.status === 404) { | |
| const message = err.response?.data.message | |
| if (message) { | |
| this.log(chalk.red(message)) | |
| return | |
| } | |
| } | |
| // Handle other status codes | |
| if (err.response?.status === 401) { | |
| this.log(chalk.red('Authentication error. Please check your API credentials.')) | |
| return | |
| } | |
| if (err.response?.status === 403) { | |
| this.log(chalk.red('You do not have permission to create import plans.')) | |
| return | |
| } | |
| // Log other response errors | |
| if (err.response?.data?.message) { | |
| this.log(chalk.red(`API error: ${err.response.data.message}`)) | |
| return | |
| } | |
| } | |
| // Log non-API errors in a user-friendly way | |
| this.log(chalk.red(`Failed to create import plan: ${err.message || 'Unknown error'}`)) | |
| throw err | |
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 4
♻️ Duplicate comments (3)
packages/cli/src/commands/import/plan.ts (1)
119-150: Usage ofanytype for resources in code generation.
As previously advised in older review comments, consider defining a proper interface (e.g.,ImportPlanResource) to avoid losing type safety and to reduce the risk of runtime errors.packages/cli/src/constructs/check-codegen.ts (1)
166-207: Return statements in avoidfunction.
Past reviews mention removingreturnstatements ingencodeafter each case to align with typical TypeScript patterns. If continuing to usereturn, ensure style consistency across check-type codegens.packages/cli/src/constructs/check-group-codegen.ts (1)
28-32: Double-check and concurrency fields are never used in props.
This repeats a previous review comment about these properties. They are defined in theCheckGroupResourceinterface but never mapped into the constructed object. To avoid confusion and possible incomplete generation, consider adding them to thebuildCheckGroupPropsfunction or removing them from the interface if no longer required.
🧹 Nitpick comments (12)
packages/cli/src/constructs/internal/codegen/context.ts (1)
5-6: Enhance error messages forMissingContextVariableMappingError.Currently, the error class does not provide any contextual detail. Consider accepting an argument (e.g., the missing ID) in the constructor to make debugging easier.
-export class MissingContextVariableMappingError extends Error {} +export class MissingContextVariableMappingError extends Error { + constructor(message?: string) { + super(message) + this.name = 'MissingContextVariableMappingError' + } +}packages/cli/src/util/index.ts (1)
1-26: Consider sanitizing or validating the secret name.Implementation is straightforward and works as intended for environment variable lookups. However, if
namecontains unexpected characters, it may cause confusion. A simple regex check or normalization step could be beneficial.packages/cli/src/constructs/key-value-pair-codegen.ts (1)
5-54: Consider sanitizingkv.keyfor secrets.If
kv.keycontains invalid characters, the generated identifier or environment variable might break. Applying a simple transformation (e.g., replacing invalid characters with underscores) can improve robustness.packages/cli/src/sourcegen/identifier.ts (2)
21-30:PascalCasehandling is missing.
Currently, only'camelCase'and'SCREAMING_SNAKE_CASE'are supported in this function. If'PascalCase'is specified, it falls back to the original string. Consider explicitly handling'PascalCase'for consistency.Here’s a diff to fill in the missing logic:
} else if (format === 'SCREAMING_SNAKE_CASE') { value = screamingSnakeCase(value) } else if (format === 'PascalCase') { + value = pascalCase(value) }
32-76: Remove the unnecessarycontinuestatement at line 67.
Per the static analysis hint, thiscontinueis redundant and can be removed for cleaner control flow.Proposed update:
if (word.length !== 0) { words.push(word) - word = '' - small = false - continue + word = '' + small = false }🧰 Tools
🪛 Biome (1.9.4)
[error] 67-67: Unnecessary continue statement
Unsafe fix: Delete the unnecessary continue statement
(lint/correctness/noUnnecessaryContinue)
packages/cli/src/constructs/api-check-codegen.ts (3)
14-25: Interface extends pattern is well-structured.
ApiCheckResourceleverages the sharedCheckResourceand adds step-specific properties. Ensure that consumers handle or test all optional fields (localSetupScript,tearDownScript, etc.) for consistent usage.
27-44: Thorough coverage of assertion sources.
ThevalueForAssertionfunction comprehensively handles various sources. If additional sources likeCOOKIESorBODY_SIZEare anticipated, consider extending the switch statement in future.
48-170: Implementation ofApiCheckCodegen.gencodeis comprehensive.
- The incremental builder approach is well-organized and easy to follow.
- The inline embedding of setup/tearDown scripts using the
contentfield is convenient but note the existing// TODO: Move to a separate file. If large scripts are common, external files might improve maintainability.- Consider validating or logging unsupported
ipFamilyvalues for stricter type safety.packages/cli/src/commands/import/plan.ts (1)
152-246: Remove the redundant'exit'case.
Static analysis flags line 239 (case 'exit':) as redundant because thedefaultclause covers the same logic. Removing the'exit'case clarifies the switch flow.- case 'exit': - // falls through default: { this.log('Exiting without making any changes.') this.exit(0) }🧰 Tools
🪛 Biome (1.9.4)
[error] 239-239: Useless case clause.
because the default clause is present:
Unsafe fix: Remove the useless case.
(lint/complexity/noUselessSwitchCase)
packages/cli/src/constructs/check-codegen.ts (1)
37-164: Graceful fallbacks inbuildCheckProps.
- The tactic of catching errors when looking up private locations or alert channels and then using fallback values is a thoughtful approach. However, confirm that skipping or silently swallowing errors is the desired outcome. In some cases, exposing a warning might help with debugging missing references.
- The function is lengthy. Consider small extraction methods for clearer logic and improved readability if it grows further.
packages/cli/src/constructs/check-group-codegen.ts (1)
127-128: Silent catch of alert channel lookup errors.
Similar to the private locations catch block, this empty catch statement might conceal root causes. Consider logging or handling the error.packages/cli/src/sourcegen/program.ts (1)
73-102: Consider enhanced error handling inrealize.
While the current logic tries to write files and directories, an error in one write might not stop subsequent writes. It can be beneficial to aggregate errors or stop on the first failure to prevent partial generation states.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (16)
packages/cli/package.json(2 hunks)packages/cli/src/commands/import/plan.ts(1 hunks)packages/cli/src/constructs/api-check-codegen.ts(1 hunks)packages/cli/src/constructs/browser-check-codegen.ts(1 hunks)packages/cli/src/constructs/check-codegen.ts(1 hunks)packages/cli/src/constructs/check-group-codegen.ts(1 hunks)packages/cli/src/constructs/heartbeat-check-codegen.ts(1 hunks)packages/cli/src/constructs/internal/codegen/context.ts(1 hunks)packages/cli/src/constructs/key-value-pair-codegen.ts(1 hunks)packages/cli/src/constructs/multi-step-check-codegen.ts(1 hunks)packages/cli/src/constructs/tcp-check-codegen.ts(1 hunks)packages/cli/src/constructs/webhook-alert-channel-codegen.ts(1 hunks)packages/cli/src/sourcegen/identifier.ts(1 hunks)packages/cli/src/sourcegen/index.ts(1 hunks)packages/cli/src/sourcegen/program.ts(1 hunks)packages/cli/src/util/index.ts(1 hunks)
🚧 Files skipped from review as they are similar to previous changes (4)
- packages/cli/src/constructs/browser-check-codegen.ts
- packages/cli/package.json
- packages/cli/src/constructs/multi-step-check-codegen.ts
- packages/cli/src/sourcegen/index.ts
🧰 Additional context used
🧬 Code Graph Analysis (9)
packages/cli/src/constructs/tcp-check-codegen.ts (6)
packages/cli/src/constructs/check-codegen.ts (2)
CheckResource(17-35)buildCheckProps(37-164)packages/cli/src/constructs/tcp-check.ts (2)
TcpRequest(20-46)TcpAssertion(8-8)packages/cli/src/sourcegen/index.ts (4)
GeneratedFile(29-29)Value(33-33)expr(22-22)ident(23-23)packages/cli/src/constructs/internal/assertion-codegen.ts (2)
valueForGeneralAssertion(45-146)valueForNumericAssertion(4-43)packages/cli/src/constructs/internal/codegen/index.ts (2)
Codegen(1-1)Context(2-2)packages/cli/src/constructs/internal/codegen/context.ts (1)
Context(17-171)
packages/cli/src/constructs/check-codegen.ts (12)
packages/cli/src/constructs/frequency-codegen.ts (2)
FrequencyResource(4-4)valueForFrequency(6-54)packages/cli/src/constructs/alert-escalation-policy-codegen.ts (2)
AlertEscalationResource(4-4)valueForAlertEscalation(6-65)packages/cli/src/constructs/retry-strategy-codegen.ts (2)
RetryStrategyResource(4-4)valueForRetryStrategy(6-77)packages/cli/src/sourcegen/index.ts (3)
Program(29-29)GeneratedFile(29-29)ObjectValueBuilder(27-27)packages/cli/src/constructs/internal/codegen/index.ts (2)
Context(2-2)Codegen(1-1)packages/cli/src/constructs/key-value-pair-codegen.ts (1)
valueForKeyValuePair(5-54)packages/cli/src/constructs/api-check-codegen.ts (2)
ApiCheckCodegen(48-171)ApiCheckResource(14-25)packages/cli/src/constructs/browser-check-codegen.ts (2)
BrowserCheckCodegen(16-49)BrowserCheckResource(6-12)packages/cli/src/constructs/check-group-codegen.ts (1)
CheckGroupCodegen(258-284)packages/cli/src/constructs/heartbeat-check-codegen.ts (2)
HeartbeatCheckCodegen(11-31)HeartbeatCheckResource(6-9)packages/cli/src/constructs/multi-step-check-codegen.ts (2)
MultiStepCheckCodegen(15-44)MultiStepCheckResource(6-11)packages/cli/src/constructs/tcp-check-codegen.ts (2)
TcpCheckCodegen(29-76)TcpCheckResource(7-12)
packages/cli/src/sourcegen/identifier.ts (4)
packages/cli/src/sourcegen/index.ts (4)
IdentifierValue(23-23)Value(33-33)Output(28-28)ident(23-23)packages/cli/src/sourcegen/objectbuilder.ts (2)
value(90-103)ident(69-71)packages/cli/src/sourcegen/arraybuilder.ts (2)
value(62-65)ident(46-48)packages/cli/src/sourcegen/output.ts (1)
Output(40-85)
packages/cli/src/constructs/heartbeat-check-codegen.ts (6)
packages/cli/src/constructs/check-codegen.ts (2)
CheckResource(17-35)buildCheckProps(37-164)packages/cli/src/constructs/heartbeat-check.ts (1)
Heartbeat(8-25)packages/cli/src/constructs/internal/codegen/index.ts (2)
Codegen(1-1)Context(2-2)packages/cli/src/constructs/internal/codegen/context.ts (1)
Context(17-171)packages/cli/src/sourcegen/index.ts (2)
expr(22-22)ident(23-23)packages/cli/src/sourcegen/identifier.ts (1)
ident(21-30)
packages/cli/src/constructs/webhook-alert-channel-codegen.ts (9)
packages/cli/src/constructs/http-header.ts (1)
HttpHeader(2-2)packages/cli/src/constructs/query-param.ts (1)
QueryParam(2-2)packages/cli/src/constructs/alert-channel-codegen.ts (2)
AlertChannelResource(21-29)buildAlertChannelProps(31-51)packages/cli/src/sourcegen/index.ts (6)
Program(29-29)GeneratedFile(29-29)ObjectValueBuilder(27-27)decl(11-11)expr(22-22)ident(23-23)packages/cli/src/constructs/internal/codegen/index.ts (2)
Context(2-2)Codegen(1-1)packages/cli/src/constructs/key-value-pair-codegen.ts (1)
valueForKeyValuePair(5-54)packages/cli/src/constructs/incidentio-alert-channel-codegen.ts (1)
IncidentioAlertChannelCodegen(29-68)packages/cli/src/constructs/msteams-alert-channel-codegen.ts (1)
MSTeamsAlertChannelCodegen(14-46)packages/cli/src/constructs/telegram-alert-channel-codegen.ts (1)
TelegramAlertChannelCodegen(28-73)
packages/cli/src/constructs/check-group-codegen.ts (7)
packages/cli/src/constructs/frequency-codegen.ts (2)
FrequencyResource(4-4)valueForFrequency(6-54)packages/cli/src/constructs/alert-escalation-policy-codegen.ts (2)
AlertEscalationResource(4-4)valueForAlertEscalation(6-65)packages/cli/src/constructs/api-check.ts (2)
ApiCheckDefaultConfig(71-77)headers(29-31)packages/cli/src/constructs/retry-strategy-codegen.ts (2)
RetryStrategyResource(4-4)valueForRetryStrategy(6-77)packages/cli/src/sourcegen/index.ts (6)
Program(29-29)GeneratedFile(29-29)ObjectValueBuilder(27-27)decl(11-11)expr(22-22)ident(23-23)packages/cli/src/constructs/internal/codegen/index.ts (2)
Context(2-2)Codegen(1-1)packages/cli/src/constructs/key-value-pair-codegen.ts (1)
valueForKeyValuePair(5-54)
packages/cli/src/constructs/api-check-codegen.ts (8)
packages/cli/src/constructs/check-codegen.ts (1)
CheckResource(17-35)packages/cli/src/constructs/api-check.ts (2)
Request(79-95)headers(29-31)packages/cli/src/sourcegen/index.ts (4)
GeneratedFile(29-29)Value(33-33)expr(22-22)ident(23-23)packages/cli/src/sourcegen/program.ts (1)
GeneratedFile(118-184)packages/cli/src/constructs/internal/assertion-codegen.ts (2)
valueForNumericAssertion(4-43)valueForGeneralAssertion(45-146)packages/cli/src/constructs/internal/codegen/index.ts (2)
Codegen(1-1)Context(2-2)packages/cli/src/constructs/internal/codegen/context.ts (1)
Context(17-171)packages/cli/src/constructs/key-value-pair-codegen.ts (1)
valueForKeyValuePair(5-54)
packages/cli/src/constructs/internal/codegen/context.ts (3)
packages/cli/src/sourcegen/identifier.ts (1)
IdentifierValue(4-15)packages/cli/src/sourcegen/index.ts (2)
IdentifierValue(23-23)GeneratedFile(29-29)packages/cli/src/sourcegen/program.ts (1)
GeneratedFile(118-184)
packages/cli/src/commands/import/plan.ts (3)
packages/cli/src/rest/projects.ts (1)
ImportPlan(43-49)packages/cli/src/sourcegen/program.ts (1)
Program(20-103)packages/cli/src/constructs/internal/codegen/context.ts (1)
Context(17-171)
🪛 Biome (1.9.4)
packages/cli/src/sourcegen/identifier.ts
[error] 67-67: Unnecessary continue statement
Unsafe fix: Delete the unnecessary continue statement
(lint/correctness/noUnnecessaryContinue)
packages/cli/src/commands/import/plan.ts
[error] 239-239: Useless case clause.
because the default clause is present:
Unsafe fix: Remove the useless case.
(lint/complexity/noUselessSwitchCase)
⏰ Context from checks skipped due to timeout of 90000ms (2)
- GitHub Check: test - windows-latest
- GitHub Check: test - ubuntu-latest
🔇 Additional comments (26)
packages/cli/src/constructs/internal/codegen/context.ts (5)
1-4: Imports look good.No immediate issues identified in these lines.
7-15:VariableLocatorimplementation is straightforward.The constructor and property assignments are clean and readable.
17-31: Private fields inContextare well-organized.No concerns regarding naming or usage.
33-122: Methods for registering and looking up check groups, alert channels, and private locations look consistent.Maps are updated correctly, and thrown errors are handled in a uniform manner. Aside from the note on more descriptive error messages, the implementation appears sound.
124-170: Methods for handling additional alert channel and status page mappings are consistent.All core registrations and lookups for group-alert-channel assignments and secrets operate correctly. The structure is solid.
packages/cli/src/constructs/key-value-pair-codegen.ts (1)
1-4: Imports are correctly organized.No issues identified here.
packages/cli/src/constructs/heartbeat-check-codegen.ts (2)
1-5: Imports are concise and appropriate.
The referenced modules align well with the intended code generation features.
6-9: Interface extension looks consistent.
By extendingCheckResource, this interface neatly adds theheartbeatproperty while enforcingcheckType: 'HEARTBEAT'.packages/cli/src/sourcegen/identifier.ts (3)
4-15: Class structure is clear.
TheIdentifierValueclass properly extendsValueand cleanly appends the identifier string to theOutput.
17-19: Interface for formatting options is straightforward.
The optionalformatfield is a good extensibility point for custom naming conventions.
78-102: Case conversion helpers look complete.
ThecamelCase,pascalCase, andscreamingSnakeCaseimplementations appear logically correct and helpful for label formatting.packages/cli/src/constructs/tcp-check-codegen.ts (2)
7-12: Resource interface extends common check fields effectively.
DefiningcheckType: 'TCP'plus optional response time props keeps TCP checks aligned with the sharedCheckResource.
14-25: TCP assertion handling is robust.
The switch statement provides explicit coverage for known assertion types (RESPONSE_DATAandRESPONSE_TIME) and cleanly throws an error for unsupported ones.packages/cli/src/constructs/api-check-codegen.ts (2)
1-6: Imports look good.
Properly organizing imports helps readability, and all dependencies appear relevant to the functionality.
8-12: Interface usage is clear.
SnippetResourceneatly encapsulates optional script data with a numeric ID, providing good clarity for snippet-like usage.packages/cli/src/commands/import/plan.ts (2)
1-16: Imports are well-structured.
All external modules and internal APIs appear correctly referenced, ensuring clarity.
17-31: Flags initialization is concise.
Good usage of OClif’sFlags. The short flag-cfor config is a practical choice.packages/cli/src/constructs/check-codegen.ts (2)
1-16: Import statements and references.
All relevant codegen modules are imported, ensuring modular separation of functionalities.
17-35:CheckResourceinterface design is consistent.
The properties match other check codegens, ensuring cross-check consistency. Make sure downstream consumers handle optional properties safely.packages/cli/src/constructs/check-group-codegen.ts (1)
258-284: Overall code generation approach looks good.
TheCheckGroupCodegenclass thoroughly registers and generates the resource with minimal redundancy. The approach of deferring logic tobuildCheckGroupPropskeeps concerns separated.packages/cli/src/constructs/webhook-alert-channel-codegen.ts (4)
28-31: Resource interface correctly restricts thetypeproperty.
Definingtype: 'WEBHOOK'clarifies usage and ensures compile-time checks.
67-75: Concise handling of optional query parameters.
The code correctly checks for a non-empty array before building thequeryParametersproperty, optimizing for minimal generated output.
104-119: Request coverage for fallback behavior inprepare.
WhenwebhookTypeis either undefined or not recognized, the code defaults to registering a generic webhook alert channel. Ensure there's a test or manual verification for this fallback path to confirm it behaves as intended.
121-148: Thegencodelogic is well-structured.
The generation logic delegates to specialized codegens when possible and otherwise uses a standard builder approach. This provides a clean separation of responsibilities for each webhook type.packages/cli/src/sourcegen/program.ts (2)
52-63: Language-based file extension handling is clear.
The switch statement correctly appends.tsor.js. No issues observed.
138-141: Automatic.ts→.jsimport adjustment might need caution.
If your build pipeline generates different artifacts or relies on.d.tsfiles, stripping the.tsextension may cause confusion. Revisit if you foresee advanced TypeScript usage or mixed bundling scenarios.
| async run (): Promise<void> { | ||
| const { flags } = await this.parse(ImportPlanCommand) | ||
| const { | ||
| config: configFilename, | ||
| root: rootDirectory, | ||
| } = flags | ||
|
|
||
| const { configDirectory, configFilenames } = splitConfigFilePath(configFilename) | ||
| const { | ||
| config: checklyConfig, | ||
| } = await loadChecklyConfig(configDirectory, configFilenames) | ||
|
|
||
| const { | ||
| logicalId, | ||
| } = checklyConfig | ||
|
|
||
| const { data: existingPlans } = await api.projects.findImportPlans(logicalId, { | ||
| onlyUncommitted: true, | ||
| }) | ||
|
|
||
| if (existingPlans.length !== 0) { | ||
| await this.#handleExistingPlans(existingPlans) | ||
| } | ||
|
|
||
| if (this.fancy) { | ||
| ux.action.start('Creating a new plan', undefined, { stdout: true }) | ||
| } | ||
|
|
||
| let plan: ImportPlan | ||
|
|
||
| try { | ||
| const { data } = await api.projects.createImportPlan(logicalId) | ||
| plan = data | ||
|
|
||
| if (this.fancy) { | ||
| ux.action.stop('✅ ') | ||
| } | ||
| } catch (err) { | ||
| if (this.fancy) { | ||
| ux.action.stop('❌') | ||
| } | ||
|
|
||
| if (isAxiosError(err)) { | ||
| if (err.response?.status === 404) { | ||
| const message = err.response?.data.message | ||
| if (message) { | ||
| this.log(chalk.red(message)) | ||
| return | ||
| } | ||
| } | ||
| } | ||
|
|
||
| throw err | ||
| } | ||
|
|
||
| const program = new Program({ | ||
| rootDirectory, | ||
| constructFileSuffix: '.check', | ||
| language: 'typescript', | ||
| }) | ||
|
|
||
| this.#generateCode(plan, program) | ||
|
|
||
| if (this.fancy) { | ||
| ux.action.start('Writing files', undefined, { stdout: true }) | ||
| } | ||
|
|
||
| try { | ||
| await program.realize() | ||
|
|
||
| if (this.fancy) { | ||
| ux.action.stop('✅ ') | ||
| } | ||
| } catch (err) { | ||
| if (this.fancy) { | ||
| ux.action.stop('❌') | ||
| } | ||
|
|
||
| throw err | ||
| } | ||
|
|
||
| this.log(`${logSymbols.success} Successfully generated the following files for your import plan:`) | ||
| for (const filePath of program.paths) { | ||
| this.log(` - ${chalk.green(filePath)}`) | ||
| } | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Refactor suggestion
Error handling for non-404 responses.
When creating a new plan, only 404 is specifically handled. Consider logging more granular error messages for other HTTP statuses (401, 403, 500, etc.) to improve debugging and user feedback.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 2
🧹 Nitpick comments (2)
packages/cli/src/sourcegen/index.ts (1)
1-34: The index.ts file provides a clean, organized export interface for the sourcegen module.This well-structured index file exports all necessary components for code generation, including value types, builders, expressions, and declarations. The organization facilitates access to these utilities for the new import command functionality.
However, I have a few suggestions for improvement:
Consider grouping related exports together rather than listing them individually. This would improve readability and make the relationships between related components more apparent:
- export { ArgumentsValue } from './args' - export { args, ArgumentsValueBuilder } from './argsbuilder' - export { ArrayValue } from './array' - export { array, ArrayValueBuilder } from './arraybuilder' + // Values + export { ArgumentsValue } from './args' + export { ArrayValue } from './array' + export { BooleanValue } from './boolean' + export { NullValue } from './null' + export { NumberValue } from './number' + export { ObjectValue } from './object' + export { StringValue } from './string' + export { UndefinedValue } from './undefined' + export { Value } from './value' + + // Builders + export { args, ArgumentsValueBuilder } from './argsbuilder' + export { array, ArrayValueBuilder } from './arraybuilder' + export { object, ObjectValueBuilder } from './objectbuilder'Add a brief module documentation comment at the top of the file explaining the purpose of these utilities in relation to the import functionality:
+/** + * Sourcegen module provides utilities for generating TypeScript code + * for the CLI import feature. This includes value representations, + * expression builders, and declaration utilities. + */ export { ArgumentsValue } from './args'packages/cli/src/sourcegen/case.ts (1)
21-35: Consider reducing duplication between pascalCase and trainCase.Both pascalCase and trainCase share the same word transformation logic but differ only in the join character. Consider refactoring to reduce duplication.
+function capitalizeWords(words: string[]): string[] { + return words.map(word => { + const initial = word.slice(0, 1).toUpperCase() + const rest = word.slice(1).toLowerCase() + return initial + rest + }) +} export function pascalCase(value: string): string { - return wordify(value).map(word => { - const initial = word.slice(0, 1).toUpperCase() - const rest = word.slice(1).toLowerCase() - return initial + rest - }).join('') + return capitalizeWords(wordify(value)).join('') } export function trainCase(value: string): string { - return wordify(value).map(word => { - const initial = word.slice(0, 1).toUpperCase() - const rest = word.slice(1).toLowerCase() - return initial + rest - }).join('-') + return capitalizeWords(wordify(value)).join('-') }
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (3)
packages/cli/src/sourcegen/case.ts(1 hunks)packages/cli/src/sourcegen/identifier.ts(1 hunks)packages/cli/src/sourcegen/index.ts(1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
- packages/cli/src/sourcegen/identifier.ts
🧰 Additional context used
🧬 Code Graph Analysis (1)
packages/cli/src/sourcegen/case.ts (1)
packages/cli/src/sourcegen/index.ts (2)
CaseFormat(6-6)cased(6-6)
🪛 Biome (1.9.4)
packages/cli/src/sourcegen/case.ts
[error] 109-109: Unnecessary continue statement
Unsafe fix: Delete the unnecessary continue statement
(lint/correctness/noUnnecessaryContinue)
⏰ Context from checks skipped due to timeout of 90000ms (2)
- GitHub Check: test - windows-latest
- GitHub Check: test - ubuntu-latest
🔇 Additional comments (4)
packages/cli/src/sourcegen/case.ts (4)
1-8: Good type definition for case formats.The
CaseFormattype clearly defines all the supported case formats in a readable manner.
10-19: LGTM: camelCase implementation is correct.The camelCase function correctly handles the first word being lowercase and subsequent words having their first letter capitalized.
37-51: LGTM: Snake and kebab case implementations look good.The implementations for snake_case, SCREAMING_SNAKE_CASE, kebab-case, and SCREAMING-KEBAB-CASE are all correct and concise.
53-72: LGTM: The cased function is well-structured.The cased function effectively routes to the appropriate case conversion function based on the format parameter. Good job including a default case.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 4
♻️ Duplicate comments (5)
packages/cli/src/commands/import/plan.ts (2)
132-138: Use a specific resource type instead ofany.This feedback repeats a previous suggestion to remove the
anycast in code generation. Defining a properly typed interface for import-plan resources would prevent type-related issues downstream.
153-247: Add unit tests to validate the existing import plans flow.The logic in
#handleExistingPlanshas multiple user choices and error scenarios that aren’t clearly tested. This recommendation was previously raised; comprehensive tests will ensure each path is covered (e.g., showing plan details, canceling plans, creating a new plan).🧰 Tools
🪛 Biome (1.9.4)
[error] 240-240: Useless case clause.
because the default clause is present:
Unsafe fix: Remove the useless case.
(lint/complexity/noUselessSwitchCase)
packages/cli/src/constructs/incidentio-alert-channel-codegen.ts (1)
51-51: Redundant.toString()call on a string
Sinceconfig.urlinWebhookAlertChannelResourceConfigis already declared as a string,.toString()is unnecessary. This duplicates a prior review comment.- builder.string('url', config.url.toString()) + builder.string('url', config.url)packages/cli/src/constructs/check-group-codegen.ts (2)
28-33: PropertiesdoubleCheckandconcurrencyremain unused.
These fields are defined inCheckGroupResourcebut never set on the constructed object inbuildCheckGroupProps. This is consistent with a past suggestion.Consider adding them:
if (resource.doubleCheck !== undefined) { builder.boolean('doubleCheck', resource.doubleCheck) } if (resource.concurrency !== undefined) { builder.number('concurrency', resource.concurrency) }
77-82: Swallowed error in private locations lookup.
Catching an error without logging or rethrowing might mask underlying issues, as previously noted.} catch (err) { - + console.error('Failed to look up private locations:', err) }
🧹 Nitpick comments (17)
packages/cli/src/constructs/api-check-codegen.ts (1)
67-73: Unify boolean defaults for better clarity.Currently, the code conditionally sets
followRedirectsandskipSSLonly whenfalseortrueis explicitly provided. Consider applying defaults (e.g.,trueforfollowRedirects) to ensure clarity about the intended behavior if these properties are not set.packages/cli/src/commands/import/plan.ts (1)
239-240: Remove the redundantcase 'exit'clause.The
case 'exit'label falls through todefaultdirectly, making it redundant. Simplify the switch statement by removing the unused case:- case 'exit': - // falls through default: { this.log('Exiting without making any changes.') this.exit(0) }🧰 Tools
🪛 Biome (1.9.4)
[error] 240-240: Useless case clause.
because the default clause is present:
Unsafe fix: Remove the useless case.
(lint/complexity/noUselessSwitchCase)
packages/cli/src/constructs/incidentio-alert-channel-codegen.ts (1)
13-25: Handle variations in 'Authorization' header.
Currently, you only extract the Bearer token when the header starts exactly with"Bearer ". You might consider case-insensitive or more flexible checks forBearerif hosting environments provide varied headers.if (header.key.toLocaleLowerCase() !== 'authorization') { continue } - -if (!header.value.startsWith('Bearer ')) { +if (!/^Bearer\s+/i.test(header.value)) { continue }packages/cli/src/constructs/alert-channel-codegen.ts (2)
21-29: Consider default values for optional booleans.
TheAlertChannelResourceinterface seems fine, but you may consider defaulting booleans likesendRecovery,sendFailure, etc., tofalseduring resource creation to avoid undefined scenarios.
31-51: buildAlertChannelProps is well structured.
The conditional checks for each property are straightforward. For large-scale usage, consider grouping these booleans or using a dynamic approach to reduce repeated conditions.packages/cli/src/sourcegen/case.ts (2)
21-35: pascalCase and trainCase have similar patterns.
These specialized transformations are straightforward, but note the repeated logic for initial + rest. Consider a helper to DRY up these transformations if more variants appear.
74-120: wordify function could remove the unnecessary continue at line 111.
According to the static analysis hint, the continue at line 111 is redundant. Removing it simplifies control flow without changing behavior.107 if (word.length !== 0) { 108 words.push(word) 109 word = '' 110 small = false -111 continue 112 }🧰 Tools
🪛 Biome (1.9.4)
[error] 111-111: Unnecessary continue statement
Unsafe fix: Delete the unnecessary continue statement
(lint/correctness/noUnnecessaryContinue)
packages/cli/src/sourcegen/program.ts (1)
103-132: realize method handles async file creation well.
Error handling is minimal, but likely sufficient for a CLI context. Consider logging any I/O errors if needed for troubleshooting.packages/cli/src/constructs/internal/codegen/context.ts (9)
5-5: Consider providing a descriptive error message.
TheMissingContextVariableMappingErrorclass lacks a constructor that sets a meaningful message. A more descriptive message can ease debugging when mappings are missing.-export class MissingContextVariableMappingError extends Error {} +export class MissingContextVariableMappingError extends Error { + constructor (message?: string) { + super(message ?? 'Context variable mapping not found.') + this.name = 'MissingContextVariableMappingError' + } +}
7-15: Add class-level documentation.
A brief docstring forVariableLocatorwould clarify its role in linking an identifier to a generated file.
55-69: Avoid repeated registrations for the same alert channel.
Similar to check groups, callingregisterAlertChannelmultiple times for the samephysicalIdgenerates new variables rather than reusing an existing one. Consider checking the map before creating a new locator.
87-100: Consider restricting duplicates in assignments.
Current logic allows multiple identicalprivateLocationPhysicalIdentries for the same group. If duplicates are unintended, consider switching to aSetto avoid repetition.- const all = this.#checkGroupPrivateLocationPhysicalIdsByPhysicalId.get(groupPhysicalId) ?? [] - all.push(privateLocationPhysicalId) - this.#checkGroupPrivateLocationPhysicalIdsByPhysicalId.set(groupPhysicalId, all) + const all = this.#checkGroupPrivateLocationPhysicalIdsByPhysicalId.get(groupPhysicalId) ?? new Set() + all.add(privateLocationPhysicalId) + this.#checkGroupPrivateLocationPhysicalIdsByPhysicalId.set(groupPhysicalId, [...all])
102-115: Duplicate handling in check assignments.
registerPrivateLocationCheckAssignmentalso appends new entries without checking for duplicates. If uniqueness is desired, consider using aSet.
117-130: Confirm desired behavior for multiple alert channel subscriptions.
Registering the samealertChannelPhysicalIdwith the samecheckPhysicalIdcan produce duplicates in the array. If that’s undesired, aSetwould help.
132-145: Same approach for alert channel group subscriptions.
RepeatedregisterAlertChannelGroupSubscriptioncalls with the same IDs may add duplicates. Ensure whether duplicates are wanted; otherwise, consider using aSet.
147-161: Provide an error message for missing status page services.
InlookupStatusPageService, we throw aMissingContextVariableMappingErrorwithout a detailed message. Consider adding contextual info like thephysicalIdto streamline debugging.- throw new MissingContextVariableMappingError() + throw new MissingContextVariableMappingError(`No StatusPageService found for physical ID: ${physicalId}`)
163-171: Expand on secret registration.
registerKnownSecrettracks secrets in aSet, returning false if already known. If needed, consider storing more metadata about each secret (like usage or date added) for better debugging.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (32)
packages/cli/src/commands/import/plan.ts(1 hunks)packages/cli/src/constructs/alert-channel-codegen.ts(1 hunks)packages/cli/src/constructs/alert-escalation-policy-codegen.ts(1 hunks)packages/cli/src/constructs/api-check-codegen.ts(1 hunks)packages/cli/src/constructs/browser-check-codegen.ts(1 hunks)packages/cli/src/constructs/check-group-codegen.ts(1 hunks)packages/cli/src/constructs/dashboard-codegen.ts(1 hunks)packages/cli/src/constructs/email-alert-channel-codegen.ts(1 hunks)packages/cli/src/constructs/frequency-codegen.ts(1 hunks)packages/cli/src/constructs/heartbeat-check-codegen.ts(1 hunks)packages/cli/src/constructs/incidentio-alert-channel-codegen.ts(1 hunks)packages/cli/src/constructs/internal/codegen/context.ts(1 hunks)packages/cli/src/constructs/key-value-pair-codegen.ts(1 hunks)packages/cli/src/constructs/maintenance-window-codegen.ts(1 hunks)packages/cli/src/constructs/msteams-alert-channel-codegen.ts(1 hunks)packages/cli/src/constructs/multi-step-check-codegen.ts(1 hunks)packages/cli/src/constructs/opsgenie-alert-channel-codegen.ts(1 hunks)packages/cli/src/constructs/pagerduty-alert-channel-codegen.ts(1 hunks)packages/cli/src/constructs/phone-call-alert-channel-codegen.ts(1 hunks)packages/cli/src/constructs/private-location-codegen.ts(1 hunks)packages/cli/src/constructs/ref-codegen.ts(1 hunks)packages/cli/src/constructs/retry-strategy-codegen.ts(1 hunks)packages/cli/src/constructs/slack-alert-channel-codegen.ts(1 hunks)packages/cli/src/constructs/sms-alert-channel-codegen.ts(1 hunks)packages/cli/src/constructs/status-page-codegen.ts(1 hunks)packages/cli/src/constructs/status-page-service-codegen.ts(1 hunks)packages/cli/src/constructs/tcp-check-codegen.ts(1 hunks)packages/cli/src/constructs/telegram-alert-channel-codegen.ts(1 hunks)packages/cli/src/constructs/webhook-alert-channel-codegen.ts(1 hunks)packages/cli/src/sourcegen/case.ts(1 hunks)packages/cli/src/sourcegen/index.ts(1 hunks)packages/cli/src/sourcegen/program.ts(1 hunks)
🚧 Files skipped from review as they are similar to previous changes (16)
- packages/cli/src/constructs/ref-codegen.ts
- packages/cli/src/constructs/dashboard-codegen.ts
- packages/cli/src/constructs/browser-check-codegen.ts
- packages/cli/src/constructs/alert-escalation-policy-codegen.ts
- packages/cli/src/constructs/frequency-codegen.ts
- packages/cli/src/constructs/maintenance-window-codegen.ts
- packages/cli/src/constructs/tcp-check-codegen.ts
- packages/cli/src/constructs/multi-step-check-codegen.ts
- packages/cli/src/constructs/status-page-codegen.ts
- packages/cli/src/constructs/heartbeat-check-codegen.ts
- packages/cli/src/constructs/telegram-alert-channel-codegen.ts
- packages/cli/src/constructs/key-value-pair-codegen.ts
- packages/cli/src/constructs/phone-call-alert-channel-codegen.ts
- packages/cli/src/constructs/retry-strategy-codegen.ts
- packages/cli/src/constructs/email-alert-channel-codegen.ts
- packages/cli/src/sourcegen/index.ts
🧰 Additional context used
🧬 Code Graph Analysis (12)
packages/cli/src/constructs/api-check-codegen.ts (7)
packages/cli/src/constructs/check-codegen.ts (1)
CheckResource(17-35)packages/cli/src/constructs/api-check.ts (2)
Request(79-95)headers(29-31)packages/cli/src/sourcegen/index.ts (5)
GeneratedFile(40-40)Value(44-44)kebabCase(14-14)expr(33-33)ident(34-34)packages/cli/src/constructs/internal/assertion-codegen.ts (2)
valueForNumericAssertion(4-43)valueForGeneralAssertion(45-146)packages/cli/src/constructs/internal/codegen/index.ts (2)
Codegen(1-1)Context(2-2)packages/cli/src/constructs/internal/codegen/context.ts (1)
Context(17-171)packages/cli/src/constructs/key-value-pair-codegen.ts (1)
valueForKeyValuePair(5-52)
packages/cli/src/constructs/status-page-service-codegen.ts (4)
packages/cli/src/constructs/internal/codegen/index.ts (1)
Codegen(1-1)packages/cli/src/constructs/internal/codegen/context.ts (1)
Context(17-171)packages/cli/src/sourcegen/index.ts (4)
kebabCase(14-14)decl(22-22)expr(33-33)ident(34-34)packages/cli/src/sourcegen/case.ts (1)
kebabCase(45-47)
packages/cli/src/constructs/sms-alert-channel-codegen.ts (4)
packages/cli/src/constructs/alert-channel-codegen.ts (2)
AlertChannelResource(21-29)buildAlertChannelProps(31-51)packages/cli/src/constructs/internal/codegen/index.ts (2)
Codegen(1-1)Context(2-2)packages/cli/src/constructs/internal/codegen/context.ts (1)
Context(17-171)packages/cli/src/sourcegen/index.ts (3)
decl(22-22)expr(33-33)ident(34-34)
packages/cli/src/constructs/slack-alert-channel-codegen.ts (4)
packages/cli/src/constructs/alert-channel-codegen.ts (2)
AlertChannelResource(21-29)buildAlertChannelProps(31-51)packages/cli/src/constructs/internal/codegen/index.ts (2)
Codegen(1-1)Context(2-2)packages/cli/src/constructs/internal/codegen/context.ts (1)
Context(17-171)packages/cli/src/sourcegen/index.ts (3)
decl(22-22)expr(33-33)ident(34-34)
packages/cli/src/constructs/alert-channel-codegen.ts (9)
packages/cli/src/sourcegen/index.ts (6)
ObjectValueBuilder(38-38)GeneratedFile(40-40)Value(44-44)expr(33-33)ident(34-34)Program(40-40)packages/cli/src/constructs/internal/codegen/index.ts (2)
Codegen(1-1)Context(2-2)packages/cli/src/constructs/phone-call-alert-channel-codegen.ts (1)
PhoneCallAlertChannelCodegen(15-50)packages/cli/src/constructs/email-alert-channel-codegen.ts (1)
EmailAlertChannelCodegen(14-43)packages/cli/src/constructs/opsgenie-alert-channel-codegen.ts (1)
OpsgenieAlertChannelCodegen(17-51)packages/cli/src/constructs/pagerduty-alert-channel-codegen.ts (1)
PagerdutyAlertChannelCodegen(16-55)packages/cli/src/constructs/slack-alert-channel-codegen.ts (1)
SlackAlertChannelCodegen(15-50)packages/cli/src/constructs/sms-alert-channel-codegen.ts (1)
SmsAlertChannelCodegen(15-50)packages/cli/src/constructs/webhook-alert-channel-codegen.ts (1)
WebhookAlertChannelCodegen(85-149)
packages/cli/src/constructs/opsgenie-alert-channel-codegen.ts (4)
packages/cli/src/constructs/alert-channel-codegen.ts (2)
AlertChannelResource(21-29)buildAlertChannelProps(31-51)packages/cli/src/constructs/internal/codegen/index.ts (2)
Codegen(1-1)Context(2-2)packages/cli/src/constructs/internal/codegen/context.ts (1)
Context(17-171)packages/cli/src/sourcegen/index.ts (3)
decl(22-22)expr(33-33)ident(34-34)
packages/cli/src/constructs/pagerduty-alert-channel-codegen.ts (4)
packages/cli/src/constructs/alert-channel-codegen.ts (2)
AlertChannelResource(21-29)buildAlertChannelProps(31-51)packages/cli/src/constructs/internal/codegen/index.ts (2)
Codegen(1-1)Context(2-2)packages/cli/src/constructs/internal/codegen/context.ts (1)
Context(17-171)packages/cli/src/sourcegen/index.ts (3)
decl(22-22)expr(33-33)ident(34-34)
packages/cli/src/constructs/private-location-codegen.ts (4)
packages/cli/src/sourcegen/index.ts (6)
GeneratedFile(40-40)Value(44-44)expr(33-33)ident(34-34)kebabCase(14-14)decl(22-22)packages/cli/src/sourcegen/program.ts (1)
GeneratedFile(168-255)packages/cli/src/constructs/internal/codegen/index.ts (2)
Codegen(1-1)Context(2-2)packages/cli/src/constructs/internal/codegen/context.ts (1)
Context(17-171)
packages/cli/src/constructs/webhook-alert-channel-codegen.ts (9)
packages/cli/src/constructs/http-header.ts (1)
HttpHeader(2-2)packages/cli/src/constructs/query-param.ts (1)
QueryParam(2-2)packages/cli/src/constructs/alert-channel-codegen.ts (2)
AlertChannelResource(21-29)buildAlertChannelProps(31-51)packages/cli/src/sourcegen/index.ts (6)
Program(40-40)GeneratedFile(40-40)ObjectValueBuilder(38-38)decl(22-22)expr(33-33)ident(34-34)packages/cli/src/constructs/internal/codegen/index.ts (2)
Context(2-2)Codegen(1-1)packages/cli/src/constructs/key-value-pair-codegen.ts (1)
valueForKeyValuePair(5-52)packages/cli/src/constructs/incidentio-alert-channel-codegen.ts (1)
IncidentioAlertChannelCodegen(29-68)packages/cli/src/constructs/msteams-alert-channel-codegen.ts (1)
MSTeamsAlertChannelCodegen(14-46)packages/cli/src/constructs/telegram-alert-channel-codegen.ts (1)
TelegramAlertChannelCodegen(28-73)
packages/cli/src/constructs/check-group-codegen.ts (7)
packages/cli/src/constructs/frequency-codegen.ts (2)
FrequencyResource(4-4)valueForFrequency(6-54)packages/cli/src/constructs/alert-escalation-policy-codegen.ts (2)
AlertEscalationResource(4-4)valueForAlertEscalation(6-65)packages/cli/src/constructs/api-check.ts (2)
ApiCheckDefaultConfig(71-77)headers(29-31)packages/cli/src/constructs/retry-strategy-codegen.ts (2)
RetryStrategyResource(4-4)valueForRetryStrategy(6-77)packages/cli/src/sourcegen/index.ts (7)
Program(40-40)GeneratedFile(40-40)ObjectValueBuilder(38-38)kebabCase(14-14)decl(22-22)expr(33-33)ident(34-34)packages/cli/src/constructs/internal/codegen/index.ts (2)
Context(2-2)Codegen(1-1)packages/cli/src/constructs/key-value-pair-codegen.ts (1)
valueForKeyValuePair(5-52)
packages/cli/src/sourcegen/case.ts (1)
packages/cli/src/sourcegen/index.ts (9)
CaseFormat(8-8)camelCase(9-9)pascalCase(10-10)trainCase(11-11)snakeCase(12-12)screamingSnakeCase(13-13)kebabCase(14-14)screamingKebabCase(15-15)cased(7-7)
packages/cli/src/constructs/internal/codegen/context.ts (4)
packages/cli/src/constructs/internal/codegen/index.ts (2)
MissingContextVariableMappingError(2-2)Context(2-2)packages/cli/src/sourcegen/index.ts (2)
IdentifierValue(34-34)GeneratedFile(40-40)packages/cli/src/sourcegen/identifier.ts (1)
IdentifierValue(5-16)packages/cli/src/sourcegen/program.ts (1)
GeneratedFile(168-255)
🪛 Biome (1.9.4)
packages/cli/src/sourcegen/case.ts
[error] 111-111: Unnecessary continue statement
Unsafe fix: Delete the unnecessary continue statement
(lint/correctness/noUnnecessaryContinue)
packages/cli/src/commands/import/plan.ts
[error] 240-240: Useless case clause.
because the default clause is present:
Unsafe fix: Remove the useless case.
(lint/complexity/noUselessSwitchCase)
⏰ Context from checks skipped due to timeout of 90000ms (2)
- GitHub Check: test - windows-latest
- GitHub Check: test - ubuntu-latest
🔇 Additional comments (44)
packages/cli/src/constructs/slack-alert-channel-codegen.ts (2)
24-49: Implementation appears consistent with the base codegen class.The usage of
buildAlertChannelPropsand the structured approach to Slack configuration align well with existing alert channel resources. The code logic to conditionally includechannelis straightforward and maintainable.
5-11:❓ Verification inconclusive
Consider adding coverage for the optional
channelproperty.The interface correctly extends
AlertChannelResourceand supports Slack-specific fields, but you may want to add tests verifying correct handling whenchannelis absent or specified.To confirm test coverage, run the following script to look for references to "SlackAlertChannel" within your test files:
🏁 Script executed:
#!/bin/bash rg "SlackAlertChannel" -A 5 testsLength of output: 79
Attention: Manual Verification Needed for Slack Alert Channel Test Coverage
- The command executed did not find a tests directory, so we could not confirm if tests cover the optional
channelproperty.- Please verify if tests for
SlackAlertChannelResourceexist in an alternative location (e.g., within thepackages/clidirectory or as part of an integrated test suite).- If such tests are absent, consider adding tests to cover both cases—when the optional
channelproperty is provided and when it is omitted.packages/cli/src/constructs/api-check-codegen.ts (1)
115-124: Assertions block is well-structured.The logic for building an array of assertions is robust, and the usage of
valueForAssertionensures each assertion type is handled appropriately. No issues found here.packages/cli/src/constructs/sms-alert-channel-codegen.ts (3)
1-11: Implementation looks good for SMS alert channel resource interfaceThe interface correctly extends
AlertChannelResourceand properly defines the SMS-specific config properties with appropriate types. The optionalnameproperty is correctly marked with the optional modifier.
15-22: Implementation of prepare method looks correctThe prepare method correctly registers the alert channel in the context with appropriate ID, variable prefix, and file path. The method follows the pattern used in other alert channel codegen implementations.
24-49: Implementation of gencode method is well-structuredThe gencode method correctly:
- Looks up the alert channel in the context
- Imports the necessary construct
- Conditionally adds the name property only if it exists
- Adds the required phoneNumber property
- Includes common alert channel properties via buildAlertChannelProps
- Exports the variable
This implementation follows good practices for code generation.
packages/cli/src/constructs/msteams-alert-channel-codegen.ts (3)
1-10: MS Teams alert channel interface looks goodThe interface correctly extends
WebhookAlertChannelResourceand appropriately defines the MS Teams-specific webhook type.
15-21: Implementation of prepare method looks correctThe prepare method correctly registers the alert channel in the context with appropriate ID, variable prefix, and file path for MS Teams alerts.
23-45:❌ Incorrect review comment
Consider adding null check for name property
The gencode method looks well-structured, but unlike the SMS implementation, it doesn't verify if the name exists before adding it. The name property seems to be assumed as mandatory in the MS Teams implementation. If this is intentional, it's fine - but if name could be optional, consider adding a conditional check similar to how it's done in the SMS implementation.
builder.object(builder => { - builder.string('name', config.name) + if (config.name) { + builder.string('name', config.name) + } builder.string('url', config.url)Run the following script to check if there are any MS Teams alert channels without a name property in existing usage:
🏁 Script executed:
#!/bin/bash # Check for MS Teams alert channels in the codebase and how they're used rg -A 5 "MSTeamsAlertChannel" --type typescriptLength of output: 82
🏁 Script executed:
#!/bin/bash # Re-run the search for MSTeamsAlertChannel usage in TypeScript files, # using the correct file type alias instead of "typescript". rg -A 5 "MSTeamsAlertChannel" --type tsLength of output: 6756
No changes required for MSTeams alert channel null-check
After verifying the codebase, it’s clear that the MSTeams alert channel interface defines the name property as a mandatory string, and all usages (e.g., in the e2e tests) consistently supply a valid name. Therefore, unlike the SMS implementation, adding a null check for name is unnecessary.
Likely an incorrect or invalid review comment.
packages/cli/src/constructs/opsgenie-alert-channel-codegen.ts (3)
1-13: Opsgenie alert channel resource interface is well-definedThe interface correctly extends
AlertChannelResourceand defines all the necessary properties for Opsgenie configuration (name, apiKey, region, and priority).
17-24: Implementation of prepare method looks correctThe prepare method correctly registers the alert channel in the context with appropriate ID, variable prefix, and file path for Opsgenie alerts.
26-50:✅ Verification successful
Implementation of gencode method is well-structured
The gencode method correctly implements the code generation logic for Opsgenie alert channels, including all required properties and common alert channel properties.
One observation: unlike the SMS implementation where name is optional, here all properties (name, apiKey, region, priority) are treated as mandatory without conditional checks. This is likely intentional based on the Opsgenie API requirements, but worth verifying.
Run the following script to check the Opsgenie construct definition to verify if all these properties are indeed required:
🏁 Script executed:
#!/bin/bash # Look for the OpsgenieAlertChannel definition to confirm required properties rg -A 15 "class OpsgenieAlertChannel" --type typescriptLength of output: 92
Below is a revised follow-up review comment that requests a re-run of the verification script with corrected parameters:
Opsgenie Alert Channel Required Properties Verification
The implementation of the
gencodemethod remains well-structured. However, to address the observation regarding the mandatory fields (name,apiKey,region, andpriority), we need to confirm whether these are indeed required by the Opsgenie API—as opposed to the SMS implementation wherenameis optional.The initial script failed due to an unrecognized file type with the
--type typescriptflag. Please re-run the verification with adjusted file matching:Once you confirm from the output that the Opsgenie API requires all these properties without optional checks, the current implementation can remain as is. If not, then further adjustments should be considered.
🏁 Script executed:
#!/bin/bash # Search for the OpsgenieAlertChannel class definition in TypeScript files rg -A 15 "class OpsgenieAlertChannel" -g "*.ts"Length of output: 3222
Opsgenie API Properties Confirmation
After verifying the OpsgenieAlertChannel class definition, it's clear that the properties (name,apiKey,region, andpriority) are explicitly declared as required. This aligns with the Opsgenie API expectations and justifies the absence of conditional checks in thegencodeimplementation. The contrast with the SMS implementation—wherenameis optional—is intentional based on these API requirements. No changes are necessary.packages/cli/src/constructs/pagerduty-alert-channel-codegen.ts (3)
1-12: PagerDuty alert channel resource interface is correctly definedThe interface properly extends
AlertChannelResourceand defines appropriate config properties with correct optionality for account and serviceName, while serviceKey is required.
16-23: Implementation of prepare method looks correctThe prepare method correctly registers the alert channel in the context with appropriate ID, variable prefix, and file path for PagerDuty alerts.
25-54: Implementation of gencode method handles optional properties correctlyThe gencode method correctly:
- Looks up the alert channel in the context
- Imports the necessary construct
- Conditionally adds optional properties (account, serviceName) only if they exist
- Always adds the required serviceKey property
- Includes common alert channel properties via buildAlertChannelProps
- Exports the variable
The implementation appropriately handles both required and optional properties, following the same pattern seen in other alert channel implementations.
packages/cli/src/constructs/status-page-service-codegen.ts (1)
19-36: LGTM for core logic.
Thegencodemethod follows a consistent pattern with other constructs, creating a newStatusPageServiceinstance with minimal but clear properties.packages/cli/src/constructs/private-location-codegen.ts (1)
33-59: All good with code structure.
Thegencodemethod closely mirrors other codegen constructs, ensuring consistency across the codebase forPrivateLocation. Good job.packages/cli/src/constructs/check-group-codegen.ts (1)
258-283: Overall structure looks good.
Creating theCheckGroupconstruct withbuildCheckGroupPropsis consistent with the approach used in other codegen files. The separation ofprepareandgencoderemains clean and modular.packages/cli/src/constructs/alert-channel-codegen.ts (6)
1-3: Ensure consistent import ordering or grouping only if required by lint rules.
No issues found here; just noting potential for grouping imports by external vs. internal if mandated by style guidelines.
12-19: Typedef for AlertChannelType looks good.
Enumerating all possible channel types ensures clarity. No issues here.
53-64: valueForAlertChannelFromId is concise and effective.
It properly constructs the expression for retrieving an alert channel by ID. Implementation is strong.
66-95: AlertChannelCodegen constructor cleanly initializes codegens.
This structured approach of mapping each channel type is well done. No immediate issues.
97-105: prepare method’s dynamic dispatch is correct.
Throws an error when an unsupported type is encountered, which is consistent with robust error handling.
106-114: gencode method’s dynamic dispatch is correct.
Similar toprepare, it cleanly delegates code generation to the correct codegen. No concerns.packages/cli/src/sourcegen/case.ts (4)
1-8: CaseFormat type covers key naming patterns.
This enumerated set is broad enough for common naming conventions. Keep the typed-based approach for clarity.
10-19: camelCase logic is valid.
Converts first word to lowercase, subsequent words to title case. Looks correct.
37-51: snakeCase, screamingSnakeCase, kebabCase, screamingKebabCase
All appear correct. Thoroughly covers the textual transformations with typical naming conventions.
53-72: cased function: central switch-based approach is clear.
No immediate issues. If you plan to expand more case types in the future, be sure to keep them in sync with this switch block.packages/cli/src/constructs/webhook-alert-channel-codegen.ts (7)
1-5: Imports are well-structured.
No concerns; references appear necessary and appropriately grouped.
12-16: WebhookType enumeration is sufficiently granular.
If more webhook providers are expected, you can easily extend this type. No issues.
17-26: WebhookAlertChannelResourceConfig interface is well-defined.
Optional fields are clearly marked, which aligns with typical usage patterns.
33-81: buildWebhookAlertChannelConfig handles property assignments nicely.
Logic is straightforward. Consider verifying ifmethodis valid (e.g., GET/POST/etc.) to handle potential misconfigurations.Would you like to add a small runtime check or an enum for allowed methods?
85-102: WebhookAlertChannelCodegen constructor’s multi-codegen approach
The mapping approach for eachwebhookTypeis consistent with the design fromAlertChannelCodegen. No issues.
104-119: prepare method gracefully delegates to sub-codegens if available.
Approach ensures specialized logic for each webhook subtype. No immediate concerns.
121-149: gencode method respects sub-codegens and fallback.
Properly builds a new section if a specialized codegen is unavailable. Implementation looks correct.packages/cli/src/sourcegen/program.ts (9)
1-3: Using node:fs/promises and path is appropriate.
Asynchronous file operations are recommended for performance in CLI tools.
4-9: Output, Value, Declaration imports
These suggest a clear separation of concerns for code generation. No issues found.
17-38: Program constructor logic is robust.
It covers valid languages, defaults the file extension accordingly. This is well-designed.
40-54: paths getter helps track generated vs. static auxiliary files.
Sorting the array is a neat feature. Implementation is straightforward.
56-79: generatedConstructFile and generatedSupportFile methods
These effectively cache or create new GeneratedFile instances. The approach is sound.
135-161: ProgramFile base class and posixPath utility
Useful for consistent path handling across different environments (Windows vs. Unix). Implementation looks good.
163-166: ImportOptions interface
A flexible approach for relative imports. No concerns here.
168-255: GeneratedFile manages sections and imports efficiently.
The logic for .ts to .js path rewriting is interesting. Ensure it aligns with your build pipeline expectations (especially if supporting TS in source but distributing JS).Can you confirm that the
.ts→.jsrewriting is always desired for your runtime or bundling toolchain?
257-265: StaticAuxiliaryFile
Straightforward container for static content. Implementation is approved.
| prepare (logicalId: string, resource: PrivateLocationResource, context: Context): void { | ||
| context.registerPrivateLocation( | ||
| resource.id, | ||
| this.program.generatedConstructFile(`resources/private-locations/${kebabCase(resource.slugName)}`), | ||
| ) | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Refactor suggestion
Validate resource slug usage.
If resource.slugName can be empty, kebabCase might return an empty string, potentially generating an invalid file path.
Add a safe check or fallback to ensure a valid slug:
if (!resource.slugName) {
throw new Error('slugName is required for PrivateLocationResource')
}📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| prepare (logicalId: string, resource: PrivateLocationResource, context: Context): void { | |
| context.registerPrivateLocation( | |
| resource.id, | |
| this.program.generatedConstructFile(`resources/private-locations/${kebabCase(resource.slugName)}`), | |
| ) | |
| } | |
| prepare (logicalId: string, resource: PrivateLocationResource, context: Context): void { | |
| + if (!resource.slugName) { | |
| + throw new Error('slugName is required for PrivateLocationResource') | |
| + } | |
| context.registerPrivateLocation( | |
| resource.id, | |
| this.program.generatedConstructFile(`resources/private-locations/${kebabCase(resource.slugName)}`), | |
| ) | |
| } |
| export class Context { | ||
| #alertChannelVariablesByPhysicalId = new Map<number, VariableLocator>() | ||
|
|
||
| #checkAlertChannelPhysicalIdsByPhysicalId = new Map<string, number[]>() | ||
| #checkPrivateLocationPhysicalIdsByPhysicalId = new Map<string, string[]>() | ||
|
|
||
| #checkGroupAlertChannelPhysicalIdsByPhysicalId = new Map<number, number[]>() | ||
| #checkGroupPrivateLocationPhysicalIdsByPhysicalId = new Map<number, string[]>() | ||
| #checkGroupVariablesByPhysicalId = new Map<number, VariableLocator>() | ||
|
|
||
| #privateLocationVariablesByPhysicalId = new Map<string, VariableLocator>() | ||
|
|
||
| #statusPageServiceVariablesByPhysicalId = new Map<string, VariableLocator>() | ||
|
|
||
| #knownSecrets = new Set<string>() | ||
|
|
||
| importVariable (locator: VariableLocator, file: GeneratedFile): void { | ||
| file.namedImport(locator.id.value, locator.file.path, { | ||
| relativeTo: dirname(file.path), | ||
| }) | ||
| } | ||
|
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
💡 Verification agent
🧩 Analysis chain
Ensure unique named imports.
If multiple variables share the same identifier value, this method may cause name collisions in the generated file. Consider either verifying uniqueness or generating a fallback name.
To confirm no collisions occur, you could scan all variable names in your code generation flow:
🏁 Script executed:
#!/bin/bash
# Checking potential collisions of imported identifiers
rg 'new IdentifierValue\('Length of output: 847
Ensure unique named imports in code generation
The importVariable method in packages/cli/src/constructs/internal/codegen/context.ts uses locator.id.value directly for named imports without any collision check. A repository scan shows multiple invocations of new IdentifierValue(...) (for instance, generating identifiers like group${nth}, ${variablePrefix}${nth}, privateLocation${nth}, and service${nth}) across different files. This raises the risk that if two parts of the code generation flow produce the same identifier value, name collisions may occur in the generated file.
- Action Items:
- Verify that the naming strategy (using template literals and counters) guarantees uniqueness across the entire codebase.
- Consider implementing a validation check within the code generation flow to catch duplicate identifiers or generate a fallback name when a collision is detected.
There was a problem hiding this 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 (4)
packages/cli/src/sourcegen/program.ts (4)
56-79: Refactor duplicated logic for generated files.
BothgeneratedConstructFileandgeneratedSupportFilerepeat a similar “check if cached, else create” pattern. Consider extracting this into a helper function to reduce code duplication.- generatedConstructFile (path: string): GeneratedFile { - ... - if (file === undefined) { - file = new GeneratedFile(path) - this.#generatedFiles.set(path, file) - } - ... - } - - generatedSupportFile (path: string): GeneratedFile { - ... - if (file === undefined) { - file = new GeneratedFile(path) - this.#generatedFiles.set(path, file) - } - ... - } + private getOrCreateGeneratedFile(path: string): GeneratedFile { + let file = this.#generatedFiles.get(path) + if (!file) { + file = new GeneratedFile(path) + this.#generatedFiles.set(path, file) + } + return file + } + generatedConstructFile (path: string): GeneratedFile { + const finalPath = path + this.#options.constructFileSuffix + this.#ext + return this.getOrCreateGeneratedFile(finalPath) + } + generatedSupportFile (path: string): GeneratedFile { + const finalPath = path + this.#ext + return this.getOrCreateGeneratedFile(finalPath) + }
81-101: Consolidate the static file creation methods.
The methodsstaticSpecFile,staticStyleFile, andstaticSupportFilealso share similar patterns of concatenating file extensions and constructingStaticAuxiliaryFile. You could unify these to reduce repetition and centralize logic.
103-132: Add error handling for file writes.
Therealize()method writes files without try/catch. While the Node.js promises will reject on failure, consider logging or handling errors more gracefully to inform users if writing files fails.async realize (): Promise<void> { for (const file of this.#generatedFiles.values()) { const fullFilePath = path.join(this.#options.rootDirectory, file.path) try { ... await writeFile(fullFilePath, output.finalize()) } catch (err) { + console.error(`Error writing generated file at ${fullFilePath}:`, err) + throw err } } ... }
159-161: Consider usingpath.posixfor cross-platform consistency.
The helper functionposixPath()re-implements path normalization. Switching topath.posixmethods could further eliminate edge cases.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
packages/cli/src/sourcegen/program.ts(1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (2)
- GitHub Check: test - windows-latest
- GitHub Check: test - ubuntu-latest
🔇 Additional comments (6)
packages/cli/src/sourcegen/program.ts (6)
1-16: Initial imports look good.
No issues found regarding syntax or references. The dependencies fromnode:fs/promisesandnode:pathare suitably imported, and the auxiliary imports (Output,Value,Declaration) are semantically relevant.
17-38: Consider support for additional file extensions.
Currently,ProgramOptions.languageonly handles'typescript' | 'javascript'. If you plan to support other JS/TS variants (e.g.,.mjs,.cjs,.jsx,.tsx), consider extending this switch or clarifying constraints in documentation.
40-54: Paths getter implementation.
Collecting all file paths from both generated and static files is straightforward and well-organized, and the sorting ensures a predictable ordering. No changes required here.
135-157: Solid abstraction inProgramFile.
This base class neatly provides path utilities (directory name, base name, relative path). The approach is clean, and the use ofposixPathfor path normalization is helpful.
168-255: Verify behavior for other file extensions.
In#processImportFrom, the logic strips.tsor.jsextensions. If.mjs,.cjs,.jsx, or.tsxappear, they may cause unexpected behavior. Confirm whether this is intentional or broaden this approach if these file types could appear in your use case.
257-265: Static file class is straightforward.
This class correctly stores the content for the specified path without extra overhead. Implementation is succinct and self-contained.
There was a problem hiding this 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
♻️ Duplicate comments (7)
packages/cli/src/constructs/status-page-codegen.ts (2)
12-22: Validate optional properties with fallback defaults.While
customDomain,logo,redirectTo, etc., are marked optional, consider adding basic validation or fallback handling. For example, you might ensure that any absent optional properties have safe defaults to avoid runtime errors.
40-57: 🛠️ Refactor suggestionEnhance error handling for missing services with more actionable guidance.
The current error message correctly indicates when a status page refers to a service that isn't being imported, but it doesn't provide guidance on how to resolve the issue.
- throw new Error(`Status page '${resource.id}' refers to service '${service.id}' which is not being imported.`) + throw new Error(`Status page '${resource.id}' refers to service '${service.id}' which is not being imported. Please ensure the service is included in your import plan or remove it from the status page.`)packages/cli/src/constructs/internal/codegen/context.ts (2)
60-64: Ensure unique named imports to avoid collisions [duplicate comment].
Similar to prior feedback on potential identifier collisions, multiple variables with the same identifier value can lead to name collisions in the generated file. Consider a safeguard strategy (e.g., verifying uniqueness) inimportVariable.
66-72: Handle duplicate registrations [duplicate comment].
As noted in previous reviews, repeated calls to register the same resource (physicalId) create a new variable name on every invocation. This can cause generation inconsistencies. Consider reusing existing mappings for the samephysicalIdto keep references in sync.Also applies to: 82-88, 98-104, 114-119, 129-134, 144-149, 159-164, 174-180
packages/cli/src/constructs/tcp-check-codegen.ts (1)
29-78: Re-iterate port validation concerns.Per prior feedback, there’s still no validation on lines 41–42 to ensure the
portfield is within the valid TCP range (1–65535), nor checks to confirm a valid or non-emptyhostname. Please consider adding these validations to prevent potential misconfigurations.packages/cli/src/constructs/check-group-codegen.ts (2)
28-32:doubleCheckandconcurrencyfields remain unused.
They’re declared inCheckGroupResourcebut never set inbuildCheckGroupProps, mirroring a past review comment.+ if (resource.doubleCheck !== undefined) { + builder.boolean('doubleCheck', resource.doubleCheck) + } + if (resource.concurrency !== undefined) { + builder.number('concurrency', resource.concurrency) + }
80-81: Silently swallowing errors in the catch block.
This catch block discards important error information, making debugging difficult, which has already been flagged in a prior review.- } catch (err) { - } + } catch (err) { + console.error('Failed to look up CheckGroup private locations:', err) + }
🧹 Nitpick comments (10)
packages/cli/src/sourcegen/program.ts (4)
23-38: Add docstrings or inline comments for constructor clarity.While the constructor logic is straightforward, consider adding a brief JSDoc to document the purpose of each program option. This will improve readability for future maintainers.
118-147: Consider parallelizing file writes or adding error handling.The loop in
realize()writes each file sequentially, and errors are not fully managed (e.g., retry on failure). Consider using a parallelization approach likePromise.all()or adding a fallback error handling mechanism to improve reliability and performance.
218-224: Broaden extension removal logic.Currently,
#processImportFromonly strips.tsor.jsextensions. If this code is intended to be extensible or if you expect.cjs,.mjs,.jsx, or.tsx, consider expanding this logic or making it configurable.
178-181: Clarify ImportOptions behavior when multiple fields are set.
ImportOptionshas bothrelativeToandrelativeToSelf. If both are provided, the code defaults torelativeTo. Document or assert that scenario to prevent mismatched usage.packages/cli/src/constructs/status-page-codegen.ts (2)
59-78: Consider consolidating optional property handling.The conditional blocks for optional properties follow a consistent pattern. Consider refactoring to reduce repetition using a helper function.
+ // Helper function to add optional string properties + const addOptionalString = (propName: string, value?: string) => { + if (value) { + builder.string(propName, value); + } + }; + - if (resource.customDomain) { - builder.string('customDomain', resource.customDomain) - } - - if (resource.logo) { - builder.string('logo', resource.logo) - } - - if (resource.redirectTo) { - builder.string('redirectTo', resource.redirectTo) - } - - if (resource.favicon) { - builder.string('favicon', resource.favicon) - } - - if (resource.defaultTheme) { - builder.string('defaultTheme', resource.defaultTheme) - } + addOptionalString('customDomain', resource.customDomain); + addOptionalString('logo', resource.logo); + addOptionalString('redirectTo', resource.redirectTo); + addOptionalString('favicon', resource.favicon); + addOptionalString('defaultTheme', resource.defaultTheme);
26-82: Add a method to validate resources before code generation.Consider adding a validation method to ensure the status page resource is valid before generating code. This would help catch issues early and provide better error messages.
// Add this method to the StatusPageCodegen class private validateResource(resource: StatusPageResource): void { if (!resource.name) { throw new Error(`Status page '${resource.id}' is missing a name.`); } if (!resource.url) { throw new Error(`Status page '${resource.id}' is missing a URL.`); } if (!resource.cards || resource.cards.length === 0) { throw new Error(`Status page '${resource.id}' has no cards defined.`); } // Validate each card for (const card of resource.cards) { if (!card.name) { throw new Error(`Card '${card.id}' in status page '${resource.id}' is missing a name.`); } if (!card.services || card.services.length === 0) { throw new Error(`Card '${card.id}' in status page '${resource.id}' has no services defined.`); } } } // Then call this at the beginning of gencode: // this.validateResource(resource);packages/cli/src/constructs/internal/codegen/context.ts (1)
35-58: Consider handling filename collisions and special characters.
WhilekebabCaseis a great start, if multiple resources share the same name or contain certain special characters, the generated filenames might conflict or break. You might add a uniqueness suffix or sanitize disallowed characters to avoid filesystem-level collisions.packages/cli/src/constructs/tcp-check-codegen.ts (1)
7-12: Consider enforcing non-negative response times.
degradedResponseTimeandmaxResponseTimecan be set to arbitrary numbers, including negatives. You might want to ensure these fields are either optional or strictly positive to align with domain expectations and avoid nonsensical configurations.packages/cli/src/constructs/api-check-codegen.ts (2)
14-25: Consider validating response time thresholds.Similar to the TCP check resource,
degradedResponseTimeandmaxResponseTimecan be set to arbitrary values. Consider restricting or validating them to avoid negative or clearly out-of-range inputs that could lead to confusion.
48-180: Potential opportunity to streamline script handling.The current logic for local vs. snippet scripts is correct but somewhat repetitive (e.g., lines 127–146 vs. 147–165). Consider extracting a helper function to reduce duplication and enhance maintainability.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (13)
packages/cli/src/constructs/api-check-codegen.ts(1 hunks)packages/cli/src/constructs/browser-check-codegen.ts(1 hunks)packages/cli/src/constructs/check-group-codegen.ts(1 hunks)packages/cli/src/constructs/dashboard-codegen.ts(1 hunks)packages/cli/src/constructs/heartbeat-check-codegen.ts(1 hunks)packages/cli/src/constructs/internal/codegen/context.ts(1 hunks)packages/cli/src/constructs/maintenance-window-codegen.ts(1 hunks)packages/cli/src/constructs/multi-step-check-codegen.ts(1 hunks)packages/cli/src/constructs/private-location-codegen.ts(1 hunks)packages/cli/src/constructs/status-page-codegen.ts(1 hunks)packages/cli/src/constructs/status-page-service-codegen.ts(1 hunks)packages/cli/src/constructs/tcp-check-codegen.ts(1 hunks)packages/cli/src/sourcegen/program.ts(1 hunks)
🚧 Files skipped from review as they are similar to previous changes (7)
- packages/cli/src/constructs/dashboard-codegen.ts
- packages/cli/src/constructs/heartbeat-check-codegen.ts
- packages/cli/src/constructs/status-page-service-codegen.ts
- packages/cli/src/constructs/multi-step-check-codegen.ts
- packages/cli/src/constructs/browser-check-codegen.ts
- packages/cli/src/constructs/private-location-codegen.ts
- packages/cli/src/constructs/maintenance-window-codegen.ts
🧰 Additional context used
🧬 Code Graph Analysis (5)
packages/cli/src/constructs/status-page-codegen.ts (5)
packages/cli/src/constructs/status-page-service-codegen.ts (1)
StatusPageServiceResource(4-7)packages/cli/src/constructs/status-page.ts (1)
StatusPageTheme(17-17)packages/cli/src/constructs/internal/codegen/index.ts (1)
Codegen(1-1)packages/cli/src/constructs/internal/codegen/context.ts (2)
Context(19-198)filename(35-58)packages/cli/src/sourcegen/index.ts (2)
expr(33-33)ident(34-34)
packages/cli/src/constructs/tcp-check-codegen.ts (7)
packages/cli/src/constructs/check-codegen.ts (2)
CheckResource(17-35)buildCheckProps(37-164)packages/cli/src/constructs/tcp-check.ts (2)
TcpRequest(20-46)TcpAssertion(8-8)packages/cli/src/sourcegen/index.ts (4)
GeneratedFile(40-40)Value(44-44)expr(33-33)ident(34-34)packages/cli/src/constructs/internal/codegen/index.ts (2)
Codegen(1-1)Context(2-2)packages/cli/src/sourcegen/exprbuilder.ts (1)
context(34-37)packages/cli/src/constructs/internal/codegen/context.ts (2)
Context(19-198)filename(35-58)packages/cli/src/sourcegen/identifier.ts (1)
ident(22-29)
packages/cli/src/constructs/check-group-codegen.ts (6)
packages/cli/src/constructs/frequency-codegen.ts (1)
FrequencyResource(4-4)packages/cli/src/constructs/alert-escalation-policy-codegen.ts (1)
AlertEscalationResource(4-4)packages/cli/src/constructs/api-check.ts (2)
ApiCheckDefaultConfig(71-77)headers(29-31)packages/cli/src/constructs/retry-strategy-codegen.ts (1)
RetryStrategyResource(4-4)packages/cli/src/sourcegen/index.ts (3)
Program(40-40)GeneratedFile(40-40)ObjectValueBuilder(38-38)packages/cli/src/constructs/internal/codegen/index.ts (2)
Context(2-2)Codegen(1-1)
packages/cli/src/constructs/api-check-codegen.ts (8)
packages/cli/src/constructs/check-codegen.ts (1)
CheckResource(17-35)packages/cli/src/constructs/api-check.ts (2)
Request(79-95)headers(29-31)packages/cli/src/sourcegen/index.ts (4)
GeneratedFile(40-40)Value(44-44)expr(33-33)ident(34-34)packages/cli/src/constructs/internal/assertion-codegen.ts (2)
valueForNumericAssertion(4-43)valueForGeneralAssertion(45-146)packages/cli/src/constructs/internal/codegen/index.ts (2)
Codegen(1-1)Context(2-2)packages/cli/src/sourcegen/exprbuilder.ts (1)
context(34-37)packages/cli/src/constructs/internal/codegen/context.ts (2)
Context(19-198)filename(35-58)packages/cli/src/sourcegen/identifier.ts (1)
ident(22-29)
packages/cli/src/constructs/internal/codegen/context.ts (5)
packages/cli/src/constructs/internal/codegen/index.ts (2)
MissingContextVariableMappingError(2-2)Context(2-2)packages/cli/src/sourcegen/identifier.ts (1)
IdentifierValue(5-16)packages/cli/src/sourcegen/index.ts (3)
IdentifierValue(34-34)GeneratedFile(40-40)kebabCase(14-14)packages/cli/src/sourcegen/program.ts (1)
GeneratedFile(183-270)packages/cli/src/sourcegen/case.ts (1)
kebabCase(45-47)
⏰ Context from checks skipped due to timeout of 90000ms (2)
- GitHub Check: test - windows-latest
- GitHub Check: test - ubuntu-latest
🔇 Additional comments (14)
packages/cli/src/constructs/status-page-codegen.ts (5)
1-5: Imports are well-organized and appropriately scoped.The imports provide all the necessary dependencies for the StatusPage code generation, with clear module paths and specific imports rather than using wildcards.
6-10: Interface definition for StatusPageCardResource is clean and well-structured.The interface provides a clear schema for status page cards with appropriate types for each property.
24-24: LGTM: Constant defined at module level.Good practice defining the construct name as a constant to avoid hardcoding strings in multiple places.
26-32: Class declaration and file creation look good.The
StatusPageCodegenclass properly extends theCodegenbase class with the correct type parameter. The file creation and import statement are appropriately structured.
33-39: Builder pattern implementation is clean and readable.The code uses the builder pattern effectively to construct the StatusPage instance with the required properties.
packages/cli/src/constructs/internal/codegen/context.ts (1)
7-15: Implementation forVariableLocatorlooks clear and concise.
This class effectively encapsulates an identifier and associated source file without adding unnecessary complexity.packages/cli/src/constructs/tcp-check-codegen.ts (2)
1-6: Imports look good.No issues found regarding correctness or maintainability in the import statements.
14-25: Comprehensive handling of TCP assertion sources.This function properly switches on known sources and throws for unsupported ones, which is a reliable approach. The naming and usage are also consistent with the rest of the codegen utilities.
packages/cli/src/constructs/api-check-codegen.ts (3)
1-6: Imports are well-organized.All necessary modules and types are imported from appropriate locations.
8-12: Straightforward snippet resource model.The
SnippetResourceinterface is concise and clearly structured. No issues found.
27-44: Assertion logic is consistent.All recognized assertion sources are handled with a default error fallback, which is best practice for maintaining safe and predictable behavior.
packages/cli/src/constructs/check-group-codegen.ts (3)
1-12: Imports look good.Overall, the import statements are well-structured and clear.
256-287: Final code generation logic looks solid.The class properly registers the check group in
prepare()and constructs the code ingencode()using the builder pattern. No major issues identified.
249-249:✅ Verification successful
Confirm undefined handling for
valueForRetryStrategy.If
resource.retryStrategyisundefined, this call might result in unintended output or errors depending on the implementation ofvalueForRetryStrategy. Please verify if the helper safely handlesundefined.
🏁 Script executed:
#!/bin/bash # Searching for the function definition to ensure it handles undefined reliably rg -A 10 'function valueForRetryStrategy'Length of output: 1047
Undefined handling in
valueForRetryStrategyappears to be appropriately managedThe function signature in
packages/cli/src/constructs/retry-strategy-codegen.ts
declares the parameter as optional (strategy?: RetryStrategyResource | null), which indicates that passingundefinedis an expected scenario. This suggests that the internal logic ofvalueForRetryStrategyis designed to safely handle cases whenresource.retryStrategyisundefined. If your tests also confirm that the output or default behavior is as intended whenundefinedis passed, then no further changes are required.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 4
♻️ Duplicate comments (2)
packages/cli/src/constructs/internal/codegen/context.ts (1)
147-153: Handle duplicatephysicalIdregistrations.
This is a repeat of a past suggestion to prevent generating new variables for already-registeredphysicalIds inregisterCheckGroup. Consider returning the existing locator if the map contains thephysicalId.packages/cli/src/constructs/status-page-service-codegen.ts (1)
12-21: Add validation for resource ID before registrationThe
preparemethod should validate thatresource.idexists and is non-empty before using it to register the status page service. Without validation, passing an undefined or empty ID could lead to unexpected behavior.prepare (logicalId: string, resource: StatusPageServiceResource, context: Context): void { + if (!resource.id) { + throw new Error('StatusPageServiceResource must have a valid id'); + } const filePath = context.filePath('resources/status-pages/services', resource.name, { unique: true, }) context.registerStatusPageService( resource.id, this.program.generatedConstructFile(filePath.fullPath), ) }
🧹 Nitpick comments (4)
packages/cli/src/constructs/internal/codegen/context.ts (1)
67-139: Consider addressing the constant condition flagged by static analysis in thedo { ... } while (true)loop.
Although this loop is intentional for generating unique file names, it triggers a lint warning regarding the literaltruecondition. You could address the lint error by rewriting it as awhileloop with a meaningful condition or disabling the rule if you are certain that this infinite loop pattern is your preferred approach.- } while (true) + } while (!uniqueFileFound)🧰 Tools
🪛 Biome (1.9.4)
[error] 138-138: Unexpected constant condition.
(lint/correctness/noConstantCondition)
packages/cli/src/constructs/status-page-service-codegen.ts (2)
32-34: Consider supporting additional StatusPageService propertiesThe current implementation only sets the
nameproperty, but theStatusPageServiceconstruct might support additional configuration options that could be exposed through theStatusPageServiceResourceinterface.Consider expanding the resource interface and the object builder to support other relevant properties that users might want to configure when importing status page services.
1-41: Add JSDoc comments for better code documentationThe file would benefit from JSDoc comments for the class, interface, and methods to explain their purpose, parameters, and return values. This would make the code more maintainable and easier to understand for other developers.
For example:
/** * Interface representing a Status Page Service resource to be imported */ export interface StatusPageServiceResource { /** Unique identifier of the status page service */ id: string /** Display name of the status page service */ name: string } /** * Generates code for Status Page Service resources */ export class StatusPageServiceCodegen extends Codegen<StatusPageServiceResource> { /** * Prepares the context for code generation * @param logicalId - Logical identifier for the resource * @param resource - The status page service resource * @param context - The code generation context */ prepare (logicalId: string, resource: StatusPageServiceResource, context: Context): void { // ... } // ... }packages/cli/src/constructs/maintenance-window-codegen.ts (1)
1-12: Interface design looks solid, but consider stricter date types.
Currently,startsAtandendsAtare typed as strings. This is perfectly valid in many contexts, but you might consider using more specific date-like types or validating date formats to reduce the risk of invalid values.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (12)
packages/cli/src/constructs/api-check-codegen.ts(1 hunks)packages/cli/src/constructs/browser-check-codegen.ts(1 hunks)packages/cli/src/constructs/check-group-codegen.ts(1 hunks)packages/cli/src/constructs/dashboard-codegen.ts(1 hunks)packages/cli/src/constructs/heartbeat-check-codegen.ts(1 hunks)packages/cli/src/constructs/internal/codegen/context.ts(1 hunks)packages/cli/src/constructs/maintenance-window-codegen.ts(1 hunks)packages/cli/src/constructs/multi-step-check-codegen.ts(1 hunks)packages/cli/src/constructs/private-location-codegen.ts(1 hunks)packages/cli/src/constructs/status-page-codegen.ts(1 hunks)packages/cli/src/constructs/status-page-service-codegen.ts(1 hunks)packages/cli/src/constructs/tcp-check-codegen.ts(1 hunks)
🚧 Files skipped from review as they are similar to previous changes (8)
- packages/cli/src/constructs/dashboard-codegen.ts
- packages/cli/src/constructs/multi-step-check-codegen.ts
- packages/cli/src/constructs/browser-check-codegen.ts
- packages/cli/src/constructs/private-location-codegen.ts
- packages/cli/src/constructs/tcp-check-codegen.ts
- packages/cli/src/constructs/status-page-codegen.ts
- packages/cli/src/constructs/heartbeat-check-codegen.ts
- packages/cli/src/constructs/check-group-codegen.ts
🧰 Additional context used
🧬 Code Graph Analysis (4)
packages/cli/src/constructs/maintenance-window-codegen.ts (3)
packages/cli/src/constructs/internal/codegen/index.ts (2)
Codegen(1-1)Context(2-2)packages/cli/src/constructs/internal/codegen/context.ts (2)
Context(48-279)filePath(67-139)packages/cli/src/sourcegen/index.ts (2)
expr(33-33)ident(34-34)
packages/cli/src/constructs/api-check-codegen.ts (7)
packages/cli/src/constructs/check-codegen.ts (1)
CheckResource(17-35)packages/cli/src/constructs/api-check.ts (2)
Request(79-95)headers(29-31)packages/cli/src/sourcegen/program.ts (1)
GeneratedFile(183-270)packages/cli/src/sourcegen/index.ts (4)
GeneratedFile(40-40)Value(44-44)expr(33-33)ident(34-34)packages/cli/src/constructs/internal/assertion-codegen.ts (2)
valueForNumericAssertion(4-43)valueForGeneralAssertion(45-146)packages/cli/src/constructs/internal/codegen/index.ts (2)
Codegen(1-1)Context(2-2)packages/cli/src/constructs/key-value-pair-codegen.ts (1)
valueForKeyValuePair(5-52)
packages/cli/src/constructs/status-page-service-codegen.ts (3)
packages/cli/src/constructs/internal/codegen/index.ts (1)
Codegen(1-1)packages/cli/src/constructs/internal/codegen/context.ts (2)
Context(48-279)filePath(67-139)packages/cli/src/sourcegen/index.ts (3)
decl(22-22)expr(33-33)ident(34-34)
packages/cli/src/constructs/internal/codegen/context.ts (5)
packages/cli/src/constructs/internal/codegen/index.ts (2)
MissingContextVariableMappingError(2-2)Context(2-2)packages/cli/src/sourcegen/index.ts (3)
IdentifierValue(34-34)GeneratedFile(40-40)kebabCase(14-14)packages/cli/src/sourcegen/identifier.ts (1)
IdentifierValue(5-16)packages/cli/src/sourcegen/program.ts (3)
GeneratedFile(183-270)path(113-116)dirname(157-159)packages/cli/src/sourcegen/case.ts (1)
kebabCase(45-47)
🪛 Biome (1.9.4)
packages/cli/src/constructs/internal/codegen/context.ts
[error] 138-138: Unexpected constant condition.
(lint/correctness/noConstantCondition)
⏰ Context from checks skipped due to timeout of 90000ms (2)
- GitHub Check: test - windows-latest
- GitHub Check: test - ubuntu-latest
🔇 Additional comments (7)
packages/cli/src/constructs/internal/codegen/context.ts (3)
1-4: No issues found in the import statements.
7-15: Well-structured locator class.
No issues detected with theVariableLocatordesign. The mapping of anIdentifierValueand aGeneratedFileis clear and consistent.
155-279: Overall approach appears sound.
All register/lookup methods for alert channels, private locations, check groups, and status page services are consistent in maintaining the necessary context mappings. No further issues identified.packages/cli/src/constructs/maintenance-window-codegen.ts (1)
16-70: Overall implementation is coherent and aligns with the existing code generation pattern.
Thegencodemethod correctly handles property creation and includes optional fields (repeatInterval, repeatEndsAt, etc.) in a clear, modular style. No critical issues detected.packages/cli/src/constructs/api-check-codegen.ts (3)
1-44: Good structure and assertion handling.
TheSnippetResource,ApiCheckResourceinterfaces, andvalueForAssertionfunction appear cohesive and maintain consistency with other check-related files.
48-109: Code generation logic is thorough.
The request object’s fields (URL, method, headers, etc.) are conditionally set, promoting clarity in the generated output. This approach helps avoid cluttering the final code with unused properties.
120-190: Scripts handling logic is well-structured.
Your approach for either local scripts or snippet-based scripts, including generating a separate file for each scenario, keeps the flow of code generation organized.
| importVariable (locator: VariableLocator, file: GeneratedFile): void { | ||
| file.namedImport(locator.id.value, locator.file.path, { | ||
| relativeTo: dirname(file.path), | ||
| }) | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Refactor suggestion
Check for named import collisions in importVariable.
Multiple imports could end up with the same identifier name if locator.id.value reoccurs. Consider verifying that each new import name is unique, or handle collisions gracefully to avoid potentially overwriting named imports in the generated file.
| const filePath = context.filePath('resources/status-pages/services', resource.name, { | ||
| unique: true, | ||
| }) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Refactor suggestion
Consider validating the resource name
The name property is used to generate the file path, but there's no validation to ensure it's a valid and safe value for a filename. Invalid characters in the name could potentially cause issues.
prepare (logicalId: string, resource: StatusPageServiceResource, context: Context): void {
if (!resource.id) {
throw new Error('StatusPageServiceResource must have a valid id');
}
+ if (!resource.name || resource.name.trim() === '') {
+ throw new Error('StatusPageServiceResource must have a valid name');
+ }
const filePath = context.filePath('resources/status-pages/services', resource.name, {
unique: true,
})📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| const filePath = context.filePath('resources/status-pages/services', resource.name, { | |
| unique: true, | |
| }) | |
| prepare (logicalId: string, resource: StatusPageServiceResource, context: Context): void { | |
| if (!resource.id) { | |
| throw new Error('StatusPageServiceResource must have a valid id'); | |
| } | |
| if (!resource.name || resource.name.trim() === '') { | |
| throw new Error('StatusPageServiceResource must have a valid name'); | |
| } | |
| const filePath = context.filePath('resources/status-pages/services', resource.name, { | |
| unique: true, | |
| }) | |
| // ... rest of the method | |
| } |
| gencode (logicalId: string, resource: StatusPageServiceResource, context: Context): void { | ||
| const { id, file } = context.lookupStatusPageService(resource.id) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Refactor suggestion
Validate resource ID before lookup
Similar to the prepare method, you should validate resource.id before calling lookupStatusPageService to prevent potential errors when looking up a service with an empty or undefined ID.
gencode (logicalId: string, resource: StatusPageServiceResource, context: Context): void {
+ if (!resource.id) {
+ throw new Error('StatusPageServiceResource must have a valid id');
+ }
const { id, file } = context.lookupStatusPageService(resource.id)📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| gencode (logicalId: string, resource: StatusPageServiceResource, context: Context): void { | |
| const { id, file } = context.lookupStatusPageService(resource.id) | |
| gencode (logicalId: string, resource: StatusPageServiceResource, context: Context): void { | |
| if (!resource.id) { | |
| throw new Error('StatusPageServiceResource must have a valid id'); | |
| } | |
| const { id, file } = context.lookupStatusPageService(resource.id) |
This comment has been minimized.
This comment has been minimized.
0c53741 to
979484b
Compare
Previously you'd be shown a select with no options.
The process is explained along the way. Explanations are shared between commands.
Auto complete still works for known values. Values that are not known can still be entered. Useful because the UI supports some icon types that the CLI type has not been updated for.
f993c12 to
cfbb25b
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 1
♻️ Duplicate comments (7)
packages/cli/src/sourcegen/case.ts (1)
77-121:wordifystill lacks documentation & edge-case testsA previous review already asked for JSDoc and unit tests covering tricky inputs (empty strings, all-caps acronyms like
HTTPRequest, numeric-only strings, special-character separators, etc.). These are important to guarantee the correctness of every downstream case-conversion helper that relies onwordify.Consider:
- Adding a concise JSDoc comment describing the splitting rules.
- Extending
case.spec.tswith the missing edge-cases.This will make future maintenance easier and prevent silent regressions.
🧰 Tools
🪛 Biome (1.9.4)
[error] 112-112: Unnecessary continue statement
Unsafe fix: Delete the unnecessary continue statement
(lint/correctness/noUnnecessaryContinue)
packages/cli/src/services/checkly-config-codegen.ts (1)
70-81: Logical-ID alert-channel references still unsupportedAs previously flagged in the
alert-channel-codegenreview, generation bails out unlessalertChannel.physicalIdis a number. Users often reference alert channels by logical ID inside the same project, so this will break legitimate configs.Either resolve the logical ID via the
Contextor emit a clearer message guiding the user to import/define the channel first.packages/cli/src/constructs/internal/codegen/context.ts (5)
148-152: 🛠️ Refactor suggestionPrevent named import collisions.
The
importVariablemethod useslocator.id.valuedirectly without checking for potential collisions in the named imports. Multiple imports could end up with the same identifier name if different locators happen to have the same ID value.Apply this change to track and ensure uniqueness of imported variable names:
importVariable (locator: VariableLocator, file: GeneratedFile): void { + // Keep track of imported variables to avoid name collisions + if (!file.hasNamedImport(locator.id.value, locator.file.path)) { file.namedImport(locator.id.value, locator.file.path, { relativeTo: dirname(file.path), }) + } }This assumes adding a
hasNamedImportmethod toGeneratedFileclass, or you could alternatively implement the tracking directly within theContextclass.
154-160: 🛠️ Refactor suggestionHandle duplicate registrations in check group registration.
The method lacks a check for existing mappings, which could lead to inconsistencies when the same physical ID is registered multiple times.
Apply this change to reuse existing variable locators:
registerCheckGroup (physicalId: number, file: GeneratedFile): VariableLocator { + if (this.#checkGroupVariablesByPhysicalId.has(physicalId)) { + return this.#checkGroupVariablesByPhysicalId.get(physicalId)! + } const nth = this.#checkGroupVariablesByPhysicalId.size + 1 const id = new IdentifierValue(`group${nth}`) const locator = new VariableLocator(id, file) this.#checkGroupVariablesByPhysicalId.set(physicalId, locator) return locator }
170-176: 🛠️ Refactor suggestionHandle duplicate registrations in alert channel registration.
The method lacks a check for existing mappings, which could lead to inconsistencies when the same physical ID is registered multiple times.
Apply this change to reuse existing variable locators:
registerAlertChannel (physicalId: number, variablePrefix: string, file: GeneratedFile): VariableLocator { + if (this.#alertChannelVariablesByPhysicalId.has(physicalId)) { + return this.#alertChannelVariablesByPhysicalId.get(physicalId)! + } const nth = this.#alertChannelVariablesByPhysicalId.size + 1 const id = new IdentifierValue(`${variablePrefix}${nth}`) const locator = new VariableLocator(id, file) this.#alertChannelVariablesByPhysicalId.set(physicalId, locator) return locator }
186-192: 🛠️ Refactor suggestionHandle duplicate registrations in private location registration.
The method lacks a check for existing mappings, which could lead to inconsistencies when the same physical ID is registered multiple times.
Apply this change to reuse existing variable locators:
registerPrivateLocation (physicalId: string, file: GeneratedFile): VariableLocator { + if (this.#privateLocationVariablesByPhysicalId.has(physicalId)) { + return this.#privateLocationVariablesByPhysicalId.get(physicalId)! + } const nth = this.#privateLocationVariablesByPhysicalId.size + 1 const id = new IdentifierValue(`privateLocation${nth}`) const locator = new VariableLocator(id, file) this.#privateLocationVariablesByPhysicalId.set(physicalId, locator) return locator }
262-268: 🛠️ Refactor suggestionHandle duplicate registrations in status page service registration.
The method lacks a check for existing mappings, which could lead to inconsistencies when the same physical ID is registered multiple times.
Apply this change to reuse existing variable locators:
registerStatusPageService (physicalId: string, file: GeneratedFile): VariableLocator { + if (this.#statusPageServiceVariablesByPhysicalId.has(physicalId)) { + return this.#statusPageServiceVariablesByPhysicalId.get(physicalId)! + } const nth = this.#statusPageServiceVariablesByPhysicalId.size + 1 const id = new IdentifierValue(`service${nth}`) const locator = new VariableLocator(id, file) this.#statusPageServiceVariablesByPhysicalId.set(physicalId, locator) return locator }
🧹 Nitpick comments (8)
packages/cli/src/sourcegen/case.ts (1)
108-113: Remove redundantcontinueto silence linter & reduce noiseBiome already flags this
continueas unnecessary because control flow naturally loops back after theif-block. Dropping it keeps the code terser and avoids future lint suppressions.- word = '' - small = false - continue + word = '' + small = false🧰 Tools
🪛 Biome (1.9.4)
[error] 112-112: Unnecessary continue statement
Unsafe fix: Delete the unnecessary continue statement
(lint/correctness/noUnnecessaryContinue)
packages/cli/src/constructs/alert-channel-subscription-codegen.ts (2)
10-12: Mark unused param indescribeto satisfy linters
resourceis not referenced insidedescribe.
Either prefix it with an underscore or remove it to avoid the “unused variable” warning:- describe (resource: AlertChannelSubscriptionResource): string { + // `resource` isn’t needed for the static label – mark it intentionally unused + // eslint-disable-next-line @typescript-eslint/no-unused-vars + describe (_resource: AlertChannelSubscriptionResource): string {🧰 Tools
🪛 GitHub Check: lint
[warning] 10-10:
'resource' is defined but never used
14-22: Validate that exactly one ofcheckIdorgroupIdis providedRight now the code happily accepts:
- both properties (
checkId+groupId) – ambiguous;- or neither property – a no-op subscription.
Add a guard to enforce the expected invariant and surface a helpful error:
prepare (logicalId: string, resource: AlertChannelSubscriptionResource, context: Context): void { + const hasCheck = resource.checkId !== undefined + const hasGroup = resource.groupId !== undefined + + if (hasCheck === hasGroup) { // both or neither + throw new Error( + `AlertChannelSubscription '${logicalId}' must reference exactly one of 'checkId' or 'groupId'.`, + ) + } + if (resource.checkId !== undefined) { context.registerAlertChannelCheckSubscription(resource.alertChannelId, resource.checkId) }packages/cli/src/services/check-parser/package-files/package-json-file.ts (2)
70-90:upsertDependencies/upsertDevDependenciesshare identical logic – extract common helperBoth methods differ only by the target field. Duplicating the same update-&-sort sequence increases maintenance overhead and the chance of diverging behaviour.
A small refactor could unify them:
- upsertDependencies (dependencies: Record<string, string>): boolean { - const result = updateDependencies(this.jsonFile.data.dependencies, dependencies) + #upsert (field: 'dependencies' | 'devDependencies', deps: Record<string, string>): boolean { + const result = updateDependencies(this.jsonFile.data[field], deps) if (!result.changed) { return false } - - this.jsonFile.data.dependencies = sortDependencies(result.dependencies) + this.jsonFile.data[field] = sortDependencies(result.dependencies) return true } - - upsertDevDependencies (dependencies: Record<string, string>): boolean { - const result = updateDependencies(this.jsonFile.data.devDependencies, dependencies) - ... - } + upsertDependencies (deps: Record<string, string>): boolean { + return this.#upsert('dependencies', deps) + } + + upsertDevDependencies (deps: Record<string, string>): boolean { + return this.#upsert('devDependencies', deps) + }Keeps behaviour identical while reducing duplication.
97-136: Gracefully handle unparsable new semver ranges
updateDependenciesthrows ifnewVersionfailssemver.minVersion. A malformed range would therefore crash the entire import flow instead of simply skipping the bad entry and reporting it.Consider returning
{ changed: false }for that dependency and logging a warning instead of a hard error. This prevents one bad version string from aborting an otherwise valid update.packages/cli/src/constructs/internal/codegen/context.ts (3)
145-146: Add a breaking condition to prevent potential infinite loops.The current implementation uses an infinite loop with
while (true)which is flagged by static analysis. While there is a return path, adding an explicit breaking condition would make the code more robust.- // eslint-disable-next-line no-constant-condition - } while (true) + // Add a safety limit to prevent infinite loops + const maxAttempts = 1000 + counter++ + } while (counter < maxAttempts) + + // If we reached this point, we couldn't find a suitable filename + throw new Error(`Couldn't generate a unique file path for ${hint} after ${maxAttempts} attempts`)🧰 Tools
🪛 Biome (1.9.4)
[error] 145-145: Unexpected constant condition.
(lint/correctness/noConstantCondition)
296-323: Consider optimizing the snippet file matching logic.The current implementation tries multiple variations of filenames when finding script snippet files. This approach might be brittle if naming conventions change.
Consider normalizing filenames during registration and lookup to reduce the complexity of matching. For example, you could store normalized keys (without extensions) and use them for lookups.
registerAuxiliarySnippetFile (physicalId: number, snippetFile: ProgramFile) { this.#auxiliarySnippetFilesByPhysicalId.set(physicalId, snippetFile) + // Store with normalized keys for easier lookup this.#auxiliarySnippetFilesByFilename.set(snippetFile.basename, snippetFile) + const normalizedName = path.parse(snippetFile.basename).name + if (!this.#auxiliarySnippetFilesByFilename.has(normalizedName)) { + this.#auxiliarySnippetFilesByFilename.set(normalizedName, snippetFile) + } }Then you could simplify the
findScriptSnippetFilesmethod to reduce the number of lookups.
73-146: Add documentation for the file path generation logic.The
filePathmethod contains complex logic for generating unique file paths with various options. Adding documentation for each parameter and how they affect the generated path would make this code more maintainable.Consider adding JSDoc comments that explain:
- What each option does (tags, isolate, unique, contentKey, case)
- How the content key is used to differentiate files
- How uniqueness is enforced
- What the return value represents
🧰 Tools
🪛 Biome (1.9.4)
[error] 145-145: Unexpected constant condition.
(lint/correctness/noConstantCondition)
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
⛔ Files ignored due to path filters (1)
package-lock.jsonis excluded by!**/package-lock.json
📒 Files selected for processing (98)
packages/cli/e2e/__tests__/help.spec.ts(2 hunks)packages/cli/package.json(6 hunks)packages/cli/src/commands/baseCommand.ts(2 hunks)packages/cli/src/commands/import/apply.ts(1 hunks)packages/cli/src/commands/import/cancel.ts(1 hunks)packages/cli/src/commands/import/commit.ts(1 hunks)packages/cli/src/commands/import/plan.ts(1 hunks)packages/cli/src/constructs/__tests__/alert-channel.spec.ts(1 hunks)packages/cli/src/constructs/__tests__/check-group.spec.ts(1 hunks)packages/cli/src/constructs/__tests__/private-location.spec.ts(1 hunks)packages/cli/src/constructs/__tests__/status-page-service.spec.ts(1 hunks)packages/cli/src/constructs/alert-channel-codegen.ts(1 hunks)packages/cli/src/constructs/alert-channel-subscription-codegen.ts(1 hunks)packages/cli/src/constructs/alert-channel.ts(2 hunks)packages/cli/src/constructs/alert-escalation-policy-codegen.ts(1 hunks)packages/cli/src/constructs/api-check-codegen.ts(1 hunks)packages/cli/src/constructs/browser-check-codegen.ts(1 hunks)packages/cli/src/constructs/check-codegen.ts(1 hunks)packages/cli/src/constructs/check-group-codegen.ts(1 hunks)packages/cli/src/constructs/check-group.ts(6 hunks)packages/cli/src/constructs/check.ts(4 hunks)packages/cli/src/constructs/construct-codegen.ts(1 hunks)packages/cli/src/constructs/dashboard-codegen.ts(1 hunks)packages/cli/src/constructs/email-alert-channel-codegen.ts(1 hunks)packages/cli/src/constructs/frequency-codegen.ts(1 hunks)packages/cli/src/constructs/heartbeat-check-codegen.ts(1 hunks)packages/cli/src/constructs/incidentio-alert-channel-codegen.ts(1 hunks)packages/cli/src/constructs/incidentio-alert-channel.ts(3 hunks)packages/cli/src/constructs/internal/assertion-codegen.ts(1 hunks)packages/cli/src/constructs/internal/codegen/codegen.ts(1 hunks)packages/cli/src/constructs/internal/codegen/context.ts(1 hunks)packages/cli/src/constructs/internal/codegen/index.ts(1 hunks)packages/cli/src/constructs/internal/codegen/safety.ts(1 hunks)packages/cli/src/constructs/internal/codegen/snippet.ts(1 hunks)packages/cli/src/constructs/key-value-pair-codegen.ts(1 hunks)packages/cli/src/constructs/maintenance-window-codegen.ts(1 hunks)packages/cli/src/constructs/msteams-alert-channel-codegen.ts(1 hunks)packages/cli/src/constructs/msteams-alert-channel.ts(3 hunks)packages/cli/src/constructs/multi-step-check-codegen.ts(1 hunks)packages/cli/src/constructs/opsgenie-alert-channel-codegen.ts(1 hunks)packages/cli/src/constructs/pagerduty-alert-channel-codegen.ts(1 hunks)packages/cli/src/constructs/phone-call-alert-channel-codegen.ts(1 hunks)packages/cli/src/constructs/playwright-config-codegen.ts(1 hunks)packages/cli/src/constructs/playwright-config.ts(0 hunks)packages/cli/src/constructs/private-location-check-assignment-codegen.ts(1 hunks)packages/cli/src/constructs/private-location-codegen.ts(1 hunks)packages/cli/src/constructs/private-location-group-assignment-codegen.ts(1 hunks)packages/cli/src/constructs/private-location.ts(3 hunks)packages/cli/src/constructs/project.ts(1 hunks)packages/cli/src/constructs/ref-codegen.ts(1 hunks)packages/cli/src/constructs/retry-strategy-codegen.ts(1 hunks)packages/cli/src/constructs/slack-alert-channel-codegen.ts(1 hunks)packages/cli/src/constructs/sms-alert-channel-codegen.ts(1 hunks)packages/cli/src/constructs/status-page-codegen.ts(1 hunks)packages/cli/src/constructs/status-page-service-codegen.ts(1 hunks)packages/cli/src/constructs/status-page-service.ts(2 hunks)packages/cli/src/constructs/tcp-check-codegen.ts(1 hunks)packages/cli/src/constructs/telegram-alert-channel-codegen.ts(1 hunks)packages/cli/src/constructs/telegram-alert-channel.ts(3 hunks)packages/cli/src/constructs/webhook-alert-channel-codegen.ts(1 hunks)packages/cli/src/helpers/command-style.ts(1 hunks)packages/cli/src/helpers/wrap.ts(1 hunks)packages/cli/src/rest/projects.ts(5 hunks)packages/cli/src/services/check-parser/package-files/__tests__/package-json-file.spec.ts(1 hunks)packages/cli/src/services/check-parser/package-files/json-source-file.ts(1 hunks)packages/cli/src/services/check-parser/package-files/package-json-file.ts(2 hunks)packages/cli/src/services/check-parser/package-files/package-manager.ts(1 hunks)packages/cli/src/services/check-parser/package-files/resolver.ts(1 hunks)packages/cli/src/services/check-parser/package-files/source-file.ts(1 hunks)packages/cli/src/services/check-parser/parser.ts(1 hunks)packages/cli/src/services/checkly-config-codegen.ts(1 hunks)packages/cli/src/services/checkly-config-loader.ts(2 hunks)packages/cli/src/sourcegen/__tests__/case.spec.ts(1 hunks)packages/cli/src/sourcegen/args.ts(1 hunks)packages/cli/src/sourcegen/argsbuilder.ts(1 hunks)packages/cli/src/sourcegen/array.ts(1 hunks)packages/cli/src/sourcegen/arraybuilder.ts(1 hunks)packages/cli/src/sourcegen/boolean.ts(1 hunks)packages/cli/src/sourcegen/case.ts(1 hunks)packages/cli/src/sourcegen/comment.ts(1 hunks)packages/cli/src/sourcegen/decl.ts(1 hunks)packages/cli/src/sourcegen/declbuilder.ts(1 hunks)packages/cli/src/sourcegen/expr.ts(1 hunks)packages/cli/src/sourcegen/exprbuilder.ts(1 hunks)packages/cli/src/sourcegen/identifier.ts(1 hunks)packages/cli/src/sourcegen/index.ts(1 hunks)packages/cli/src/sourcegen/null.ts(1 hunks)packages/cli/src/sourcegen/number.ts(1 hunks)packages/cli/src/sourcegen/object.ts(1 hunks)packages/cli/src/sourcegen/objectbuilder.ts(1 hunks)packages/cli/src/sourcegen/output.ts(1 hunks)packages/cli/src/sourcegen/program.ts(1 hunks)packages/cli/src/sourcegen/string.ts(1 hunks)packages/cli/src/sourcegen/undefined.ts(1 hunks)packages/cli/src/sourcegen/unknown.ts(1 hunks)packages/cli/src/sourcegen/value.ts(1 hunks)packages/cli/src/util/index.ts(1 hunks)packages/cli/tsconfig.json(2 hunks)
💤 Files with no reviewable changes (1)
- packages/cli/src/constructs/playwright-config.ts
✅ Files skipped from review due to trivial changes (2)
- packages/cli/src/constructs/tests/check-group.spec.ts
- packages/cli/src/constructs/tests/private-location.spec.ts
🚧 Files skipped from review as they are similar to previous changes (86)
- packages/cli/src/constructs/tests/alert-channel.spec.ts
- packages/cli/tsconfig.json
- packages/cli/src/commands/baseCommand.ts
- packages/cli/src/sourcegen/null.ts
- packages/cli/src/services/check-parser/package-files/source-file.ts
- packages/cli/src/constructs/internal/codegen/safety.ts
- packages/cli/src/sourcegen/undefined.ts
- packages/cli/src/services/check-parser/package-files/json-source-file.ts
- packages/cli/src/sourcegen/boolean.ts
- packages/cli/e2e/tests/help.spec.ts
- packages/cli/src/sourcegen/args.ts
- packages/cli/src/constructs/ref-codegen.ts
- packages/cli/src/services/checkly-config-loader.ts
- packages/cli/src/sourcegen/unknown.ts
- packages/cli/src/constructs/incidentio-alert-channel.ts
- packages/cli/src/services/check-parser/package-files/tests/package-json-file.spec.ts
- packages/cli/src/constructs/playwright-config-codegen.ts
- packages/cli/src/constructs/project.ts
- packages/cli/src/services/check-parser/parser.ts
- packages/cli/src/sourcegen/identifier.ts
- packages/cli/src/constructs/status-page-service.ts
- packages/cli/src/sourcegen/number.ts
- packages/cli/src/sourcegen/array.ts
- packages/cli/src/helpers/wrap.ts
- packages/cli/src/constructs/frequency-codegen.ts
- packages/cli/src/sourcegen/tests/case.spec.ts
- packages/cli/src/constructs/internal/codegen/index.ts
- packages/cli/src/constructs/telegram-alert-channel.ts
- packages/cli/src/sourcegen/value.ts
- packages/cli/src/constructs/tests/status-page-service.spec.ts
- packages/cli/src/util/index.ts
- packages/cli/src/constructs/private-location.ts
- packages/cli/src/sourcegen/string.ts
- packages/cli/src/sourcegen/output.ts
- packages/cli/src/constructs/alert-channel-codegen.ts
- packages/cli/package.json
- packages/cli/src/constructs/internal/codegen/codegen.ts
- packages/cli/src/constructs/dashboard-codegen.ts
- packages/cli/src/constructs/private-location-check-assignment-codegen.ts
- packages/cli/src/helpers/command-style.ts
- packages/cli/src/constructs/internal/assertion-codegen.ts
- packages/cli/src/constructs/msteams-alert-channel.ts
- packages/cli/src/constructs/key-value-pair-codegen.ts
- packages/cli/src/constructs/private-location-group-assignment-codegen.ts
- packages/cli/src/constructs/maintenance-window-codegen.ts
- packages/cli/src/commands/import/cancel.ts
- packages/cli/src/constructs/heartbeat-check-codegen.ts
- packages/cli/src/constructs/check.ts
- packages/cli/src/constructs/telegram-alert-channel-codegen.ts
- packages/cli/src/constructs/phone-call-alert-channel-codegen.ts
- packages/cli/src/constructs/alert-escalation-policy-codegen.ts
- packages/cli/src/services/check-parser/package-files/resolver.ts
- packages/cli/src/constructs/sms-alert-channel-codegen.ts
- packages/cli/src/constructs/slack-alert-channel-codegen.ts
- packages/cli/src/constructs/alert-channel.ts
- packages/cli/src/constructs/status-page-codegen.ts
- packages/cli/src/constructs/construct-codegen.ts
- packages/cli/src/sourcegen/comment.ts
- packages/cli/src/constructs/status-page-service-codegen.ts
- packages/cli/src/constructs/multi-step-check-codegen.ts
- packages/cli/src/constructs/email-alert-channel-codegen.ts
- packages/cli/src/constructs/retry-strategy-codegen.ts
- packages/cli/src/constructs/api-check-codegen.ts
- packages/cli/src/constructs/opsgenie-alert-channel-codegen.ts
- packages/cli/src/sourcegen/index.ts
- packages/cli/src/constructs/check-codegen.ts
- packages/cli/src/sourcegen/declbuilder.ts
- packages/cli/src/commands/import/commit.ts
- packages/cli/src/constructs/browser-check-codegen.ts
- packages/cli/src/sourcegen/expr.ts
- packages/cli/src/commands/import/apply.ts
- packages/cli/src/sourcegen/decl.ts
- packages/cli/src/constructs/tcp-check-codegen.ts
- packages/cli/src/sourcegen/object.ts
- packages/cli/src/sourcegen/exprbuilder.ts
- packages/cli/src/constructs/pagerduty-alert-channel-codegen.ts
- packages/cli/src/constructs/private-location-codegen.ts
- packages/cli/src/constructs/incidentio-alert-channel-codegen.ts
- packages/cli/src/constructs/internal/codegen/snippet.ts
- packages/cli/src/constructs/webhook-alert-channel-codegen.ts
- packages/cli/src/sourcegen/arraybuilder.ts
- packages/cli/src/sourcegen/argsbuilder.ts
- packages/cli/src/constructs/msteams-alert-channel-codegen.ts
- packages/cli/src/constructs/check-group.ts
- packages/cli/src/sourcegen/objectbuilder.ts
- packages/cli/src/sourcegen/program.ts
🧰 Additional context used
🧠 Learnings (1)
packages/cli/src/commands/import/plan.ts (1)
Learnt from: sorccu
PR: checkly/checkly-cli#1045
File: packages/cli/src/commands/import/plan.ts:865-896
Timestamp: 2025-05-08T23:24:10.668Z
Learning: In the `parseFilter` function of the import command, filter specifications without a colon are valid and represent filtering for all resources of the specified type (without filtering by ID).
🧬 Code Graph Analysis (1)
packages/cli/src/constructs/internal/codegen/context.ts (5)
packages/cli/src/constructs/internal/codegen/index.ts (2)
MissingContextVariableMappingError(2-2)Context(2-2)packages/cli/src/sourcegen/index.ts (4)
IdentifierValue(44-44)GeneratedFile(50-50)CaseFormat(8-8)cased(7-7)packages/cli/src/sourcegen/identifier.ts (1)
IdentifierValue(5-16)packages/cli/src/sourcegen/program.ts (3)
GeneratedFile(194-292)path(120-123)dirname(168-170)packages/cli/src/constructs/internal/codegen/snippet.ts (1)
parseSnippetDependencies(46-59)
🪛 Biome (1.9.4)
packages/cli/src/commands/import/plan.ts
[error] 583-583: Useless case clause.
because the default clause is present:
Unsafe fix: Remove the useless case.
(lint/complexity/noUselessSwitchCase)
[error] 926-926: Useless case clause.
because the default clause is present:
Unsafe fix: Remove the useless case.
(lint/complexity/noUselessSwitchCase)
[error] 1139-1139: Useless case clause.
because the default clause is present:
Unsafe fix: Remove the useless case.
(lint/complexity/noUselessSwitchCase)
[error] 1227-1227: Useless case clause.
because the default clause is present:
Unsafe fix: Remove the useless case.
(lint/complexity/noUselessSwitchCase)
packages/cli/src/services/check-parser/package-files/package-manager.ts
[error] 378-378: Unnecessary continue statement
Unsafe fix: Delete the unnecessary continue statement
(lint/correctness/noUnnecessaryContinue)
packages/cli/src/constructs/internal/codegen/context.ts
[error] 145-145: Unexpected constant condition.
(lint/correctness/noConstantCondition)
packages/cli/src/sourcegen/case.ts
[error] 112-112: Unnecessary continue statement
Unsafe fix: Delete the unnecessary continue statement
(lint/correctness/noUnnecessaryContinue)
🪛 GitHub Check: lint
packages/cli/src/constructs/alert-channel-subscription-codegen.ts
[warning] 10-10:
'resource' is defined but never used
⏰ Context from checks skipped due to timeout of 90000ms (2)
- GitHub Check: test - windows-latest
- GitHub Check: test - ubuntu-latest
🔇 Additional comments (9)
packages/cli/src/commands/import/plan.ts (4)
202-208: Wrap debug-file write intry/catchto avoid crashing on I/O errorsIf the user passes
--debug-import-planand thefs.writeFilefails (e.g. path not writable) the command will reject before reaching the surroundingtry/catchfurther below, causing an unhandled rejection and an ugly stack-trace.
Protect the UX with a dedicated guard:-const output = JSON.stringify(plan, null, 2) -await fs.writeFile(debugImportPlanOutputFile, output, 'utf8') -this.style.shortSuccess( - `Successfully wrote debug import plan to "${debugImportPlanOutputFile}".`, -) +try { + const output = JSON.stringify(plan, null, 2) + await fs.writeFile(debugImportPlanOutputFile, output, 'utf8') + this.style.shortSuccess( + `Successfully wrote debug import plan to "${debugImportPlanOutputFile}".`, + ) +} catch (err) { + this.style.longError( + `Failed to write the debug import plan to "${debugImportPlanOutputFile}".`, + (err as Error).message, + ) + this.cancelAndExit() +}[ suggest_essential_refactor ]
942-946:resourcesmay beundefined, leading to a crash
plan.changes?.resourcesis optional in the API contract.
If the backend returns a plan that only contains auxiliary files, the destructuring here assignsundefinedtoresources, yet later code blindly passes it tosortResourcesand iterates over it – throwingTypeError: undefined is not iterable.-const { resources, auxiliary } = plan.changes +const { resources = [], auxiliary } = plan.changesAlso guard calls to
sortResourcesand the two loops below withif (resources.length) { … }.
This prevents the command from terminating before the user can retry.
[ raise_critical_issue ]
1015-1019: Type-safety & null-safety – stop usinganyfor resourcesCasting to
anydefeats the purpose of TypeScript and masks real errors.
Now that you already normaliseresourcesto an array, introduce a proper interface and drop the casts:-interface FailedResource { - resource: ResourceSync - cause: Error -} - -type Resource = ResourceSync // give it a shorter alias -sortResources(resources as any) +sortResources(resources) -for (const resource of resources) { - codegen.prepare(resource.logicalId, resource as any, context) +for (const resource of resources) { + codegen.prepare(resource.logicalId, resource, context) }Same for the
gencodeloop.
[ suggest_essential_refactor ]
193-273: Potential infinite retry loop – add an escape hatch
while (true)keeps recreating plans until every resource succeeds.
If a non-recoverable failure occurs (e.g. unsupported resource type) the loop can run forever, forcing users toCtrl-C.
Consider:
- Limiting the number of retries (e.g.
maxRetries = 3)- Aborting when
failures.lengthdoes not shrink between iterations- Offering a “give up” prompt in
#confirmRetryWithoutFailedThe UX will feel much safer.
[ duplicate_comment ][ suggest_optional_refactor ]packages/cli/src/services/check-parser/package-files/package-manager.ts (2)
276-281:detectPresenceawaits nothing – detection always “succeeds”
lookupPathis asynchronous, yet the result isn’t awaited.
ConsequentlyfoundPathis always aPromise, neverundefined, so the method never throws and every detector reports a false positive.-async detectPresence (executable: string): Promise<void> { - const foundPath = this.lookupPath(executable) - if (foundPath === undefined) { - throw new NotDetectedError() - } +async detectPresence (executable: string): Promise<void> { + const foundPath = await this.lookupPath(executable) + if (foundPath === undefined) { + throw new NotDetectedError() + } }Without this fix the CLI may assume a package manager exists and emit commands that fail at runtime.
[ raise_critical_issue ]
372-380: Nit: unnecessarycontinueInside the
for…ofloop youcontinueimmediately after thecatch, but the next iteration starts automatically.
Removing thecontinuesimplifies the flow without changing behaviour.
[ suggest_nitpick ]🧰 Tools
🪛 Biome (1.9.4)
[error] 378-378: Unnecessary continue statement
Unsafe fix: Delete the unnecessary continue statement
(lint/correctness/noUnnecessaryContinue)
packages/cli/src/rest/projects.ts (1)
153-160:listImportPlanslacks the error handling you added elsewhere
get,deleteProject, andfindImportPlansall translate 404s intoProjectNotFoundError, butlistImportPlansreturns the raw Axios promise.
For API consistency and to avoid leaking Axios errors to callers, wrap it like the others (example shown):- listImportPlans ({ onlyUnapplied = false, onlyUncommitted = false } = {}) { - return this.api.get<ImportPlan[]>('/next/projects/imports', { + async listImportPlans ({ onlyUnapplied = false, onlyUncommitted = false } = {}) { + try { + return await this.api.get<ImportPlan[]>('/next/projects/imports', { params: { onlyUnapplied, onlyUncommitted }, }) + } catch (err) { + if (isAxiosError(err) && err.response?.status === 404) { + throw new ProjectNotFoundError() + } + throw err + } }[ duplicate_comment ]
packages/cli/src/constructs/check-group-codegen.ts (2)
54-77:doubleCheckandconcurrencyare still not emittedThe resource interface exposes
doubleCheckandconcurrency, butbuildCheckGroupPropsomits them, so the generated construct will silently ignore these settings.if (resource.muted !== undefined) { builder.boolean('muted', resource.muted) } + if (resource.doubleCheck !== undefined) { + builder.boolean('doubleCheck', resource.doubleCheck) + } + + if (resource.concurrency !== undefined) { + builder.number('concurrency', resource.concurrency) + }This was raised previously but remains unfixed.
[ duplicate_comment ]
257-257: Guard againstundefinedwhen emittingretryStrategyWhen
resource.retryStrategyisundefinedthis line writesretryStrategy: undefined, producing invalid TypeScript and breakingtsc.
Wrap the emission in a conditional:-if (resource.retryStrategy !== undefined) { - builder.value('retryStrategy', valueForRetryStrategy(genfile, resource.retryStrategy)) -} +if (resource.retryStrategy !== undefined) { + builder.value('retryStrategy', valueForRetryStrategy(genfile, resource.retryStrategy)) +}[ duplicate_comment ]
| if (location.physicalId !== undefined && typeof location.physicalId === 'string') { | ||
| builder.value(valueForPrivateLocationFromId(file, location.physicalId)) | ||
| continue | ||
| } | ||
|
|
||
| throw new Error(`Unable to generate configuration code for Private Location '${location.logicalId}'`) | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add support for logical-ID private-location references
Similar to alert channels, this block only accepts a string physicalId. If users supply an object with logicalId, an exception is thrown, stopping config generation even though the location exists in the project graph.
Proposed approach:
- Look up the location in
contextwhen onlylogicalIdis present. - Fallback to the error if it truly cannot be resolved.
- if (location.physicalId !== undefined && typeof location.physicalId === 'string') {
- builder.value(valueForPrivateLocationFromId(file, location.physicalId))
- continue
- }
+ if (typeof location.physicalId === 'string') {
+ builder.value(valueForPrivateLocationFromId(file, location.physicalId))
+ continue
+ }
+
+ if (location.logicalId !== undefined) {
+ const id = context.lookupPrivateLocationId(location.logicalId)
+ if (id !== undefined) {
+ builder.value(valueForPrivateLocationFromId(file, id))
+ continue
+ }
+ }This keeps the happy path seamless for users who work with logical identifiers.
Committable suggestion skipped: line range outside the PR's diff.
🤖 Prompt for AI Agents
In packages/cli/src/services/checkly-config-codegen.ts around lines 93 to 99,
the code only handles private locations with a string physicalId and throws an
error if only a logicalId is provided. To fix this, add logic to check if
location.logicalId exists when physicalId is not a string, then look up the
corresponding location in the context using that logicalId. If the lookup
succeeds, generate the configuration code using the found location; otherwise,
throw the existing error. This will support logical-ID references without
breaking config generation.
See CodeRabbit's comment below, it is a decent description. Copied here:
Affected Components
Notes for the Reviewer
New Dependency Submission