[release/v7.5] Update Get-ChangeLog to handle backport PRs correctly#26824
Conversation
There was a problem hiding this comment.
Pull request overview
This PR backports tooling changes to Get-ChangeLog on release/v7.5 to correctly attribute changelog entries when commits come from backport PRs (where the merge author differs from the original PR author).
Changes:
- Detect backport PR commits via
[release/vX.Y]subject prefix and extract the original author from the PR body for attribution. - Add a PowerShell team GitHub-login allowlist to avoid “Thanks @…” messages for internal/team authors.
- Strip
[release/vX.Y]prefixes from changelog message subjects and avoid using$input(automatic variable) inInvoke-PRBackport.
| try{ | ||
| $response = Invoke-WebRequest -Uri $uri -Method Get -Headers $header -ErrorAction Ignore | ||
| } catch{} | ||
| ## Always disable verbose to avoid noise when we debug this function. | ||
| $response = Invoke-RestMethod ` | ||
| -Uri "https://api.github.com/repos/PowerShell/PowerShell/commits/$($commit.Hash)" ` | ||
| -Headers $header ` | ||
| -ErrorAction Stop ` | ||
| -Verbose:$false | ||
| } catch { | ||
| ## A commit could be available in ADO only. In that case, we will get status code 422 (UnprocessableEntity). | ||
| ## Otherwise, let the error bubble up. | ||
| if ($_.Exception.Response.StatusCode -ne 422) { | ||
| throw | ||
| } | ||
| } |
There was a problem hiding this comment.
$response is not cleared before the commit lookup, so if the GitHub commit API call fails (e.g., 422) $response may still contain the prior commit’s data and incorrectly set AuthorGitHubLogin. Set $response = $null before the try/catch (and/or in the 422 catch path) so stale responses can’t be reused.
| "CL-Untagged" { $clUntagged += $commit } | ||
| "CL-NotInBuild" { continue } | ||
| Default { throw "unknown tag '$cLabel' for PR: '$($commit.PullRequest)'" } | ||
| Default { throw "unknown tag '$cLabel' for PR: '$prNumber'" } |
There was a problem hiding this comment.
The default branch of this switch throws unknown tag '$cLabel' ..., but $cLabel is not defined anywhere in this scope. Use the actual label value being evaluated (e.g., $clLabel.Name) so the error message is accurate and doesn’t itself error/print an empty label.
| Default { throw "unknown tag '$cLabel' for PR: '$prNumber'" } | |
| Default { throw "unknown tag '$($clLabel.Name)' for PR: '$prNumber'" } |
| foreach ($commit in $new_commits) { | ||
| $commitSubject = $commit.Subject | ||
| $prNumber = $commit.PullRequest | ||
| Write-Verbose "subject: $commitSubject" | ||
| 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 (Get-ChangeLogMessage $commit.Subject) | ||
|
|
||
| try { | ||
| $pr = Invoke-RestMethod ` | ||
| -Uri "https://api.github.com/repos/PowerShell/PowerShell/pulls/$prNumber" ` | ||
| -Headers $header ` | ||
| -ErrorAction Stop ` | ||
| -Verbose:$false ## Always disable verbose to avoid noise when we debug this function. | ||
| } catch { | ||
| ## A commit may not have corresponding GitHub PRs. In that case, we will get status code 404 (Not Found). | ||
| ## Otherwise, let the error bubble up. | ||
| if ($_.Exception.Response.StatusCode -ne 404) { | ||
| throw | ||
| } | ||
| } |
There was a problem hiding this comment.
$pr is not reset per loop iteration, and the REST call is attempted even when $prNumber is empty. If $prNumber is empty, the .../pulls/ endpoint can return a list of PRs; and if the call fails with 404, $pr can retain the previous iteration’s value. Initialize $pr = $null each iteration, only call the PR endpoint when $prNumber is present, and explicitly set $pr = $null when handling 404.
Backport of #26610 to release/v7.5
Triggered by @daxian-dbw on behalf of @daxian-dbw
Original CL Label: CL-BuildPackaging
/cc @PowerShell/powershell-maintainers
Impact
REQUIRED: Choose either Tooling Impact or Customer Impact (or both). At least one checkbox must be selected.
Tooling Impact
Updates Get-ChangeLog to detect backport PRs and extract real author attribution
Customer Impact
Regression
REQUIRED: Check exactly one box.
This is not a regression.
Testing
Successfully tested in 7.6 release. Ensures correct attribution in changelogs for backport PRs.
Risk
REQUIRED: Check exactly one box.
Improves changelog generation to properly attribute backport PRs. Only affects release tooling. Successfully backported to 7.6 branch.