Skip to content

Commit 72aac52

Browse files
author
David Hasani
committed
handle empty diff
1 parent 7dc7aca commit 72aac52

File tree

5 files changed

+27
-22
lines changed

5 files changed

+27
-22
lines changed

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,7 @@ export class GumbyController {
192192
private async transformInitiated(message: any) {
193193
// feature flag for SQL transformations
194194
if (!isSQLTransformReady) {
195+
// TODO: if (!projectContainsEmbeddedSQLUsingOracle)
195196
await this.handleLanguageUpgrade(message)
196197
return
197198
}

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

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -591,8 +591,6 @@ export const jobPartiallyCompletedNotification = `Amazon Q ${getTransformationAc
591591

592592
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}).`
593593

594-
export const noPomXmlFoundNotification = `None of your open projects are supported by Amazon Q Code Transformation. Amazon Q could not find a pom.xml file in any of your open projects. Currently, Amazon Q can only upgrade Java 8 or Java 11 projects built on Maven. For more information, see the [Amazon Q documentation](${codeTransformPrereqDoc}).`
595-
596594
export const noJavaHomeFoundChatMessage = `Sorry, I couldn\'t locate your Java installation. For more information, see the [Amazon Q documentation](${codeTransformPrereqDoc}).`
597595

598596
export const dependencyVersionsErrorMessage =
@@ -629,9 +627,9 @@ export const changesAppliedChatMessage = 'I applied the changes to your project.
629627

630628
export const changesAppliedNotification = 'Amazon Q applied the changes to your project.'
631629

632-
export const noOpenProjectsFoundChatMessage = `Sorry, I couldn\'t find a project that I can upgrade. Currently, I can only upgrade Java 8 or Java 11 projects built on Maven. For more information, see the [Amazon Q documentation](${codeTransformPrereqDoc}).`
630+
export const noOpenProjectsFoundChatMessage = `I couldn't find a project that I can transform. Please open a Java project and try again. For more information, see the [Amazon Q documentation](${codeTransformPrereqDoc}).`
633631

634-
export const noJavaProjectsFoundChatMessage = `Sorry, I couldn\'t find a project that I can upgrade. Currently, I can only upgrade Java 8 or Java 11 projects built on Maven. For more information, see the [Amazon Q documentation](${codeTransformPrereqDoc}).`
632+
export const noJavaProjectsFoundChatMessage = `I couldn't find a project that I can transform. Please open a Java project and try again. For more information, see the [Amazon Q documentation](${codeTransformPrereqDoc}).`
635633

636634
export const linkToDocsHome = 'https://docs.aws.amazon.com/amazonq/latest/aws-builder-use-ug/code-transformation.html'
637635

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

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,8 @@ export async function uploadPayload(payloadFileName: string, uploadContext?: Upl
231231
*/
232232
const mavenExcludedExtensions = ['.repositories', '.sha1']
233233

234+
const sourceExcludedExtensions = ['.DS_Store']
235+
234236
/**
235237
* Determines if the specified file path corresponds to a Maven metadata file
236238
* by checking against known metadata file extensions. This is used to identify
@@ -243,24 +245,22 @@ function isExcludedDependencyFile(path: string): boolean {
243245
return mavenExcludedExtensions.some((extension) => path.endsWith(extension))
244246
}
245247

246-
/**
247-
* Gets all files in dir. We use this method to get the source code, then we run a mvn command to
248-
* copy over dependencies into their own folder, then we use this method again to get those
249-
* dependencies. If isDependenciesFolder is true, then we are getting all the files
250-
* of the dependencies which were copied over by the previously-run mvn command, in which case
251-
* we DO want to include any dependencies that may happen to be named "target", hence the check
252-
* in the first part of the IF statement. The point of excluding folders named target is that
253-
* "target" is also the name of the folder where .class files, large JARs, etc. are stored after
254-
* building, and we do not want these included in the ZIP so we exclude these when calling
255-
* getFilesRecursively on the source code folder.
256-
*/
248+
// do not zip the .DS_Store file as it may appear in the diff.patch
249+
function isExcludedSourceFile(path: string): boolean {
250+
return sourceExcludedExtensions.some((extension) => path.endsWith(extension))
251+
}
252+
253+
// zip all dependency files and all source files excluding "target" (contains large JARs) plus ".git" and ".idea" (may appear in diff.patch)
257254
function getFilesRecursively(dir: string, isDependenciesFolder: boolean): string[] {
258255
const entries = nodefs.readdirSync(dir, { withFileTypes: true })
259256
const files = entries.flatMap((entry) => {
260257
const res = path.resolve(dir, entry.name)
261-
// exclude 'target' directory from ZIP (except if zipping dependencies) due to issues in backend
262258
if (entry.isDirectory()) {
263-
if (isDependenciesFolder || entry.name !== 'target') {
259+
if (isDependenciesFolder) {
260+
// include all dependency files
261+
return getFilesRecursively(res, isDependenciesFolder)
262+
} else if (entry.name !== 'target' && entry.name !== '.git' && entry.name !== '.idea') {
263+
// exclude the above directories when zipping source code
264264
return getFilesRecursively(res, isDependenciesFolder)
265265
} else {
266266
return []
@@ -309,8 +309,8 @@ export async function zipCode(
309309
const sourceFiles = getFilesRecursively(projectPath, false)
310310
let sourceFilesSize = 0
311311
for (const file of sourceFiles) {
312-
if (nodefs.statSync(file).isDirectory()) {
313-
getLogger().info('CodeTransformation: Skipping directory, likely a symlink')
312+
if (nodefs.statSync(file).isDirectory() || isExcludedSourceFile(file)) {
313+
getLogger().info('CodeTransformation: Skipping file')
314314
continue
315315
}
316316
const relativePath = path.relative(projectPath, file)

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

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,12 @@ export class DiffModel {
144144
*/
145145
public parseDiff(pathToDiff: string, pathToWorkspace: string): ProposedChangeNode[] {
146146
const diffContents = fs.readFileSync(pathToDiff, 'utf8')
147+
148+
if (!diffContents.trim()) {
149+
getLogger().error(`CodeTransformation: diff.patch file is empty`)
150+
throw new Error('No changes were made as a part of this transformation.')
151+
}
152+
147153
const changedFiles = parsePatch(diffContents)
148154
// path to the directory containing copy of the changed files in the transformed project
149155
const pathToTmpSrcDir = this.copyProject(pathToWorkspace, changedFiles)
@@ -372,13 +378,12 @@ export class ProposedTransformationExplorer {
372378
pathContainingArchive = path.dirname(pathToArchive)
373379
const zip = new AdmZip(pathToArchive)
374380
zip.extractAllTo(pathContainingArchive)
381+
375382
// TODO: below only needed if the backend cannot fix the "b/" diff.patch issue
376-
// read in the diff.patch
377383
const diffPatch = fs.readFileSync(
378384
path.join(pathContainingArchive, ExportResultArchiveStructure.PathToDiffPatch),
379385
'utf-8'
380386
)
381-
// go through each line, and replace "b" with "b/" on lines that start with "diff"
382387
const lines = diffPatch.split('\n')
383388
const newLines = lines.map((line) => {
384389
if (line.trim().startsWith('diff') || line.trim().startsWith('+++')) {
@@ -391,6 +396,7 @@ export class ProposedTransformationExplorer {
391396
path.join(pathContainingArchive, ExportResultArchiveStructure.PathToDiffPatch),
392397
newDiffPatch
393398
)
399+
394400
diffModel.parseDiff(
395401
path.join(pathContainingArchive, ExportResultArchiveStructure.PathToDiffPatch),
396402
transformByQState.getProjectPath()

packages/core/src/dev/config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,4 @@ export const betaUrl = {
1212
}
1313

1414
// feature flag for SQL transformations
15-
export const isSQLTransformReady = false
15+
export const isSQLTransformReady = true

0 commit comments

Comments
 (0)