From 1078caff2b400a07ae1119749f432a6312107c75 Mon Sep 17 00:00:00 2001 From: Travis Plunk Date: Wed, 10 Jul 2019 14:53:02 -0700 Subject: [PATCH] Update change log generation tool to deal with private commits (#10096) --- tools/releaseTools.psm1 | 54 +++++++++++++++++++++++++++++++++++------ 1 file changed, 46 insertions(+), 8 deletions(-) diff --git a/tools/releaseTools.psm1 b/tools/releaseTools.psm1 index d4afc17424..1e7f68710e 100644 --- a/tools/releaseTools.psm1 +++ b/tools/releaseTools.psm1 @@ -33,6 +33,9 @@ class CommitNode { # We have their names in this array so that we don't need to query GitHub to find out if they are powershell team members. $Script:powershell_team = @( "Robert Holt" + "Travis Plunk" + "dependabot-preview[bot]" + "Joey Aiello" ) # They are very active contributors, so we keep their email-login mappings here to save a few queries to Github. @@ -150,7 +153,10 @@ function Get-ChangeLog # Find the merge commit that merged the release branch to master. $child_merge_commit = Get-ChildMergeCommit -CommitHash $tag_hash - $commit_hash, $parent_hashes = $child_merge_commit.Split("||") + if($child_merge_commit) + { + $commit_hash, $parent_hashes = $child_merge_commit.Split("||") + } # Find the other parent of the merge commit, which represents the original head of master right before merging. $other_parent_hash = ($parent_hashes -replace $tag_hash).Trim() @@ -169,7 +175,11 @@ function Get-ChangeLog # Find the commits that were only in the release branch, excluding those that were cherry-picked from master branch. $new_commits_from_last_release = git --no-pager log --first-parent --cherry-pick --left-only "$tag_hash...$other_parent_hash" --format=$format | New-CommitNode # Find the commits that are actually duplicate but having different patch-ids due to resolving conflicts during the cherry-pick. - $duplicate_commits = Compare-Object $new_commits_from_last_release $new_commits_from_other_parent -Property PullRequest -ExcludeDifferent -IncludeEqual -PassThru + $duplicate_commits = $null + if($new_commits_from_last_release -and $new_commits_from_other_parent) + { + $duplicate_commits = Compare-Object $new_commits_from_last_release $new_commits_from_other_parent -Property PullRequest -ExcludeDifferent -IncludeEqual -PassThru + } if ($duplicate_commits) { $duplicate_pr_numbers = @($duplicate_commits | ForEach-Object -MemberName PullRequest) $new_commits_from_other_parent = $new_commits_from_other_parent | Where-Object PullRequest -NotIn $duplicate_pr_numbers @@ -234,14 +244,17 @@ function Get-ChangeLog $clExperimental = @() foreach ($commit in $new_commits) { + Write-Verbose "authorname: $($commit.AuthorName)" if ($commit.AuthorEmail.EndsWith("@microsoft.com") -or $powershell_team -contains $commit.AuthorName -or $Script:attribution_ignore_list -contains $commit.AuthorEmail) { - $commit.ChangeLogMessage = "- {0}" -f $commit.Subject + $commit.ChangeLogMessage = "- {0}" -f (Get-ChangeLogMessage $commit.Subject) } else { if ($community_login_map.ContainsKey($commit.AuthorEmail)) { $commit.AuthorGitHubLogin = $community_login_map[$commit.AuthorEmail] } else { $uri = "https://api.github.com/repos/PowerShell/PowerShell/commits/$($commit.Hash)" - $response = Invoke-WebRequest -Uri $uri -Method Get -Headers $header -ErrorAction SilentlyContinue + try{ + $response = Invoke-WebRequest -Uri $uri -Method Get -Headers $header -ErrorAction Ignore + } catch{} if($response) { $content = ConvertFrom-Json -InputObject $response.Content @@ -249,7 +262,7 @@ function Get-ChangeLog $community_login_map[$commit.AuthorEmail] = $commit.AuthorGitHubLogin } } - $commit.ChangeLogMessage = "- {0} (Thanks @{1}!)" -f $commit.Subject, $commit.AuthorGitHubLogin + $commit.ChangeLogMessage = ("- {0} (Thanks @{1}!)" -f (Get-ChangeLogMessage $commit.Subject), $commit.AuthorGitHubLogin) } if ($commit.IsBreakingChange) { @@ -262,12 +275,19 @@ function Get-ChangeLog } catch { if ($_.Exception.Response.StatusCode -eq '404') { - Write-Warning -Message "Ignoring commit $($commit.Hash) by $($commit.AuthorName), as it does not have a PR." - continue + $pr = $null + #continue } } - $clLabel = $pr.labels | Where-Object { $_.Name -match "^CL-"} + if($pr) + { + $clLabel = $pr.labels | Where-Object { $_.Name -match "^CL-"} + } + else { + Write-Warning -Message "Tagging $($commit.Hash) by $($commit.AuthorName), as CL-BuildPackaging as it does not have a PR." + $clLabel = [PSCustomObject]@{Name ='CL-BuildPackaging'} + } if ($clLabel.count -gt 1 -and $clLabel.Name -notcontains 'CL-BreakingChange') { $multipleLabelsPRs += $pr @@ -329,6 +349,24 @@ function PrintChangeLog($clSection, $sectionTitle) { } } +function Get-ChangeLogMessage +{ + param($OriginalMessage) + + switch -regEx ($OriginalMessage) + { + '^Merged PR (\d*): ' { + return $OriginalMessage.replace($Matches.0,'') + " (Internal $($Matches.1))" + } + '^Build\(deps\): ' { + return $OriginalMessage.replace($Matches.0,'') + } + default { + return $OriginalMessage + } + } +} + ############################## #.SYNOPSIS #Gets packages which have newer packages in nuget.org