Skip to content

fix(amazonq): update logic for converting gitignore pattern to regex #5360

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Feb 18, 2025

Conversation

gandhi-21
Copy link
Contributor

@gandhi-21 gandhi-21 commented Feb 11, 2025

Updating .gitignore pattern to regex conversion to factor for following edge cases:

  • .* should be matching only files starting with . now, instead of all files previously

As part of the changes, added a unit test to verify the correct regex pattern is being created and files are being matched.
Existing tests which check the file zipping logic are passing as well so no regression should be expected.

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)

Description

The current implementation to convert .gitignore patterns into regex is not following gitignore patterns and resulting in the below issues

  • .* is converted into \\..*/.* which results in all files being selected instead of the intention to only select files that start with a .. This is a special case where adding ^ in the front makes sure only files starting with . are ignored.

Changes

  • Added special handling for .* case
  • Added a unit test to check the regex patterns are matching the files as expected from the changes

Checklist

  • My code follows the code style of this project
  • I have added tests to cover my changes
  • [N/A] A short description of the change has been added to the CHANGELOG if the change is customer-facing in the IDE.
  • [N/A] I have added metrics for my changes (if required)

License

I confirm that my contribution is made under the terms of the Apache 2.0 license.

@gandhi-21 gandhi-21 requested review from a team as code owners February 11, 2025 21:15
"file.png/",
"src/file.png/"
)
val expectedFilesToMatch = listOf(".gitignore/", ".env/", "file.txt/", "build/", "build/output.jar/", "log.txt/", "file.png/", "src/file.png/")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NIT: I would move this directly above the assertion -- it took me a bit to understand what this meant in the context of the test

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updated

Comment on lines 189 to 191
for (sampleFileName in sampleFileNames) {
for (pattern in patterns) {
if (pattern.matches(sampleFileName)) {
matchedFiles.add(sampleFileName)
break
}
}
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Optional: You could do something like:

val matchedFiles = samplefileNames.filter { fileName -> patterns.find { pattern -> pattern.matches(fileName)}}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

makes sense, updating

@gandhi-21 gandhi-21 force-pushed the gitignoreChanges branch 2 times, most recently from 371d0eb to d860beb Compare February 12, 2025 18:15
@gandhi-21 gandhi-21 marked this pull request as draft February 12, 2025 18:21
@gandhi-21 gandhi-21 force-pushed the gitignoreChanges branch 2 times, most recently from b55c947 to 668f385 Compare February 12, 2025 18:22
@gandhi-21 gandhi-21 marked this pull request as ready for review February 12, 2025 18:29
"mybuild/",
"build.json/",
"log.txt/",
"file.txt.json/",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why each file name ends with '/' ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@gandhi-21 gandhi-21 force-pushed the gitignoreChanges branch 2 times, most recently from fa5f45c to 9350f89 Compare February 18, 2025 16:36
@rli rli merged commit 666798a into aws:main Feb 18, 2025
3 of 11 checks passed
@gandhi-21 gandhi-21 deleted the gitignoreChanges branch February 26, 2025 21:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants