1
+ # Copyright (c) Microsoft Corporation. All rights reserved.
2
+ # Licensed under the MIT License.
3
+
4
+ using module ./ GitHubTools.psm1
5
+
6
+ $script :NoThanks = @ (
7
+ ' rjmholt'
8
+ ' TylerLeonhardt'
9
+ ' daxian-dbw'
10
+ ' SteveL-MSFT'
11
+ ' PaulHigin'
12
+ )
13
+
14
+ class ChangelogItem
15
+ {
16
+ [GitHubCommitInfo ]$Commit
17
+ [GitHubPR ]$PR
18
+ [GitHubIssue []]$ClosedIssues
19
+ [int ]$IssueNumber = -1
20
+ [int ]$PRNumber = -1
21
+ [string ]$ContributingUser
22
+ }
23
+
24
+ filter Get-ChangelogItemFromCommit
25
+ {
26
+ param (
27
+ [Parameter (Mandatory , ValueFromPipeline , Position = 0 )]
28
+ [GitHubCommitInfo []]
29
+ $Commit ,
30
+
31
+ [Parameter (Mandatory )]
32
+ [string ]
33
+ $GitHubToken ,
34
+
35
+ [Parameter ()]
36
+ [hashtable ]
37
+ $KnownUserEmails
38
+ )
39
+
40
+ foreach ($singleCommit in $Commit )
41
+ {
42
+ $changelogItem = [ChangelogItem ]@ {
43
+ Commit = $singleCommit
44
+ BodyText = $singleCommit.Body
45
+ ChangeLabels = $singleCommit.CommitLabels
46
+ ContributingUser = $singleCommit.GitHubCommitData.author.login
47
+ }
48
+
49
+ if ($Commit.PRNumber -ge 0 )
50
+ {
51
+ $getPrParams = @ {
52
+ Organization = $singleCommit.Organization
53
+ Repository = $singleCommit.Repository
54
+ PullNumber = $singleCommit.PRNumber
55
+ GitHubToken = $GitHubToken
56
+ }
57
+ $pr = Get-GitHubPR @getPrParams
58
+
59
+ $changelogItem.PR = $pr
60
+ $changelogItem.PRNumber = $pr.Number
61
+
62
+ $closedIssueInfos = $pr.GetClosedIssueInfos ()
63
+ if ($closedIssueInfos )
64
+ {
65
+ $changelogItem.ClosedIssues = $closedIssueInfos | Get-GitHubIssue
66
+ $changelogItem.IssueNumber = $closedIssueInfos [0 ].Number
67
+ $changelogItem.Labels += ($closedIssueInfos | ForEach-Object { $_.Labels })
68
+ }
69
+ }
70
+
71
+ $changelogItem
72
+ }
73
+ }
74
+
75
+ function New-ChangelogSection
76
+ {
77
+ param (
78
+ [Parameter (Mandatory )]
79
+ [string ]
80
+ $ReleaseName ,
81
+
82
+ [Parameter (Mandatory )]
83
+ [string ]
84
+ $RepositoryUrl ,
85
+
86
+ [Parameter (ValueFromPipeline )]
87
+ [ChangelogItem []]
88
+ $ChangelogItem ,
89
+
90
+ [Parameter ()]
91
+ [string ]
92
+ $DateFormat = ' dddd, dd MMMM yyyy' ,
93
+
94
+ [Parameter ()]
95
+ [datetime ]
96
+ $Date = ([datetime ]::Now)
97
+ )
98
+
99
+ begin
100
+ {
101
+ $repoDetails = GetHumanishRepositoryDetails - RemoteUrl $RepositoryUrl
102
+ $repository = $repoDetails.Repository
103
+ $organization = $repoDetails.Organization
104
+
105
+ $clBuilder = [System.Text.StringBuilder ]::new()
106
+ $null = $clBuilder.Append (" ##$ReleaseName `n " )
107
+ $null = $clBuilder.Append (" ###$ ( $Date.ToString ($DateFormat )) `n " )
108
+ $null = $clBuilder.Append (" ####[$repository ]($RepositoryUrl )`n`n " )
109
+ }
110
+
111
+ process
112
+ {
113
+ foreach ($clItem in $ChangelogItem )
114
+ {
115
+ if ($clItem.Labels -contains ' ignore' )
116
+ {
117
+ continue
118
+ }
119
+
120
+ if (-not $clItem.BodyText )
121
+ {
122
+ continue
123
+ }
124
+
125
+ if ($clItem.IssueNumber -gt 0 )
126
+ {
127
+ $issueNumber = $clItem.IssueNumber
128
+ }
129
+ elseif ($clItem.PRNumber -gt 0 )
130
+ {
131
+ $issueNumber = $clItem.PRNumber
132
+ }
133
+
134
+ if ($issueNumber )
135
+ {
136
+ $itemHeader = " $repository #$issueNumber "
137
+ }
138
+ else
139
+ {
140
+ $itemHeader = " $repository "
141
+ }
142
+
143
+ $itemLink = " https://github.com/$organization /$repository "
144
+ if ($clItem.PRNumber -ge 0 )
145
+ {
146
+ $prNum = $clItem.PRNumber
147
+ $itemLink += " /pull/$prNum "
148
+ }
149
+
150
+ $indentedBody = ($clItem.BodyText.Split (" `n " ) | Where-Object { $_ } | ForEach-Object { " $_ " }) -join " `n "
151
+
152
+ if ($script :NoThanks -notcontains $clItem.ContributingUser )
153
+ {
154
+ $thanks = " (thanks @$ ( $clItem.ContributingUser ) !)"
155
+ }
156
+
157
+ $itemText = " - [$itemHeader ]($itemLink ) -`n $indentedBody$thanks `n "
158
+
159
+ $null = $clBuilder.Append ($itemText )
160
+ }
161
+ }
162
+
163
+ end
164
+ {
165
+ return $clBuilder.Append (" `n " ).ToString()
166
+ }
167
+ }
0 commit comments