Skip to content

Commit 9626b9d

Browse files
committed
Modify refresh button functionality to handle CSB; store summary and build log; open diff patch and summary directly in VSCode
1 parent 242f9fd commit 9626b9d

File tree

5 files changed

+330
-80
lines changed

5 files changed

+330
-80
lines changed

packages/core/src/amazonqGumby/chat/controller/controller.ts

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,15 @@ export class GumbyController {
190190

191191
private async transformInitiated(message: any) {
192192
this.messenger.sendViewHistoryMessage(message.tabID)
193+
if (transformByQState.isRefreshInProgress()) {
194+
transformByQState.setBlockedByRefresh(true)
195+
this.messenger.sendMessage(
196+
'A job refresh is currently in progress. Please wait for it to complete.',
197+
message.tabID,
198+
'ai-prompt'
199+
)
200+
return
201+
}
193202

194203
// silently check for projects eligible for SQL conversion
195204
let embeddedSQLProjects: TransformationCandidateProject[] = []
@@ -460,6 +469,15 @@ export class GumbyController {
460469
}
461470

462471
private async handleUserLanguageUpgradeProjectChoice(message: any) {
472+
if (transformByQState.isRefreshInProgress()) {
473+
transformByQState.setBlockedByRefresh(true)
474+
this.messenger.sendMessage(
475+
'A job refresh is currently in progress. Please wait for it to complete.',
476+
message.tabID,
477+
'ai-prompt'
478+
)
479+
return
480+
}
463481
await telemetry.codeTransform_submitSelection.run(async () => {
464482
const pathToProject: string = message.formSelectedValues['GumbyTransformLanguageUpgradeProjectForm']
465483
const toJDKVersion: JDKVersion = message.formSelectedValues['GumbyTransformJdkToForm']
@@ -492,6 +510,15 @@ export class GumbyController {
492510
}
493511

494512
private async handleUserSQLConversionProjectSelection(message: any) {
513+
if (transformByQState.isRefreshInProgress()) {
514+
transformByQState.setBlockedByRefresh(true)
515+
this.messenger.sendMessage(
516+
'A job refresh is currently in progress. Please wait for it to complete.',
517+
message.tabID,
518+
'ai-prompt'
519+
)
520+
return
521+
}
495522
await telemetry.codeTransform_submitSelection.run(async () => {
496523
const pathToProject: string = message.formSelectedValues['GumbyTransformSQLConversionProjectForm']
497524
const schema: string = message.formSelectedValues['GumbyTransformSQLSchemaForm']

packages/core/src/codewhisperer/commands/startTransformByQ.ts

Lines changed: 57 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,6 @@ import { convertDateToTimestamp } from '../../shared/datetime'
7979
import { findStringInDirectory } from '../../shared/utilities/workspaceUtils'
8080
import { makeTemporaryToolkitFolder } from '../../shared/filesystemUtilities'
8181
import { AuthUtil } from '../util/authUtil'
82-
import { homedir } from 'os'
8382

8483
export function getFeedbackCommentData() {
8584
const jobId = transformByQState.getJobId()
@@ -476,6 +475,30 @@ export async function startTransformationJob(
476475
codeTransformRunTimeLatency: calculateTotalLatency(transformStartTime),
477476
})
478477
})
478+
479+
// create local history folder(s) and store metadata
480+
const jobHistoryPath = path.join(os.homedir(), '.aws', 'transform', transformByQState.getProjectName(), jobId)
481+
if (!fs.existsSync(jobHistoryPath)) {
482+
fs.mkdirSync(jobHistoryPath, { recursive: true })
483+
}
484+
transformByQState.setJobHistoryPath(jobHistoryPath)
485+
// save a copy of the upload zip
486+
fs.copyFileSync(transformByQState.getPayloadFilePath(), path.join(jobHistoryPath, 'zipped-code.zip'))
487+
488+
const fields = [
489+
jobId,
490+
transformByQState.getTransformationType(),
491+
transformByQState.getSourceJDKVersion(),
492+
transformByQState.getTargetJDKVersion(),
493+
transformByQState.getCustomDependencyVersionFilePath(),
494+
transformByQState.getCustomBuildCommand(),
495+
transformByQState.getTargetJavaHome(),
496+
transformByQState.getProjectPath(),
497+
transformByQState.getStartTime(),
498+
]
499+
500+
const jobDetails = fields.join('\t')
501+
fs.writeFileSync(path.join(jobHistoryPath, 'metadata.txt'), jobDetails)
479502
} catch (error) {
480503
getLogger().error(`CodeTransformation: ${CodeWhispererConstants.failedToStartJobNotification}`, error)
481504
const errorMessage = (error as Error).message.toLowerCase()
@@ -726,9 +749,19 @@ export async function postTransformationJob() {
726749
})
727750
}
728751

729-
if (transformByQState.getPayloadFilePath()) {
730-
// delete original upload ZIP at very end of transformation
731-
fs.rmSync(transformByQState.getPayloadFilePath(), { force: true })
752+
if (
753+
transformByQState.isSucceeded() ||
754+
transformByQState.isPartiallySucceeded() ||
755+
transformByQState.isCancelled()
756+
) {
757+
if (transformByQState.getPayloadFilePath()) {
758+
// delete original upload ZIP at very end of transformation
759+
fs.rmSync(transformByQState.getPayloadFilePath(), { force: true })
760+
// delete the copy of the upload ZIP
761+
fs.rmSync(path.join(transformByQState.getJobHistoryPath(), 'zipped-code.zip'), { force: true })
762+
}
763+
// delete transformation job metadata file (no longer needed)
764+
fs.rmSync(path.join(transformByQState.getJobHistoryPath(), 'metadata.txt'), { force: true })
732765
}
733766
// delete temporary build logs file
734767
const logFilePath = path.join(os.tmpdir(), 'build-logs.txt')
@@ -745,28 +778,30 @@ export async function postTransformationJob() {
745778
// store job details and diff path locally (history)
746779
// TODO: ideally when job is cancelled, should be stored as CANCELLED instead of FAILED (remove this if statement after bug is fixed)
747780
if (!transformByQState.isCancelled()) {
748-
const jobHistoryFilePath = path.join(homedir(), '.aws', 'transform', 'transformation-history.tsv')
781+
const historyLogFilePath = path.join(os.homedir(), '.aws', 'transform', 'transformation-history.tsv')
749782
// create transform folder if necessary
750-
if (!fs.existsSync(jobHistoryFilePath)) {
751-
fs.mkdirSync(path.dirname(jobHistoryFilePath), { recursive: true })
783+
if (!fs.existsSync(historyLogFilePath)) {
784+
fs.mkdirSync(path.dirname(historyLogFilePath), { recursive: true })
752785
// create headers of new transformation history file
753-
fs.writeFileSync(jobHistoryFilePath, 'date\tproject_name\tstatus\tduration\tdiff_path\tjob_id\n')
786+
fs.writeFileSync(historyLogFilePath, 'date\tproject_name\tstatus\tduration\tdiff_patch\tsummary\tjob_id\n')
754787
}
755788
const latest = sessionJobHistory[transformByQState.getJobId()]
756-
const jobDetails: string =
757-
latest.startTime +
758-
'\t' +
759-
latest.projectName +
760-
'\t' +
761-
latest.status +
762-
'\t' +
763-
latest.duration +
764-
'\t' +
765-
transformByQState.getDiffPatchFilePath() +
766-
'\t' +
767-
transformByQState.getJobId() +
768-
'\n'
769-
fs.writeFileSync(jobHistoryFilePath, jobDetails, { flag: 'a' })
789+
const fields = [
790+
latest.startTime,
791+
latest.projectName,
792+
latest.status,
793+
latest.duration,
794+
transformByQState.isSucceeded() || transformByQState.isPartiallySucceeded()
795+
? path.join(transformByQState.getJobHistoryPath(), 'diff.patch')
796+
: '',
797+
transformByQState.isSucceeded() || transformByQState.isPartiallySucceeded()
798+
? path.join(transformByQState.getJobHistoryPath(), 'summary', 'summary.md')
799+
: '',
800+
transformByQState.getJobId(),
801+
]
802+
803+
const jobDetails = fields.join('\t') + '\n'
804+
fs.writeFileSync(historyLogFilePath, jobDetails, { flag: 'a' })
770805
}
771806
}
772807

packages/core/src/codewhisperer/models/model.ts

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -730,7 +730,7 @@ export class TransformByQState {
730730
private planFilePath: string = ''
731731
private summaryFilePath: string = ''
732732
private preBuildLogFilePath: string = ''
733-
private diffPatchFilePath: string = ''
733+
private jobHistoryPath: string = ''
734734

735735
private resultArchiveFilePath: string = ''
736736
private projectCopyFilePath: string = ''
@@ -762,6 +762,9 @@ export class TransformByQState {
762762

763763
private intervalId: NodeJS.Timeout | undefined = undefined
764764

765+
private refreshInProgress: boolean = false
766+
private blockedByRefresh: boolean = false
767+
765768
public isNotStarted() {
766769
return this.transformByQState === TransformByQStatus.NotStarted
767770
}
@@ -786,6 +789,14 @@ export class TransformByQState {
786789
return this.transformByQState === TransformByQStatus.PartiallySucceeded
787790
}
788791

792+
public isRefreshInProgress() {
793+
return this.refreshInProgress
794+
}
795+
796+
public wasBlockedByRefresh() {
797+
return this.blockedByRefresh
798+
}
799+
789800
public getHasSeenTransforming() {
790801
return this.hasSeenTransforming
791802
}
@@ -882,8 +893,8 @@ export class TransformByQState {
882893
return this.summaryFilePath
883894
}
884895

885-
public getDiffPatchFilePath() {
886-
return this.diffPatchFilePath
896+
public getJobHistoryPath() {
897+
return this.jobHistoryPath
887898
}
888899

889900
public getResultArchiveFilePath() {
@@ -980,6 +991,14 @@ export class TransformByQState {
980991
this.transformByQState = TransformByQStatus.PartiallySucceeded
981992
}
982993

994+
public setRefreshInProgress(inProgress: boolean) {
995+
this.refreshInProgress = inProgress
996+
}
997+
998+
public setBlockedByRefresh(blocked: boolean): void {
999+
this.blockedByRefresh = blocked
1000+
}
1001+
9831002
public setHasSeenTransforming(hasSeen: boolean) {
9841003
this.hasSeenTransforming = hasSeen
9851004
}
@@ -1060,8 +1079,8 @@ export class TransformByQState {
10601079
this.summaryFilePath = filePath
10611080
}
10621081

1063-
public setDiffPatchFilePath(filePath: string) {
1064-
return (this.diffPatchFilePath = filePath)
1082+
public setJobHistoryPath(filePath: string) {
1083+
this.jobHistoryPath = filePath
10651084
}
10661085

10671086
public setResultArchiveFilePath(filePath: string) {
@@ -1130,6 +1149,7 @@ export class TransformByQState {
11301149

11311150
public setJobDefaults() {
11321151
this.setToNotStarted()
1152+
this.refreshInProgress = false
11331153
this.hasSeenTransforming = false
11341154
this.jobFailureErrorNotification = undefined
11351155
this.jobFailureErrorChatMessage = undefined

0 commit comments

Comments
 (0)