diff --git a/helpers/Build-Help.ps1 b/helpers/Build-Help.ps1 index 933f032..3cda1d0 100644 --- a/helpers/Build-Help.ps1 +++ b/helpers/Build-Help.ps1 @@ -14,4 +14,72 @@ Import-Module .\output\module\M365FoundationsCISReport\*\*.psd1 # git tag -d $ver #> +# Refresh authentication to ensure the correct scopes +gh auth refresh -s project,read:project,write:project,repo +# Create the project +gh project create --owner CriticalSolutionsNetwork --title "Test Validation Project" + +$repoOwner = "CriticalSolutionsNetwork" +$repoName = "M365FoundationsCISReport" +$directoryPath = ".\source\tests" +$projectName = "Test Validation Project" + +# Function to create GitHub issues +function Create-GitHubIssue { + param ( + [string]$title, + [string]$body, + [string]$project + ) + + # Create the issue and add it to the specified project + $issue = gh issue create --repo "$repoOwner/$repoName" --title "$title" --body "$body" --project "$project" + return $issue +} + +# Load test definitions from CSV +$testDefinitionsPath = ".\source\helper\TestDefinitions.csv" +$testDefinitions = Import-Csv -Path $testDefinitionsPath + +# Iterate over each .ps1 file in the directory +Get-ChildItem -Path $directoryPath -Filter "*.ps1" | ForEach-Object { + $fileName = $_.Name + $testDefinition = $testDefinitions | Where-Object { $_.TestFileName -eq $fileName } + + if ($testDefinition) { + $rec = $testDefinition.Rec + $elevel = $testDefinition.ELevel + $profileLevel = $testDefinition.ProfileLevel + $ig1 = $testDefinition.IG1 + $ig2 = $testDefinition.IG2 + $ig3 = $testDefinition.IG3 + $connection = $testDefinition.Connection + + $issueTitle = "Rec: $rec - Validate $fileName, ELevel: $elevel, ProfileLevel: $profileLevel, IG1: $ig1, IG2: $ig2, IG3: $ig3, Connection: $connection" + $issueBody = @" +# Validation for $fileName + +## Tasks +- [ ] Validate test for a pass + - Description of passing criteria: +- [ ] Validate test for a fail + - Description of failing criteria: +- [ ] Add notes and observations + - Placeholder for additional notes: +"@ + + # Create the issue using GitHub CLI + try { + Create-GitHubIssue -title "$issueTitle" -body "$issueBody" -project "$projectName" + Write-Output "Created issue for $fileName" + } catch { + Write-Error "Failed to create issue for $fileName : $_" + } + + # Introduce a delay of 2 seconds + Start-Sleep -Seconds 2 + } else { + Write-Warning "No matching test definition found for $fileName" + } +}