|
1 |
| -param( |
2 |
| - [Parameter(Mandatory = $true)][string] $RepoUrl, |
3 |
| - [Parameter(Mandatory = $true)][string] $OldTag, |
4 |
| - [Parameter(Mandatory = $true)][string] $NewTag |
5 |
| -) |
6 |
| - |
7 |
| -Set-StrictMode -Version latest |
8 |
| - |
9 |
| -$prefix = 'https?://(www\.)?github.com/' |
10 |
| -if (-not ($RepoUrl -match "^$prefix")) |
11 |
| -{ |
12 |
| - Write-Warning "Only github.com repositories are currently supported. Given RepoUrl doesn't look like one: $RepoUrl" |
13 |
| - return |
14 |
| -} |
15 |
| - |
16 |
| -$tmpDir = Join-Path ([System.IO.Path]::GetTempPath()) ([System.Guid]::NewGuid()) |
17 |
| - |
18 |
| -try |
19 |
| -{ |
20 |
| - git clone --depth 1 $RepoUrl $tmpDir |
21 |
| - |
22 |
| - $file = $(Get-ChildItem -Path $tmpDir | Where-Object { $_.Name -match '^changelog(\.md|\.txt|)$' } ) |
23 |
| - if ("$file" -eq "") |
24 |
| - { |
25 |
| - Write-Warning "Couldn't find a changelog" |
26 |
| - return |
27 |
| - } |
28 |
| - elseif ($file -is [Array]) |
29 |
| - { |
30 |
| - Write-Warning "Multiple changelogs found: $file" |
31 |
| - return |
32 |
| - } |
33 |
| - Write-Host "Found changelog: $file" |
34 |
| - [string[]]$lines = Get-Content $file |
35 |
| -} |
36 |
| -finally |
37 |
| -{ |
38 |
| - Write-Host "Removing $tmpDir" |
39 |
| - Remove-Item -Recurse -Force -ErrorAction Continue -Path $tmpDir |
40 |
| -} |
41 |
| - |
42 |
| -$foundFirst = $false |
43 |
| -$changelog = "" |
44 |
| -for ($i = 0; $i -lt $lines.Count; $i++) |
45 |
| -{ |
46 |
| - $line = $lines[$i] |
47 |
| - |
48 |
| - if (-not $foundFirst) |
49 |
| - { |
50 |
| - if ($line -match "^#+ +v?$NewTag\b") |
51 |
| - { |
52 |
| - $foundFirst = $true |
53 |
| - } |
54 |
| - else |
55 |
| - { |
56 |
| - continue |
57 |
| - } |
58 |
| - } |
59 |
| - elseif ($line -match "^#+ +v?$OldTag\b") |
60 |
| - { |
61 |
| - break |
62 |
| - } |
63 |
| - |
64 |
| - $changelog += "$line`n" |
65 |
| -} |
66 |
| - |
67 |
| -$changelog = $changelog.Trim() |
68 |
| -if ($changelog.Length -gt 1) |
69 |
| -{ |
70 |
| - $changelog = "# Changelog`n$changelog" |
71 |
| - # Increase header level by one. |
72 |
| - $changelog = $changelog -replace "(#+) ", '$1# ' |
73 |
| - # Remove at-mentions. |
74 |
| - $changelog = $changelog -replace '@', '' |
75 |
| - # Make PR/issue references into links to the original repository (unless they already are links). |
76 |
| - $changelog = $changelog -replace '(?<!\[)#([0-9]+)', ('[#$1](' + $RepoUrl + '/issues/$1)') |
77 |
| - # Replace any links pointing to github.com so that the target PRs/Issues don't get na notification. |
78 |
| - $changelog = $changelog -replace ('\(' + $prefix), '(https://github-redirect.dependabot.com/' |
79 |
| -} |
80 |
| - |
81 |
| -# Limit the changelog length to ~60k to allow for other text in the PR body (total PR limit is 65536 characters). |
82 |
| -$limit = 60000 |
83 |
| -if ($changelog.Length -gt $limit) |
84 |
| -{ |
85 |
| - $oldLength = $changelog.Length |
86 |
| - Write-Warning "Truncating changelog because it's $($changelog.Length - $limit) characters longer than the limit $limit." |
87 |
| - while ($changelog.Length -gt $limit) |
88 |
| - { |
89 |
| - $changelog = $changelog.Substring(0, $changelog.LastIndexOf("`n")) |
90 |
| - } |
91 |
| - $changelog += "`n`n> :warning: **Changelog content truncated by $($oldLength - $changelog.Length) characters because it was over the limit ($limit) and wouldn't fit into PR description.**" |
92 |
| -} |
93 |
| - |
94 |
| -$changelog |
| 1 | +param( |
| 2 | + [Parameter(Mandatory = $true)][string] $RepoUrl, |
| 3 | + [Parameter(Mandatory = $true)][string] $OldTag, |
| 4 | + [Parameter(Mandatory = $true)][string] $NewTag |
| 5 | +) |
| 6 | + |
| 7 | +Set-StrictMode -Version latest |
| 8 | + |
| 9 | +$prefix = 'https?://(www\.)?github.com/' |
| 10 | +if (-not ($RepoUrl -match "^$prefix")) |
| 11 | +{ |
| 12 | + Write-Warning "Only github.com repositories are currently supported. Given RepoUrl doesn't look like one: $RepoUrl" |
| 13 | + return |
| 14 | +} |
| 15 | + |
| 16 | +$tmpDir = Join-Path ([System.IO.Path]::GetTempPath()) ([System.Guid]::NewGuid()) |
| 17 | + |
| 18 | +try |
| 19 | +{ |
| 20 | + git clone --depth 1 $RepoUrl $tmpDir |
| 21 | + |
| 22 | + $file = $(Get-ChildItem -Path $tmpDir | Where-Object { $_.Name -match '^changelog(\.md|\.txt|)$' } ) |
| 23 | + if ("$file" -eq "") |
| 24 | + { |
| 25 | + Write-Warning "Couldn't find a changelog" |
| 26 | + return |
| 27 | + } |
| 28 | + elseif ($file -is [Array]) |
| 29 | + { |
| 30 | + Write-Warning "Multiple changelogs found: $file" |
| 31 | + return |
| 32 | + } |
| 33 | + Write-Host "Found changelog: $file" |
| 34 | + [string[]]$lines = Get-Content $file |
| 35 | +} |
| 36 | +finally |
| 37 | +{ |
| 38 | + Write-Host "Removing $tmpDir" |
| 39 | + Remove-Item -Recurse -Force -ErrorAction Continue -Path $tmpDir |
| 40 | +} |
| 41 | + |
| 42 | +$foundFirst = $false |
| 43 | +$changelog = "" |
| 44 | +for ($i = 0; $i -lt $lines.Count; $i++) |
| 45 | +{ |
| 46 | + $line = $lines[$i] |
| 47 | + |
| 48 | + if (-not $foundFirst) |
| 49 | + { |
| 50 | + if ($line -match "^#+ +v?$NewTag\b") |
| 51 | + { |
| 52 | + $foundFirst = $true |
| 53 | + } |
| 54 | + else |
| 55 | + { |
| 56 | + continue |
| 57 | + } |
| 58 | + } |
| 59 | + elseif ($line -match "^#+ +v?$OldTag\b") |
| 60 | + { |
| 61 | + break |
| 62 | + } |
| 63 | + |
| 64 | + $changelog += "$line`n" |
| 65 | +} |
| 66 | + |
| 67 | +$changelog = $changelog.Trim() |
| 68 | +if ($changelog.Length -gt 1) |
| 69 | +{ |
| 70 | + $changelog = "# Changelog`n$changelog" |
| 71 | + # Increase header level by one. |
| 72 | + $changelog = $changelog -replace "(#+) ", '$1# ' |
| 73 | + # Remove at-mentions. |
| 74 | + $changelog = $changelog -replace '@', '' |
| 75 | + # Make PR/issue references into links to the original repository (unless they already are links). |
| 76 | + $changelog = $changelog -replace '(?<!\[)#([0-9]+)', ('[#$1](' + $RepoUrl + '/issues/$1)') |
| 77 | + # Replace any links pointing to github.com so that the target PRs/Issues don't get na notification. |
| 78 | + $changelog = $changelog -replace ('\(' + $prefix), '(https://github-redirect.dependabot.com/' |
| 79 | +} |
| 80 | + |
| 81 | +# Limit the changelog length to ~60k to allow for other text in the PR body (total PR limit is 65536 characters). |
| 82 | +$limit = 60000 |
| 83 | +if ($changelog.Length -gt $limit) |
| 84 | +{ |
| 85 | + $oldLength = $changelog.Length |
| 86 | + Write-Warning "Truncating changelog because it's $($changelog.Length - $limit) characters longer than the limit $limit." |
| 87 | + while ($changelog.Length -gt $limit) |
| 88 | + { |
| 89 | + $changelog = $changelog.Substring(0, $changelog.LastIndexOf("`n")) |
| 90 | + } |
| 91 | + $changelog += "`n`n> :warning: **Changelog content truncated by $($oldLength - $changelog.Length) characters because it was over the limit ($limit) and wouldn't fit into PR description.**" |
| 92 | +} |
| 93 | + |
| 94 | +$changelog |
0 commit comments