-
Notifications
You must be signed in to change notification settings - Fork 262
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
Conversation
219b520
to
8e36b25
Compare
...s-community/src/software/aws/toolkits/jetbrains/services/amazonq/FeatureDevSessionContext.kt
Fixed
Show fixed
Hide fixed
...t/software/aws/toolkits/jetbrains/services/amazonqFeatureDev/FeatureDevSessionContextTest.kt
Show resolved
Hide resolved
...t/software/aws/toolkits/jetbrains/services/amazonqFeatureDev/FeatureDevSessionContextTest.kt
Show resolved
Hide resolved
"file.png/", | ||
"src/file.png/" | ||
) | ||
val expectedFilesToMatch = listOf(".gitignore/", ".env/", "file.txt/", "build/", "build/output.jar/", "log.txt/", "file.png/", "src/file.png/") |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
updated
for (sampleFileName in sampleFileNames) { | ||
for (pattern in patterns) { | ||
if (pattern.matches(sampleFileName)) { | ||
matchedFiles.add(sampleFileName) | ||
break | ||
} | ||
} | ||
} |
There was a problem hiding this comment.
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)}}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
makes sense, updating
...s-community/src/software/aws/toolkits/jetbrains/services/amazonq/FeatureDevSessionContext.kt
Outdated
Show resolved
Hide resolved
371d0eb
to
d860beb
Compare
b55c947
to
668f385
Compare
d2cb0ed
to
34ded4d
Compare
"mybuild/", | ||
"build.json/", | ||
"log.txt/", | ||
"file.txt.json/", |
There was a problem hiding this comment.
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 '/' ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
there's a trailing / added when matching files as per the comment
https://github.com/aws/aws-toolkit-jetbrains/blob/main/plugins/core/jetbrains-community/src/software/aws/toolkits/jetbrains/services/amazonq/FeatureDevSessionContext.kt#L285
fa5f45c
to
9350f89
Compare
9350f89
to
fb597cc
Compare
Updating .gitignore pattern to regex conversion to factor for following edge cases:
.*
should be matching only files starting with.
now, instead of all files previouslyAs 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
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
.*
caseChecklist
License
I confirm that my contribution is made under the terms of the Apache 2.0 license.