Skip to content

Commit edb3fa2

Browse files
author
David Hasani
committed
fix diff.patch issue
1 parent 5cd62dc commit edb3fa2

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
@@ -394,7 +394,7 @@ export class Messenger {
394394
message = 'I will continue transforming your code without upgrading this dependency.'
395395
break
396396
case 'choose-transformation-objective':
397-
message = 'Choose your transformation objective.'
397+
message = CodeWhispererConstants.chooseTransformationObjective
398398
break
399399
}
400400

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 = `I couldn\'t find a project that I can upgrade. Your Java project must be built on Maven and contain a pom.xml file. 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
@@ -373,6 +373,25 @@ export class ProposedTransformationExplorer {
373373
pathContainingArchive = path.dirname(pathToArchive)
374374
const zip = new AdmZip(pathToArchive)
375375
zip.extractAllTo(pathContainingArchive)
376+
// TODO: below only needed if the backend cannot fix the "b/" diff.patch issue
377+
// read in the diff.patch
378+
const diffPatch = fs.readFileSync(
379+
path.join(pathContainingArchive, ExportResultArchiveStructure.PathToDiffPatch),
380+
'utf-8'
381+
)
382+
// go through each line, and replace "b" with "b/" on lines that start with "diff"
383+
const lines = diffPatch.split('\n')
384+
const newLines = lines.map((line) => {
385+
if (line.trim().startsWith('diff') || line.trim().startsWith('+++')) {
386+
return line.replace('b', 'b/')
387+
}
388+
return line
389+
})
390+
const newDiffPatch = newLines.join('\n')
391+
fs.writeFileSync(
392+
path.join(pathContainingArchive, ExportResultArchiveStructure.PathToDiffPatch),
393+
newDiffPatch
394+
)
376395
diffModel.parseDiff(
377396
path.join(pathContainingArchive, ExportResultArchiveStructure.PathToDiffPatch),
378397
transformByQState.getProjectPath()

0 commit comments

Comments
 (0)