-
Notifications
You must be signed in to change notification settings - Fork 258
feat(cli): Add si change-set review command
#8297
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
Merged
+306
−2
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,192 @@ | ||
| /** | ||
| * Change Set Review Module - Review all changes in a change set | ||
| * | ||
| * This module provides functionality to review all component changes in a | ||
| * change set, showing attribute diffs and subscription sources. | ||
| * | ||
| * @module | ||
| */ | ||
|
|
||
| import { ChangeSetsApi } from "@systeminit/api-client"; | ||
| import { Context } from "../context.ts"; | ||
| import { resolveChangeSet } from "./utils.ts"; | ||
| import type { ChangeSetReviewOptions } from "./types.ts"; | ||
|
|
||
| export type { ChangeSetReviewOptions }; | ||
|
|
||
| /** | ||
| * Main entry point for the change-set review command | ||
| */ | ||
| export async function callChangeSetReview( | ||
| options: ChangeSetReviewOptions, | ||
| ): Promise<void> { | ||
| const ctx = Context.instance(); | ||
|
|
||
| try { | ||
| const apiConfig = Context.apiConfig(); | ||
| const workspaceId = Context.workspaceId(); | ||
|
|
||
| ctx.logger.info("Fetching change set review..."); | ||
|
|
||
| // Resolve change set ID from name or ID | ||
| const changeSetId = await resolveChangeSet( | ||
| workspaceId, | ||
| options.changeSetIdOrName, | ||
| ); | ||
|
|
||
| const changeSetsApi = new ChangeSetsApi(apiConfig); | ||
|
|
||
| const response = await changeSetsApi.reviewChangeSet({ | ||
| workspaceId, | ||
| changeSetId, | ||
| includeResourceDiff: options.includeResourceDiff || false, | ||
| }); | ||
|
|
||
| const reviewData = response.data; | ||
|
|
||
| // Handle building response (202) - check for status field | ||
| if ("status" in reviewData && reviewData.status === "building") { | ||
| const buildingData = reviewData as unknown as { | ||
| status: string; | ||
| message: string; | ||
| retryAfterSeconds: number; | ||
| estimatedCompletionSeconds: number; | ||
| }; | ||
|
|
||
| ctx.logger.warn( | ||
| "Change set review data is still being generated. Please retry in a few seconds.", | ||
| ); | ||
| ctx.logger.info( | ||
| `Retry in ${buildingData.retryAfterSeconds} seconds (estimated completion: ${buildingData.estimatedCompletionSeconds}s)`, | ||
| ); | ||
| Deno.exit(0); | ||
| } | ||
|
|
||
| // Type guard for successful response | ||
| if (!("components" in reviewData)) { | ||
| ctx.logger.error("Unexpected response format from API"); | ||
| Deno.exit(1); | ||
| } | ||
|
|
||
| const { components, summary } = reviewData; | ||
|
|
||
| // Display summary | ||
| if (components.length === 0) { | ||
| ctx.logger.info("No components have changes in this change set"); | ||
| return; | ||
| } | ||
|
|
||
| ctx.logger.info( | ||
| `Found ${summary.totalComponents} component(s) with changes: ${summary.added} added, ${summary.modified} modified, ${summary.removed} removed`, | ||
| ); | ||
| ctx.logger.info(""); | ||
|
|
||
| // Display each component's changes | ||
| for (const component of components) { | ||
| ctx.logger.info( | ||
| `Component: ${component.componentName} (${component.schemaName})`, | ||
| ); | ||
| ctx.logger.info(`Status: ${component.diffStatus}`); | ||
|
|
||
| const attributeDiffs = Object.entries(component.attributeDiffs || {}); | ||
|
|
||
| if (component.diffStatus === "Added") { | ||
| ctx.logger.info("All attributes are new:"); | ||
| } | ||
|
|
||
| for (const [path, diff] of attributeDiffs) { | ||
| if (diff.changeType === "added") { | ||
| ctx.logger.info(` + "${path}"`); | ||
| displayAttributeValue(" ", diff, "new"); | ||
| } else if (diff.changeType === "modified") { | ||
| ctx.logger.info(` ~ "${path}"`); | ||
| ctx.logger.info(" Old:"); | ||
| displayAttributeValue(" ", diff, "old"); | ||
| ctx.logger.info(" New:"); | ||
| displayAttributeValue(" ", diff, "new"); | ||
| } else if (diff.changeType === "removed") { | ||
| ctx.logger.info(` - "${path}"`); | ||
| displayAttributeValue(" ", diff, "old"); | ||
| } | ||
| } | ||
|
|
||
| ctx.logger.info(""); | ||
| } | ||
|
|
||
| // Display summary again at the end | ||
| ctx.logger.info( | ||
| `Summary: ${summary.added} added, ${summary.modified} modified, ${summary.removed} removed`, | ||
| ); | ||
|
|
||
| ctx.analytics.trackEvent("change set review", { | ||
| changeSetId, | ||
| componentsChanged: summary.totalComponents, | ||
| added: summary.added, | ||
| modified: summary.modified, | ||
| removed: summary.removed, | ||
| }); | ||
| } catch (error: unknown) { | ||
| // Handle 400 error for HEAD change set | ||
| if ( | ||
| error && | ||
| typeof error === "object" && | ||
| "response" in error && | ||
| error.response && | ||
| typeof error.response === "object" && | ||
| "status" in error.response && | ||
| error.response.status === 400 | ||
| ) { | ||
| ctx.logger.error( | ||
| "Cannot review HEAD change set - HEAD has no diffs to review", | ||
| ); | ||
| Deno.exit(1); | ||
| } | ||
|
|
||
| ctx.logger.error(`Failed to review change set: ${error}`); | ||
| Deno.exit(1); | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * Display a single attribute value with proper formatting | ||
| */ | ||
| function displayAttributeValue( | ||
| indent: string, | ||
| // deno-lint-ignore no-explicit-any | ||
| diff: any, | ||
| type: "old" | "new", | ||
| ): void { | ||
| const ctx = Context.instance(); | ||
|
|
||
| const value = type === "new" ? diff.newValue : diff.oldValue; | ||
| const sourceType = type === "new" ? diff.newSourceType : diff.oldSourceType; | ||
|
|
||
| if (sourceType === "subscription") { | ||
| const componentName = type === "new" | ||
| ? diff.newSourceComponentName | ||
| : diff.oldSourceComponentName; | ||
| const sourcePath = type === "new" ? diff.newSourcePath : diff.oldSourcePath; | ||
|
|
||
| if (componentName) { | ||
| ctx.logger.info( | ||
| `${indent}Value: "$source: ${componentName} -> ${sourcePath}"`, | ||
| ); | ||
| } else { | ||
| ctx.logger.info(`${indent}Value: "$source: -> ${sourcePath}"`); | ||
| } | ||
| } else if (sourceType === "prototype") { | ||
| const prototype = type === "new" | ||
| ? diff.newSourcePrototype | ||
| : diff.oldSourcePrototype; | ||
| ctx.logger.info(`${indent}Value: "$source: ${prototype}"`); | ||
| } else { | ||
| // Static value | ||
| if (typeof value === "string") { | ||
| ctx.logger.info(`${indent}Value: "${value}"`); | ||
| } else if (value === null || value === undefined) { | ||
| ctx.logger.info(`${indent}Value: ${value}`); | ||
| } else { | ||
| ctx.logger.info(`${indent}Value: ${JSON.stringify(value)}`); | ||
| } | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
The feature seems very useful! I just feel like we should do a raw string output for the check instead of using the logger, since that' output and not execution logs, and should be printed even if logging is set to silent
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.
The entire CLI output is behind the logger - if our plan is this then we need to rethink how we deal with the logger ingeneral - my thoughts here is that this isn't something we should take on at this time
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.
I agree with Victor, but I also agree that there are many locations that we really shouldn't be using the logger to talk to the user.
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.
So... another PR would be the right move to gut it all atomically.