Skip to content

Commit 5ebadfa

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 38a3f46 commit 5ebadfa

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
@@ -727,7 +727,7 @@ export class TransformByQState {
727727
private planFilePath: string = ''
728728
private summaryFilePath: string = ''
729729
private preBuildLogFilePath: string = ''
730-
private diffPatchFilePath: string = ''
730+
private jobHistoryPath: string = ''
731731

732732
private resultArchiveFilePath: string = ''
733733
private projectCopyFilePath: string = ''
@@ -759,6 +759,9 @@ export class TransformByQState {
759759

760760
private intervalId: NodeJS.Timeout | undefined = undefined
761761

762+
private refreshInProgress: boolean = false
763+
private blockedByRefresh: boolean = false
764+
762765
public isNotStarted() {
763766
return this.transformByQState === TransformByQStatus.NotStarted
764767
}
@@ -783,6 +786,14 @@ export class TransformByQState {
783786
return this.transformByQState === TransformByQStatus.PartiallySucceeded
784787
}
785788

789+
public isRefreshInProgress() {
790+
return this.refreshInProgress
791+
}
792+
793+
public wasBlockedByRefresh() {
794+
return this.blockedByRefresh
795+
}
796+
786797
public getHasSeenTransforming() {
787798
return this.hasSeenTransforming
788799
}
@@ -879,8 +890,8 @@ export class TransformByQState {
879890
return this.summaryFilePath
880891
}
881892

882-
public getDiffPatchFilePath() {
883-
return this.diffPatchFilePath
893+
public getJobHistoryPath() {
894+
return this.jobHistoryPath
884895
}
885896

886897
public getResultArchiveFilePath() {
@@ -977,6 +988,14 @@ export class TransformByQState {
977988
this.transformByQState = TransformByQStatus.PartiallySucceeded
978989
}
979990

991+
public setRefreshInProgress(inProgress: boolean) {
992+
this.refreshInProgress = inProgress
993+
}
994+
995+
public setBlockedByRefresh(blocked: boolean): void {
996+
this.blockedByRefresh = blocked
997+
}
998+
980999
public setHasSeenTransforming(hasSeen: boolean) {
9811000
this.hasSeenTransforming = hasSeen
9821001
}
@@ -1057,8 +1076,8 @@ export class TransformByQState {
10571076
this.summaryFilePath = filePath
10581077
}
10591078

1060-
public setDiffPatchFilePath(filePath: string) {
1061-
return (this.diffPatchFilePath = filePath)
1079+
public setJobHistoryPath(filePath: string) {
1080+
this.jobHistoryPath = filePath
10621081
}
10631082

10641083
public setResultArchiveFilePath(filePath: string) {
@@ -1127,6 +1146,7 @@ export class TransformByQState {
11271146

11281147
public setJobDefaults() {
11291148
this.setToNotStarted()
1149+
this.refreshInProgress = false
11301150
this.hasSeenTransforming = false
11311151
this.jobFailureErrorNotification = undefined
11321152
this.jobFailureErrorChatMessage = undefined

0 commit comments

Comments
 (0)