-
Notifications
You must be signed in to change notification settings - Fork 274
fix(amazonq): fix for /test project payload collection filter #5305
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
Changes from 8 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
c051d8f
Fix to decouple gitignore logic to run it module level.
ashishrp-aws 4af555f
Added changelog for bug fix
ashishrp-aws 1c58a91
Merge branch 'main' into test
ashishrp-aws e6bb632
Reduced number of variables in test class and corrected assert statem…
ashishrp-aws b4b2db5
Further reduction for variables.
ashishrp-aws f0dfc03
Merge branch 'main' into test
ashishrp-aws e9e1a01
Removed ignoreFile with file path.
ashishrp-aws 2ea7759
Update .changes/next-release/bugfix-52963f8d-8f8e-4b53-b7dc-0ef4819b5…
ashishrp-aws d262131
Fix for detektMain errors
ashishrp-aws File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
4 changes: 4 additions & 0 deletions
4
.changes/next-release/bugfix-52963f8d-8f8e-4b53-b7dc-0ef4819b5976.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| { | ||
| "type" : "bugfix", | ||
| "description" : "Amazon Q /test: Fixed an issue which incorrectly caused payload size exceeded exception when collecting project payload files" | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
102 changes: 102 additions & 0 deletions
102
...src/software/aws/toolkits/jetbrains/services/codewhisperer/util/GitIgnoreFilteringUtil.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,102 @@ | ||
| // Copyright 2025 Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| package software.aws.toolkits.jetbrains.services.codewhisperer.util | ||
|
|
||
| import com.intellij.openapi.vfs.VfsUtil | ||
| import com.intellij.openapi.vfs.VirtualFile | ||
| import kotlinx.coroutines.async | ||
| import kotlinx.coroutines.withContext | ||
| import kotlin.coroutines.coroutineContext | ||
|
|
||
| class GitIgnoreFilteringUtil(private val moduleDir: VirtualFile) { | ||
| private var ignorePatternsWithGitIgnore = emptyList<Regex>() | ||
| private val additionalGitIgnoreRules = setOf( | ||
| ".aws-sam", | ||
| ".gem", | ||
| ".git", | ||
| ".gitignore", | ||
| ".gradle", | ||
| ".hg", | ||
| ".idea", | ||
| ".project", | ||
| ".rvm", | ||
| ".svn", | ||
| "*.zip", | ||
| "*.bin", | ||
| "*.png", | ||
| "*.jpg", | ||
| "*.svg", | ||
| "*.pyc", | ||
| "license.txt", | ||
| "License.txt", | ||
| "LICENSE.txt", | ||
| "license.md", | ||
| "License.md", | ||
| "LICENSE.md", | ||
| "node_modules", | ||
| "build", | ||
| "dist", | ||
| "annotation-generated-src", | ||
| "annotation-generated-tst" | ||
| ) | ||
|
|
||
| init { | ||
| ignorePatternsWithGitIgnore = try { | ||
| buildList { | ||
| addAll(additionalGitIgnoreRules.map { convertGitIgnorePatternToRegex(it) }) | ||
| addAll(parseGitIgnore()) | ||
| }.mapNotNull { pattern -> | ||
| runCatching { Regex(pattern) }.getOrNull() | ||
| } | ||
| } catch (e: Exception) { | ||
| emptyList() | ||
| } | ||
| } | ||
|
|
||
| private fun parseGitIgnore(): Set<String> { | ||
| val gitignoreFile = moduleDir.findChild(".gitignore") | ||
| return gitignoreFile?.let { | ||
| if (it.isValid && it.exists()) { | ||
| it.inputStream.bufferedReader().readLines() | ||
| .filter { line -> | ||
| line.isNotBlank() && !line.startsWith("#") | ||
| } | ||
| .map { pattern -> | ||
| convertGitIgnorePatternToRegex(pattern.trim()) | ||
| } | ||
| .toSet() | ||
| } else { | ||
| emptySet() | ||
| } | ||
| } ?: emptySet() | ||
| } | ||
|
|
||
| // gitignore patterns are not regex, method update needed. | ||
| private fun convertGitIgnorePatternToRegex(pattern: String): String = pattern | ||
| .replace(".", "\\.") | ||
| .replace("*", ".*") | ||
| .let { if (it.endsWith("/")) "$it.*" else "$it/.*" } // Add a trailing /* to all patterns. (we add a trailing / to all files when matching) | ||
|
|
||
| suspend fun ignoreFile(file: VirtualFile): Boolean { | ||
ashishrp-aws marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| // this method reads like something a JS dev would write and doesn't do what the author thinks | ||
| val deferredResults = ignorePatternsWithGitIgnore.map { pattern -> | ||
| withContext(coroutineContext) { | ||
| // avoid partial match (pattern.containsMatchIn) since it causes us matching files | ||
| // against folder patterns. (e.g. settings.gradle ignored by .gradle rule!) | ||
| // we convert the glob rules to regex, add a trailing /* to all rules and then match | ||
| // entries against them by adding a trailing /. | ||
| // TODO: Add unit tests for gitignore matching | ||
| val relative = getRelativePath(file) | ||
| async { pattern.matches("$relative/") } | ||
| } | ||
| } | ||
|
|
||
| // this will serially iterate over and block | ||
| // ideally we race the results https://github.com/Kotlin/kotlinx.coroutines/issues/2867 | ||
| // i.e. Promise.any(...) | ||
| return deferredResults.any { it.await() } | ||
| } | ||
|
|
||
| private fun getRelativePath(file: VirtualFile): String = VfsUtil.getRelativePath(file, moduleDir) ?: "" | ||
|
||
| } | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.