forked from Azure/bicep
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCreateReleaseNotes.ps1
64 lines (51 loc) · 1.67 KB
/
CreateReleaseNotes.ps1
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
<#
The script creates BIcep release notes.
Note: Non-MSFT users do not have permissions to execute this script successfully.
Prerequisites:
- GitHub CLI installed on the machine
- Completed login procedures for GH CLI
Parameters:
- WorkingDir - Directory used for temporary work. Contents will be deleted.
- TagName - The tag name of the GitHub release release. Should be in the format v<x>.<y>.<z> where <x>, <y>, and <z> are numbers.
- BuildId - Set it to a DevOps build ID to use a specific signed build instead of the latest.
#>
[CmdletBinding()]
param (
[Parameter(Mandatory = $true)]
[string] $FromTag,
[Parameter(Mandatory = $true)]
[string] $ToTag
)
$ErrorActionPreference = 'Stop';
function ValidateTag([string] $tag) {
if($tag -notmatch 'v\d+\.\d+\.\d+')
{
Write-Error "The specified tag name '$($tag)' is not in the expected format 'v<x>.<y>.<z>' where <x>, <y>, and <z> are numbers.";
}
}
ValidateTag -tag $FromTag;
ValidateTag -tag $ToTag;
$shortLogOutput = git shortlog "$FromTag..$ToTag";
if($lastExitCode -ne 0)
{
Write-Output $shortLogOutput;
Write-Error "Failed to obtain the short log";
}
$currentAuthor = $null;
[Regex] $regex = '\(\#(?<pr>\d+)\)';
foreach ($line in $shortLogOutput) {
$match = $regex.Match($line);
if($match.Success)
{
$pullRequestNumber = $match.Groups['pr'].Value
$pullRequestInfo = gh pr view $pullRequestNumber --json author,title
$json = $pullRequestInfo | ConvertFrom-Json;
if($json.author.login -ne $currentAuthor)
{
$currentAuthor = $json.author.login;
Write-Output '';
Write-Output "@$currentAuthor";
}
Write-Output "* $($json.title) (#$pullRequestNumber)"
}
}