Skip to content

Commit 7dc7aca

Browse files
author
David Hasani
committed
fix diff.patch issue
1 parent 1cbe326 commit 7dc7aca

File tree

5 files changed

+36
-12
lines changed

5 files changed

+36
-12
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ export class GumbyController {
224224
this.sessionStorage.getSession().conversationState = ConversationState.WAITING_FOR_TRANSFORMATION_OBJECTIVE
225225
this.messenger.sendStaticTextResponse('choose-transformation-objective', message.tabID)
226226
this.messenger.sendChatInputEnabled(message.tabID, true)
227-
this.messenger.sendUpdatePlaceholder(message.tabID, "Enter 'language upgrade' or 'SQL conversion'")
227+
this.messenger.sendUpdatePlaceholder(message.tabID, CodeWhispererConstants.chooseTransformationObjective)
228228
}
229229

230230
private async beginTransformation(message: any) {

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -390,7 +390,7 @@ export class Messenger {
390390
message = 'I will continue transforming your code without upgrading this dependency.'
391391
break
392392
case 'choose-transformation-objective':
393-
message = 'Choose your transformation objective.'
393+
message = CodeWhispererConstants.chooseTransformationObjective
394394
break
395395
}
396396

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,16 @@
33
* SPDX-License-Identifier: Apache-2.0
44
*/
55

6+
import { TransformationType, transformByQState } from '../../codewhisperer/models/model'
7+
68
// For uniquely identifiying which chat messages should be routed to Gumby
79
export const gumbyChat = 'gumbyChat'
810

911
// This sets the tab name
1012
export const featureName = 'Q - Code Transform'
1113

1214
export const dependencyNoAvailableVersions = 'no available versions'
15+
16+
export function getTransformationActionString() {
17+
return transformByQState.getTransformationType() === TransformationType.LANGUAGE_UPGRADE ? 'upgraded' : 'converted'
18+
}

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

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
* SPDX-License-Identifier: Apache-2.0
44
*/
55

6+
import { getTransformationActionString } from '../../amazonqGumby/models/constants'
7+
68
/**
79
* Automated and manual trigger
810
*/
@@ -450,6 +452,8 @@ export const codeTransformLocThreshold = 100000
450452
export const jobStartedChatMessage =
451453
'I am starting to transform your code. It can take 10 to 30 minutes to upgrade your code, depending on the size of your project. To monitor progress, go to the Transformation Hub. If I run into any issues, I might pause the transformation to get input from you on how to proceed.'
452454

455+
export const chooseTransformationObjective = 'Enter "language upgrade" or "sql conversion"'
456+
453457
export const uploadingCodeStepMessage = 'Upload your code'
454458

455459
export const buildCodeStepMessage = 'Build uploaded code in secure build environment'
@@ -490,8 +494,7 @@ export const startTransformationButtonText = 'Start a new transformation'
490494

491495
export const stopTransformationButtonText = 'Stop transformation'
492496

493-
export const checkingForProjectsChatMessage =
494-
'I am checking for open projects that are eligible for Code Transformation.'
497+
export const checkingForProjectsChatMessage = 'Checking for eligible projects...'
495498

496499
export const buildStartedChatMessage =
497500
'I am building your project. This can take up to 10 minutes, depending on the size of your project.'
@@ -578,17 +581,13 @@ export const jobCancelledChatMessage =
578581

579582
export const jobCancelledNotification = 'You cancelled the transformation.'
580583

581-
export const jobCompletedChatMessage =
582-
'I upgraded your code. You can review the diff to see my proposed changes and accept or reject them. The transformation summary has details about the files I updated.'
584+
export const jobCompletedChatMessage = `I ${getTransformationActionString()} your code. You can review the diff to see my proposed changes and accept or reject them. The transformation summary has details about the files I updated.`
583585

584-
export const jobCompletedNotification =
585-
'Amazon Q upgraded your code. You can review the diff to see my proposed changes and accept or reject them. The transformation summary has details about the files I updated.'
586+
export const jobCompletedNotification = `Amazon Q ${getTransformationActionString()} your code. You can review the diff to see my proposed changes and accept or reject them. The transformation summary has details about the files I updated.`
586587

587-
export const jobPartiallyCompletedChatMessage =
588-
'I upgraded part of your code. You can review the diff to see my proposed changes and accept or reject them. The transformation summary has details about the files I updated and the errors that prevented a complete transformation.'
588+
export const jobPartiallyCompletedChatMessage = `I ${getTransformationActionString()} part of your code. You can review the diff to see my proposed changes and accept or reject them. The transformation summary has details about the files I updated and the errors that prevented a complete transformation.`
589589

590-
export const jobPartiallyCompletedNotification =
591-
'Amazon Q upgraded part of your code. You can review the diff to see my proposed changes and accept or reject them. The transformation summary has details about the files I updated and the errors that prevented a complete transformation.'
590+
export const jobPartiallyCompletedNotification = `Amazon Q ${getTransformationActionString()} part of your code. You can review the diff to see my proposed changes and accept or reject them. The transformation summary has details about the files I updated and the errors that prevented a complete transformation.`
592591

593592
export const noPomXmlFoundChatMessage = `Sorry, I couldn\'t find a project that I can upgrade. I couldn\'t find a pom.xml file in any of your open projects. Currently, I can only upgrade Java 8 or Java 11 projects built on Maven. For more information, see the [Amazon Q documentation](${codeTransformPrereqDoc}).`
594593

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

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -372,6 +372,25 @@ export class ProposedTransformationExplorer {
372372
pathContainingArchive = path.dirname(pathToArchive)
373373
const zip = new AdmZip(pathToArchive)
374374
zip.extractAllTo(pathContainingArchive)
375+
// TODO: below only needed if the backend cannot fix the "b/" diff.patch issue
376+
// read in the diff.patch
377+
const diffPatch = fs.readFileSync(
378+
path.join(pathContainingArchive, ExportResultArchiveStructure.PathToDiffPatch),
379+
'utf-8'
380+
)
381+
// go through each line, and replace "b" with "b/" on lines that start with "diff"
382+
const lines = diffPatch.split('\n')
383+
const newLines = lines.map((line) => {
384+
if (line.trim().startsWith('diff') || line.trim().startsWith('+++')) {
385+
return line.replace('b', 'b/')
386+
}
387+
return line
388+
})
389+
const newDiffPatch = newLines.join('\n')
390+
fs.writeFileSync(
391+
path.join(pathContainingArchive, ExportResultArchiveStructure.PathToDiffPatch),
392+
newDiffPatch
393+
)
375394
diffModel.parseDiff(
376395
path.join(pathContainingArchive, ExportResultArchiveStructure.PathToDiffPatch),
377396
transformByQState.getProjectPath()

0 commit comments

Comments
 (0)