Skip to content

Commit 3ef7378

Browse files
author
David Hasani
committed
handle empty diff
1 parent edb3fa2 commit 3ef7378

File tree

4 files changed

+25
-18
lines changed

4 files changed

+25
-18
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/service/transformByQ/transformApiHandler.ts

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

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

247-
/**
248-
* Gets all files in dir. We use this method to get the source code, then we run a mvn command to
249-
* copy over dependencies into their own folder, then we use this method again to get those
250-
* dependencies. If isDependenciesFolder is true, then we are getting all the files
251-
* of the dependencies which were copied over by the previously-run mvn command, in which case
252-
* we DO want to include any dependencies that may happen to be named "target", hence the check
253-
* in the first part of the IF statement. The point of excluding folders named target is that
254-
* "target" is also the name of the folder where .class files, large JARs, etc. are stored after
255-
* building, and we do not want these included in the ZIP so we exclude these when calling
256-
* getFilesRecursively on the source code folder.
257-
*/
249+
// do not zip the .DS_Store file as it may appear in the diff.patch
250+
function isExcludedSourceFile(path: string): boolean {
251+
return sourceExcludedExtensions.some((extension) => path.endsWith(extension))
252+
}
253+
254+
// zip all dependency files and all source files excluding "target" (contains large JARs) plus ".git" and ".idea" (may appear in diff.patch)
258255
function getFilesRecursively(dir: string, isDependenciesFolder: boolean): string[] {
259256
const entries = nodefs.readdirSync(dir, { withFileTypes: true })
260257
const files = entries.flatMap((entry) => {
261258
const res = path.resolve(dir, entry.name)
262-
// exclude 'target' directory from ZIP (except if zipping dependencies) due to issues in backend
263259
if (entry.isDirectory()) {
264-
if (isDependenciesFolder || entry.name !== 'target') {
260+
if (isDependenciesFolder) {
261+
// include all dependency files
262+
return getFilesRecursively(res, isDependenciesFolder)
263+
} else if (entry.name !== 'target' && entry.name !== '.git' && entry.name !== '.idea') {
264+
// exclude the above directories when zipping source code
265265
return getFilesRecursively(res, isDependenciesFolder)
266266
} else {
267267
return []
@@ -310,8 +310,8 @@ export async function zipCode(
310310
const sourceFiles = getFilesRecursively(projectPath, false)
311311
let sourceFilesSize = 0
312312
for (const file of sourceFiles) {
313-
if (nodefs.statSync(file).isDirectory()) {
314-
getLogger().info('CodeTransformation: Skipping directory, likely a symlink')
313+
if (nodefs.statSync(file).isDirectory() || isExcludedSourceFile(file)) {
314+
getLogger().info('CodeTransformation: Skipping file')
315315
continue
316316
}
317317
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
@@ -145,6 +145,12 @@ export class DiffModel {
145145
*/
146146
public parseDiff(pathToDiff: string, pathToWorkspace: string): ProposedChangeNode[] {
147147
const diffContents = fs.readFileSync(pathToDiff, 'utf8')
148+
149+
if (!diffContents.trim()) {
150+
getLogger().error(`CodeTransformation: diff.patch file is empty`)
151+
throw new Error('No changes were made as a part of this transformation.')
152+
}
153+
148154
const changedFiles = parsePatch(diffContents)
149155
// path to the directory containing copy of the changed files in the transformed project
150156
const pathToTmpSrcDir = this.copyProject(pathToWorkspace, changedFiles)
@@ -373,13 +379,12 @@ export class ProposedTransformationExplorer {
373379
pathContainingArchive = path.dirname(pathToArchive)
374380
const zip = new AdmZip(pathToArchive)
375381
zip.extractAllTo(pathContainingArchive)
382+
376383
// TODO: below only needed if the backend cannot fix the "b/" diff.patch issue
377-
// read in the diff.patch
378384
const diffPatch = fs.readFileSync(
379385
path.join(pathContainingArchive, ExportResultArchiveStructure.PathToDiffPatch),
380386
'utf-8'
381387
)
382-
// go through each line, and replace "b" with "b/" on lines that start with "diff"
383388
const lines = diffPatch.split('\n')
384389
const newLines = lines.map((line) => {
385390
if (line.trim().startsWith('diff') || line.trim().startsWith('+++')) {
@@ -392,6 +397,7 @@ export class ProposedTransformationExplorer {
392397
path.join(pathContainingArchive, ExportResultArchiveStructure.PathToDiffPatch),
393398
newDiffPatch
394399
)
400+
395401
diffModel.parseDiff(
396402
path.join(pathContainingArchive, ExportResultArchiveStructure.PathToDiffPatch),
397403
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)