Skip to content

Commit 8e20bee

Browse files
committed
Minor fixes: move strings to constants file, fix circular dependency issue, etc.
1 parent e5b4ef2 commit 8e20bee

File tree

7 files changed

+83
-48
lines changed

7 files changed

+83
-48
lines changed
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"type": "Feature",
3+
"description": "/transform: Show transformation history in Transformation Hub and allow users to resume jobs"
4+
}

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

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -200,11 +200,7 @@ export class GumbyController {
200200
})
201201
this.messenger.sendViewHistoryMessage(message.tabID, numInProgress)
202202
if (transformByQState.isRefreshInProgress()) {
203-
this.messenger.sendMessage(
204-
'A job refresh is currently in progress. Please wait for it to complete.',
205-
message.tabID,
206-
'ai-prompt'
207-
)
203+
this.messenger.sendMessage(CodeWhispererConstants.refreshInProgressChatMessage, message.tabID, 'ai-prompt')
208204
return
209205
}
210206

@@ -478,11 +474,7 @@ export class GumbyController {
478474

479475
private async handleUserLanguageUpgradeProjectChoice(message: any) {
480476
if (transformByQState.isRefreshInProgress()) {
481-
this.messenger.sendMessage(
482-
'A job refresh is currently in progress. Please wait for it to complete.',
483-
message.tabID,
484-
'ai-prompt'
485-
)
477+
this.messenger.sendMessage(CodeWhispererConstants.refreshInProgressChatMessage, message.tabID, 'ai-prompt')
486478
return
487479
}
488480
await telemetry.codeTransform_submitSelection.run(async () => {
@@ -518,11 +510,7 @@ export class GumbyController {
518510

519511
private async handleUserSQLConversionProjectSelection(message: any) {
520512
if (transformByQState.isRefreshInProgress()) {
521-
this.messenger.sendMessage(
522-
'A job refresh is currently in progress. Please wait for it to complete.',
523-
message.tabID,
524-
'ai-prompt'
525-
)
513+
this.messenger.sendMessage(CodeWhispererConstants.refreshInProgressChatMessage, message.tabID, 'ai-prompt')
526514
return
527515
}
528516
await telemetry.codeTransform_submitSelection.run(async () => {

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

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -382,15 +382,12 @@ export class Messenger {
382382

383383
buttons.push({
384384
keepCardAfterClick: true,
385-
text: 'Open job history',
385+
text: CodeWhispererConstants.jobHistoryButtonText,
386386
id: ButtonActions.VIEW_JOB_HISTORY,
387387
disabled: false,
388388
})
389389

390-
const messageText =
391-
numInProgress > 0
392-
? `You have ${numInProgress} job${numInProgress > 1 ? 's' : ''} in progress. You can resume ${numInProgress > 1 ? 'them' : 'it'} in the transformation history table.`
393-
: 'View previous transformations run from the IDE'
390+
const messageText = CodeWhispererConstants.viewHistoryMessage(numInProgress)
394391

395392
const message = new ChatMessage(
396393
{
@@ -407,7 +404,7 @@ export class Messenger {
407404
this.dispatcher.sendAsyncEventProgress(
408405
new AsyncEventProgressMessage(tabID, {
409406
inProgress: true,
410-
message: `I am now resuming your job (id: ${jobId}). This can take 10 to 30 minutes to complete.`,
407+
message: CodeWhispererConstants.refreshingJobChatMessage(jobId),
411408
})
412409
)
413410
}

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

Lines changed: 9 additions & 5 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 { TransformationHubViewProvider } from '../service/transformByQ/transformationHubViewProvider'
8382

8483
export function getFeedbackCommentData() {
8584
const jobId = transformByQState.getJobId()
@@ -758,9 +757,9 @@ export async function postTransformationJob() {
758757
if (transformByQState.getPayloadFilePath()) {
759758
// delete original upload ZIP at very end of transformation
760759
fs.rmSync(transformByQState.getPayloadFilePath(), { force: true })
761-
// delete the copy of the upload ZIP
762-
fs.rmSync(path.join(transformByQState.getJobHistoryPath(), 'zipped-code.zip'), { force: true })
763760
}
761+
// delete the copy of the upload ZIP
762+
fs.rmSync(path.join(transformByQState.getJobHistoryPath(), 'zipped-code.zip'), { force: true })
764763
// delete transformation job metadata file (no longer needed)
765764
fs.rmSync(path.join(transformByQState.getJobHistoryPath(), 'metadata.txt'), { force: true })
766765
}
@@ -779,7 +778,7 @@ export async function postTransformationJob() {
779778
// store job details and diff path locally (history)
780779
// TODO: ideally when job is cancelled, should be stored as CANCELLED instead of FAILED (remove this if statement after bug is fixed)
781780
if (!transformByQState.isCancelled()) {
782-
const historyLogFilePath = path.join(os.homedir(), '.aws', 'transform', 'transformation-history.tsv')
781+
const historyLogFilePath = path.join(os.homedir(), '.aws', 'transform', 'transformation_history.tsv')
783782
// create transform folder if necessary
784783
if (!fs.existsSync(historyLogFilePath)) {
785784
fs.mkdirSync(path.dirname(historyLogFilePath), { recursive: true })
@@ -803,7 +802,12 @@ export async function postTransformationJob() {
803802

804803
const jobDetails = fields.join('\t') + '\n'
805804
fs.writeFileSync(historyLogFilePath, jobDetails, { flag: 'a' })
806-
await TransformationHubViewProvider.instance.updateContent('job history', undefined, true)
805+
await vscode.commands.executeCommand(
806+
'aws.amazonq.transformationHub.updateContent',
807+
'job history',
808+
undefined,
809+
true
810+
)
807811
}
808812
}
809813

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

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -799,6 +799,33 @@ export const formattedStringMap = new Map([
799799
['numChangedFiles', 'Files to be changed'],
800800
])
801801

802+
export const refreshInProgressChatMessage = 'A job refresh is currently in progress. Please wait for it to complete.'
803+
804+
export const refreshingJobChatMessage = (jobId: string) =>
805+
`I am now resuming your job (id: ${jobId}). This can take 10 to 30 minutes to complete.`
806+
807+
export const jobHistoryButtonText = 'Open job history'
808+
809+
export const viewHistoryMessage = (numInProgress: number) =>
810+
numInProgress > 0
811+
? `You have ${numInProgress} job${numInProgress > 1 ? 's' : ''} in progress. You can resume ${numInProgress > 1 ? 'them' : 'it'} in the transformation history table.`
812+
: 'View previous transformations run from the IDE'
813+
814+
export const transformationHistoryTableDescription =
815+
'This table lists the most recent jobs that you have run in the past 30 days. To open the diff patch and summary files, click the provided links. Jobs with a status of FAILED may still be in progress. Resume them within 12 hours of starting the job to get an updated job status and artifacts. Click the refresh icon to do so. The diff patch and summary will appear once they are available.'
816+
817+
export const refreshErrorChatMessage =
818+
"Sorry, I couldn't refresh the job. Please try again or start a new transformation."
819+
820+
export const refreshErrorNotification = (jobId: string) => `There was an error refreshing this job. Job Id: ${jobId}`
821+
822+
export const refreshCompletedChatMessage =
823+
'Job refresh completed. Please see the transformation history table for the updated status and artifacts.'
824+
825+
export const refreshCompletedNotification = (jobId: string) => `Job refresh completed. (Job Id: ${jobId})`
826+
827+
export const refreshNoUpdatesNotification = (jobId: string) => `No updates. (Job Id: ${jobId})`
828+
802829
// end of QCT Strings
803830

804831
export enum UserGroup {

packages/core/src/codewhisperer/service/transformByQ/transformationHubViewProvider.ts

Lines changed: 27 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,14 @@ export class TransformationHubViewProvider implements vscode.WebviewViewProvider
4848
private lastClickedButton: string = ''
4949
private _extensionUri: vscode.Uri = globals.context.extensionUri
5050
private transformationHistory: HistoryObject[] = []
51-
constructor() {}
51+
constructor() {
52+
vscode.commands.registerCommand(
53+
'aws.amazonq.transformationHub.updateContent',
54+
(button: 'job history' | 'plan progress', startTime?: number, historyFileUpdated?: boolean) => {
55+
return this.updateContent(button, startTime, historyFileUpdated)
56+
}
57+
)
58+
}
5259
static #instance: TransformationHubViewProvider
5360

5461
public async updateContent(
@@ -150,12 +157,7 @@ export class TransformationHubViewProvider implements vscode.WebviewViewProvider
150157
</head>
151158
<body>
152159
<p><b>Transformation History</b></p>
153-
<p>This table lists the most recent jobs that you have run in the past 30 days.
154-
To open the diff patch and summary files, click the provided links.
155-
Jobs with a status of FAILED may still be in progress.
156-
Resume them within 12 hours of starting the job to get an updated job status and artifacts. Click the refresh icon to do so.
157-
The diff patch and summary will appear once they are available.
158-
</p>
160+
<p>${CodeWhispererConstants.transformationHistoryTableDescription}</p>
159161
${
160162
jobsToDisplay.length === 0
161163
? `<p>${CodeWhispererConstants.nothingToShowMessage}</p>`
@@ -314,8 +316,11 @@ export class TransformationHubViewProvider implements vscode.WebviewViewProvider
314316
// artifacts should be available to download
315317
jobHistoryPath = await this.retrieveArtifacts(jobId, projectName)
316318

317-
// delete metadata file, if it exists
319+
// delete metadata and zipped code files, if they exist
318320
fs.rmSync(path.join(os.homedir(), '.aws', 'transform', projectName, jobId, 'metadata.txt'), { force: true })
321+
fs.rmSync(path.join(os.homedir(), '.aws', 'transform', projectName, jobId, 'zipped-code.zip'), {
322+
force: true,
323+
})
319324
} else if (CodeWhispererConstants.validStatesForBuildSucceeded.includes(status)) {
320325
// still in progress on server side
321326
if (transformByQState.isRunning()) {
@@ -361,10 +366,10 @@ export class TransformationHubViewProvider implements vscode.WebviewViewProvider
361366
if (messenger) {
362367
messenger.sendJobFinishedMessage(
363368
ChatSessionManager.Instance.getSession().tabID!,
364-
"Sorry, I couldn't refresh the job. Please try again or start a new transformation."
369+
CodeWhispererConstants.refreshErrorChatMessage
365370
)
366371
}
367-
void vscode.window.showErrorMessage(`There was an error refreshing this job. Job Id: ${jobId}`)
372+
void vscode.window.showErrorMessage(CodeWhispererConstants.refreshErrorNotification(jobId))
368373
return
369374
}
370375

@@ -400,10 +405,10 @@ export class TransformationHubViewProvider implements vscode.WebviewViewProvider
400405
if (messenger) {
401406
messenger.sendJobFinishedMessage(
402407
ChatSessionManager.Instance.getSession().tabID!,
403-
"Sorry, I couldn't refresh the job. Please try again or start a new transformation."
408+
CodeWhispererConstants.refreshErrorChatMessage
404409
)
405410
}
406-
void vscode.window.showErrorMessage(`There was an error refreshing this job. Job Id: ${jobId}`)
411+
void vscode.window.showErrorMessage(CodeWhispererConstants.refreshErrorNotification(jobId))
407412
this.updateContent('job history') // re-enable refresh buttons
408413
return
409414
}
@@ -413,7 +418,7 @@ export class TransformationHubViewProvider implements vscode.WebviewViewProvider
413418
if (messenger) {
414419
messenger.sendJobFinishedMessage(
415420
ChatSessionManager.Instance.getSession().tabID!,
416-
'Job refresh completed. Please see the transformation history table for the updated status and artifacts.'
421+
CodeWhispererConstants.refreshCompletedChatMessage
417422
)
418423
}
419424
} else {
@@ -423,15 +428,20 @@ export class TransformationHubViewProvider implements vscode.WebviewViewProvider
423428
// if job failed on backend, mark it to disable the refresh button
424429
status = 'FAILED_BE' // this will be truncated to just 'FAILED' in the table
425430
}
431+
// delete metadata and zipped code files, if they exist
432+
fs.rmSync(path.join(os.homedir(), '.aws', 'transform', projectName, jobId, 'metadata.txt'), { force: true })
433+
fs.rmSync(path.join(os.homedir(), '.aws', 'transform', projectName, jobId, 'zipped-code.zip'), {
434+
force: true,
435+
})
426436
}
427437

428438
if (status === currentStatus && !jobHistoryPath) {
429439
// no changes, no need to update file/table
430-
void vscode.window.showInformationMessage(`No updates. (Job Id: ${jobId})`)
440+
void vscode.window.showInformationMessage(CodeWhispererConstants.refreshNoUpdatesNotification(jobId))
431441
return
432442
}
433443

434-
void vscode.window.showInformationMessage(`Job refresh completed. (Job Id: ${jobId})`)
444+
void vscode.window.showInformationMessage(CodeWhispererConstants.refreshCompletedNotification(jobId))
435445
// update local file and history table
436446
await this.updateHistoryFile(status, duration, jobHistoryPath, jobId)
437447
}
@@ -473,7 +483,7 @@ export class TransformationHubViewProvider implements vscode.WebviewViewProvider
473483

474484
private async updateHistoryFile(status: string, duration: string, jobHistoryPath: string, jobId: string) {
475485
const history: string[][] = []
476-
const historyLogFilePath = path.join(os.homedir(), '.aws', 'transform', 'transformation-history.tsv')
486+
const historyLogFilePath = path.join(os.homedir(), '.aws', 'transform', 'transformation_history.tsv')
477487
if (fs.existsSync(historyLogFilePath)) {
478488
const historyFile = fs.readFileSync(historyLogFilePath, { encoding: 'utf8', flag: 'r' })
479489
const jobs = historyFile.split('\n')
@@ -920,7 +930,7 @@ export class TransformationHubViewProvider implements vscode.WebviewViewProvider
920930

921931
export function readHistoryFile(): HistoryObject[] {
922932
const history: HistoryObject[] = []
923-
const jobHistoryFilePath = path.join(os.homedir(), '.aws', 'transform', 'transformation-history.tsv')
933+
const jobHistoryFilePath = path.join(os.homedir(), '.aws', 'transform', 'transformation_history.tsv')
924934
if (fs.existsSync(jobHistoryFilePath)) {
925935
const historyFile = fs.readFileSync(jobHistoryFilePath, { encoding: 'utf8', flag: 'r' })
926936
const jobs = historyFile.split('\n')

packages/core/src/test/amazonqGumby/transformationJobHistory.test.ts

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -220,26 +220,31 @@ describe('Transformation Job History', function () {
220220
}
221221

222222
fsExistsStub.returns(false) // Assuming history file doesn't exist yet
223-
const updateContentStub = sinon.stub(transformationHub, 'updateContent').resolves()
223+
const executeCommandStub = sinon.stub(vscode.commands, 'executeCommand').resolves()
224224
sinon.stub(transformApiHandler, 'updateJobHistory')
225-
sinon.stub(vscode.commands, 'executeCommand').resolves()
226225

227226
await postTransformationJob()
228227

229228
sinon.assert.calledWith(
230229
fsWriteStub.firstCall,
231-
sinon.match(/transformation-history\.tsv$/),
230+
sinon.match(/transformation_history\.tsv$/),
232231
'date\tproject_name\tstatus\tduration\tdiff_patch\tsummary\tjob_id\n'
233232
)
234233

235234
sinon.assert.calledWith(
236235
fsWriteStub.secondCall,
237-
sinon.match(/transformation-history\.tsv$/),
236+
sinon.match(/transformation_history\.tsv$/),
238237
sinon.match(/test-project.*COMPLETED.*4 min.*diff\.patch.*summary\.md.*completed-job-123/),
239238
{ flag: 'a' }
240239
)
241240

242-
sinon.assert.calledWith(updateContentStub, 'job history', undefined, true)
241+
sinon.assert.calledWith(
242+
executeCommandStub,
243+
'aws.amazonq.transformationHub.updateContent',
244+
'job history',
245+
undefined,
246+
true
247+
)
243248
})
244249
})
245250
})

0 commit comments

Comments
 (0)