Skip to content

Commit 496a3f5

Browse files
rjmholtRobert Holt
authored andcommitted
Add thanks
1 parent 7e24b5b commit 496a3f5

File tree

2 files changed

+175
-13
lines changed

2 files changed

+175
-13
lines changed

tools/ChangelogTools.psm1

Lines changed: 167 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,167 @@
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+
}

tools/GitHubTools.psm1

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ class GitHubCommitInfo : GitCommitInfo
1717
{
1818
[string]$Organization
1919
[string]$Repository
20+
[pscustomobject]$GitHubCommitData
2021
}
2122

2223
class GitHubIssueInfo
@@ -60,17 +61,6 @@ class GitHubPR : GitHubIssue
6061
}
6162
}
6263

63-
class ChangelogItem
64-
{
65-
[GitHubCommitInfo]$Commit
66-
[GitHubPR]$PR
67-
[GitHubIssue[]]$ClosedIssues
68-
[string[]]$Labels
69-
[int]$IssueNumber = -1
70-
[int]$PRNumber = -1
71-
[string]$BodyText
72-
}
73-
7464
$script:CloseKeywords = @(
7565
'close'
7666
'closes'
@@ -368,6 +358,8 @@ function Get-GitCommit
368358
}
369359

370360
$originDetails = GetHumanishRepositoryDetails -RemoteUrl (Exec { git remote get-url $Remote })
361+
$organization = $originDetails.Organization
362+
$repository = $originDetails.Repository
371363

372364
$format = '%H||%P||%aN||%aE||%s'
373365
$commits = Exec { git --no-pager log "$SinceRef..$UntilRef" --format=$format }
@@ -383,10 +375,13 @@ function Get-GitCommit
383375
ContributorEmail = $email
384376
Subject = $subject
385377
Body = $body
386-
Organization = $originDetails.Organization
387-
Repository = $originDetails.Repository
378+
Organization = $organization
379+
Repository = $repository
388380
}
389381

382+
# Query the GitHub API for more commit information
383+
$commitVal.GitHubCommitData = Invoke-RestMethod -Method Get -Uri "https://api.github.com/repos/$organization/$repository/commits/$hash"
384+
390385
# Look for something like 'This is a commit message (#1224)'
391386
$pr = [regex]::Match($subject, '\(#(\d+)\)$').Groups[1].Value
392387
if ($pr)

0 commit comments

Comments
 (0)