forked from panoramicdata/PanoramicData.OData.Client
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAdd-ChangelogEntry.ps1
More file actions
180 lines (146 loc) · 5.42 KB
/
Add-ChangelogEntry.ps1
File metadata and controls
180 lines (146 loc) · 5.42 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
<#
.SYNOPSIS
Adds a new entry to the CHANGELOG.md file under the [vNext] section.
.DESCRIPTION
This script adds changelog entries to the appropriate category (Added, Changed,
Deprecated, Removed, Fixed, Security) under the [vNext] placeholder section.
The [vNext] placeholder will be replaced with the actual version number during
the publish process.
.PARAMETER Category
The changelog category. Must be one of: Added, Changed, Deprecated, Removed, Fixed, Security
.PARAMETER Message
The changelog entry message describing the change.
.EXAMPLE
.\Add-ChangelogEntry.ps1 -Category Added -Message "New feature for batch processing"
.EXAMPLE
.\Add-ChangelogEntry.ps1 -Category Fixed -Message "Resolved null reference in query builder"
.EXAMPLE
.\Add-ChangelogEntry.ps1 Added "Support for OData V4.01 features"
#>
[CmdletBinding()]
param(
[Parameter(Mandatory = $true, Position = 0)]
[ValidateSet('Added', 'Changed', 'Deprecated', 'Removed', 'Fixed', 'Security')]
[string]$Category,
[Parameter(Mandatory = $true, Position = 1)]
[string]$Message
)
$ErrorActionPreference = 'Stop'
$changelogPath = Join-Path $PSScriptRoot 'CHANGELOG.md'
if (-not (Test-Path $changelogPath)) {
Write-Error "CHANGELOG.md not found at: $changelogPath"
exit 1
}
$content = Get-Content $changelogPath -Raw
$lines = Get-Content $changelogPath
# Find the [vNext] section
$vNextIndex = -1
for ($i = 0; $i -lt $lines.Count; $i++) {
if ($lines[$i] -match '^\s*##\s*\[vNext\]') {
$vNextIndex = $i
break
}
}
if ($vNextIndex -eq -1) {
Write-Error "[vNext] section not found in CHANGELOG.md. Please ensure the changelog has a [vNext] placeholder."
exit 1
}
# Find or create the category section under [vNext]
$categoryHeader = "### $Category"
$categoryIndex = -1
$nextSectionIndex = $lines.Count
# Look for the category header between [vNext] and the next version section
for ($i = $vNextIndex + 1; $i -lt $lines.Count; $i++) {
# Stop if we hit another version section
if ($lines[$i] -match '^\s*##\s*\[[\d\.]+') {
$nextSectionIndex = $i
break
}
if ($lines[$i] -eq $categoryHeader) {
$categoryIndex = $i
}
}
# Format the entry
$entry = "- $Message"
if ($categoryIndex -ne -1) {
# Category exists - find the end of the category's entries
$insertIndex = $categoryIndex + 1
# Skip past existing entries in this category
while ($insertIndex -lt $nextSectionIndex -and
$lines[$insertIndex] -match '^\s*-' -or
[string]::IsNullOrWhiteSpace($lines[$insertIndex])) {
if ($lines[$insertIndex] -match '^\s*-') {
$insertIndex++
}
elseif ([string]::IsNullOrWhiteSpace($lines[$insertIndex])) {
# Check if next line is a new category or version
if ($insertIndex + 1 -lt $lines.Count -and $lines[$insertIndex + 1] -match '^###\s') {
break
}
$insertIndex++
}
else {
break
}
}
# Insert after the last entry in the category
$newLines = @()
$newLines += $lines[0..($categoryIndex)]
$newLines += $entry
if ($categoryIndex + 1 -lt $lines.Count) {
$newLines += $lines[($categoryIndex + 1)..($lines.Count - 1)]
}
$lines = $newLines
}
else {
# Category doesn't exist - need to add it
# Find where to insert (after [vNext] header and any existing categories, before next version)
$insertIndex = $vNextIndex + 1
# Skip any blank lines after [vNext]
while ($insertIndex -lt $nextSectionIndex -and [string]::IsNullOrWhiteSpace($lines[$insertIndex])) {
$insertIndex++
}
# Define category order
$categoryOrder = @('Added', 'Changed', 'Deprecated', 'Removed', 'Fixed', 'Security')
$targetCategoryIndex = [Array]::IndexOf($categoryOrder, $Category)
# Find the right position based on category order
$foundPosition = $false
for ($i = $insertIndex; $i -lt $nextSectionIndex; $i++) {
if ($lines[$i] -match '^###\s+(\w+)') {
$existingCategory = $Matches[1]
$existingCategoryIndex = [Array]::IndexOf($categoryOrder, $existingCategory)
if ($existingCategoryIndex -gt $targetCategoryIndex) {
# Insert before this category
$insertIndex = $i
$foundPosition = $true
break
}
}
}
if (-not $foundPosition) {
# Insert at the end of the [vNext] section (before next version or end of file)
$insertIndex = $nextSectionIndex
}
# Insert the new category with entry
$newLines = @()
if ($insertIndex -gt 0) {
$newLines += $lines[0..($insertIndex - 1)]
}
# Add blank line before if previous line isn't blank
if ($insertIndex -gt 0 -and -not [string]::IsNullOrWhiteSpace($lines[$insertIndex - 1])) {
$newLines += ''
}
$newLines += $categoryHeader
$newLines += $entry
if ($insertIndex -lt $lines.Count) {
# Add blank line after if next line isn't blank
if (-not [string]::IsNullOrWhiteSpace($lines[$insertIndex])) {
$newLines += ''
}
$newLines += $lines[$insertIndex..($lines.Count - 1)]
}
$lines = $newLines
}
# Write back to file
$lines | Set-Content $changelogPath -Encoding UTF8
Write-Host "Added to CHANGELOG.md [$Category]: $Message" -ForegroundColor Green