Skip to content
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

♻️ Added logic to set rule title, uri, and isArchived #1440

Merged
merged 11 commits into from
Sep 11, 2024
29 changes: 29 additions & 0 deletions build-scripts/update-rule-history.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ $historyChangeEntry = $listOfCommits -join "<LINE>"
$historyArray = $historyChangeEntry -split "<HISTORY_ENTRY>"

$commitSyncHash = "";
$rulesContentFolder = "./SSW.Rules.Content/"

$historyArray | Foreach-Object {
$historyEntry = $_ -split "<FILES_CHANGED>"
$userDetails = $historyEntry[0] -split "<LINE>"
Expand All @@ -56,12 +58,39 @@ $historyArray | Foreach-Object {
$fileArray | Where-Object {$_ -Match "^*.md" } | Foreach-Object {
if(!$filesProcessed.ContainsKey($_))
{
$fullPath = Join-Path $rulesContentFolder $_
$createdRecord = git log --diff-filter=A --reverse --pretty="%ad<LINE>%aN<LINE>%ae<LINE>" --date=iso-strict -- $_
$createdDetails = $createdRecord -split "<LINE>"

# Read and parse Markdown file to set title, uri, and archived status
$utf8NoBomEncoding = New-Object System.Text.UTF8Encoding $false
$streamReader = New-Object System.IO.StreamReader -Arg $fullPath, $utf8NoBomEncoding
$content = $streamReader.ReadToEnd()
$streamReader.Close()

$lines = $content -split "`n"
$title = ""
$uri = ""
$isArchived = $false

$titleLine = $lines | Where-Object { $_.StartsWith('title:') }
$title = $titleLine.Substring(6).Trim()

$uriLine = $lines | Where-Object { $_.Trim().StartsWith('uri:') }
$uri = $uriLine.Substring(4).Trim()

$archivedReasonLine = $lines | Where-Object { $_.Replace(' ', '').StartsWith('archivedreason:') }
if ($archivedReasonLine) {
$archivedReason = $archivedReasonLine.Trim().Substring(15).Trim()
$isArchived = $archivedReason -ne 'null' -and $archivedReason -ne ''
}

$filesProcessed.Add($_, 0)
$historyFileArray += @{
file = $($_)
title = $title
uri = $uri
isArchived = $isArchived
lastUpdated = $lastUpdated
lastUpdatedBy = $lastUpdatedBy
lastUpdatedByEmail = $lastUpdatedByEmail
Expand Down
Loading