Skip to content

Commit e68c4a8

Browse files
Add Pattern parameter to filter test files
Introduces a new 'Pattern' parameter to Repair-PullRequestTest, allowing users to filter test files by name using wildcards. Updates logic to apply this filter when processing failed tests and enhances verbose output to reflect the applied pattern.
1 parent fb96c05 commit e68c4a8

File tree

1 file changed

+19
-3
lines changed

1 file changed

+19
-3
lines changed

.aitools/module/Repair-PullRequestTest.ps1

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,10 @@ function Repair-PullRequestTest {
2626
from the development branch to the current branch, without running Update-PesterTest
2727
or committing any changes.
2828
29+
.PARAMETER Pattern
30+
Pattern to filter test files. Only files matching this pattern will be processed.
31+
Supports wildcards (e.g., "*Login*" to match files containing "Login").
32+
2933
.NOTES
3034
Tags: Testing, Pester, PullRequest, CI
3135
Author: dbatools team
@@ -53,7 +57,8 @@ function Repair-PullRequestTest {
5357
[switch]$AutoCommit,
5458
[int]$MaxPRs = 5,
5559
[int]$BuildNumber,
56-
[switch]$CopyOnly
60+
[switch]$CopyOnly,
61+
[string]$Pattern
5762
)
5863

5964
begin {
@@ -269,7 +274,14 @@ function Repair-PullRequestTest {
269274
$fileErrorPath = @()
270275
$testdirectory = Join-Path $script:ModulePath "tests"
271276

272-
foreach ($test in $allFailedTestsAcrossPRs) {
277+
# Apply Pattern filter first if specified
278+
$filteredTests = if ($Pattern) {
279+
$allFailedTestsAcrossPRs | Where-Object { [System.IO.Path]::GetFileName($_.TestFile) -match $Pattern }
280+
} else {
281+
$allFailedTestsAcrossPRs
282+
}
283+
284+
foreach ($test in $filteredTests) {
273285
$fileName = [System.IO.Path]::GetFileName($test.TestFile)
274286
# ONLY include files that are actually in the PR changes
275287
if ($allRelevantTestFiles.Count -eq 0 -or $fileName -in $allRelevantTestFiles) {
@@ -284,7 +296,11 @@ function Repair-PullRequestTest {
284296
}
285297
}
286298
$fileErrorPath = $fileErrorPath | Sort-Object -Unique
287-
Write-Verbose "Found failures in $($fileErrorMap.Keys.Count) unique test files (filtered to PR changes only)"
299+
$filterMessage = "filtered to PR changes only"
300+
if ($Pattern) {
301+
$filterMessage += " and pattern '$Pattern'"
302+
}
303+
Write-Verbose "Found failures in $($fileErrorMap.Keys.Count) unique test files ($filterMessage)"
288304
foreach ($fileName in $fileErrorMap.Keys) {
289305
Write-Verbose " ${fileName} - $($fileErrorMap[$fileName].Count) failures"
290306
Write-Verbose " Paths: $fileErrorPath"

0 commit comments

Comments
 (0)