From 454fac8676d9cc9e75b6220cf04c6f8ecc95f5ad Mon Sep 17 00:00:00 2001 From: Tim Keller Date: Thu, 8 Aug 2024 15:23:45 +0200 Subject: [PATCH] fix selection of newest jira state file --- WASP/Private/Read-JiraStateFile.ps1 | 18 +++++------------- 1 file changed, 5 insertions(+), 13 deletions(-) diff --git a/WASP/Private/Read-JiraStateFile.ps1 b/WASP/Private/Read-JiraStateFile.ps1 index 94590cd..17ec828 100644 --- a/WASP/Private/Read-JiraStateFile.ps1 +++ b/WASP/Private/Read-JiraStateFile.ps1 @@ -9,7 +9,7 @@ function Read-JiraStateFile () { Author: Tim Keller Contact: tim.keller@unibas.ch Created: 2024-07-04 - Updated: 2024-07-16 + Updated: 2024-08-08 Version: 1.0.0 #> param( @@ -21,18 +21,14 @@ function Read-JiraStateFile () { $JiraStateFolder = Join-Path -Path $LogPath -ChildPath $Config.Logger.LogSubFilePathJiraStates } process { try { - <#Create a ordered hashtable to find the newest jira state file in the jira state folder#> - $AvailableFiles = [Ordered]@{} + <#Create a hashtable to find the newest jira state file in the jira state folder#> + $AvailableFiles = @{} $Prefix = $Config.Logger.LogFileNamePrefixJiraStates $Suffix = ".json" <#Extract the date from the jira state logs and add them to the AvailabeFiles hashtable#> Get-ChildItem -Path $JiraStateFolder | ForEach-Object {$AvailableFiles[$_.Name] = $([datetime]::parseexact($($_.Name -replace "$Prefix(.+)$Suffix", '$1'), 'yyyy-MM-dd_HH-mm-ss', $null))} - foreach($item in $date_array) - { - $item -replace "$Prefix(.+)$Suffix", '$1' - } - <#Get the full file path of the newest jira state file and convert it from json#> - $FilePath= Join-Path -Path (Get-Item -Path $JiraStateFolder).FullName -ChildPath $($AvailableFiles.Keys | Select-Object -Last 1) + <#Get the full file path of the newest jira state file and convert it from json. The newest file is selected by ordering the available jira state files by date and selecting the last one in the list.#> + $FilePath= Join-Path -Path (Get-Item -Path $JiraStateFolder).FullName -ChildPath $($AvailableFiles.GetEnumerator() | Sort-Object {$_.Value} | Select-Object -Last 1).Key $JiraState = Get-Content -Path $FilePath -Raw | ConvertFrom-Json -ErrorAction Stop <#Put the the information of the jira state log into the format that the name@version is the key of the hashtable and the status and assignee are the values#> $IssuesState = @{} @@ -49,7 +45,3 @@ function Read-JiraStateFile () { return $IssuesState } } - - - -