Skip to content

Commit 1db8ac9

Browse files
Merge pull request #67 from supervoidcoder/copilot/update-release-notes-functionality
Extract merge commit body for release notes instead of PR description
2 parents 5d89575 + 714b5fa commit 1db8ac9

1 file changed

Lines changed: 63 additions & 7 deletions

File tree

.github/workflows/release.yml

Lines changed: 63 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -75,9 +75,29 @@ jobs:
7575
}
7676
Write-Output "base_sha=$($merged.base.sha)" >> $env:GITHUB_OUTPUT
7777
Write-Output "head_sha=$($merged.head.sha)" >> $env:GITHUB_OUTPUT
78-
$body = $merged.body
79-
if ([string]::IsNullOrWhiteSpace($body)) { $body = "" }
80-
$body = $body -replace "`r?`n", " "
78+
79+
# Get the merge commit SHA and fetch its message body
80+
# This allows personalized release notes to be written in the merge commit message
81+
$mergeCommitSha = $merged.merge_commit_sha
82+
Write-Output "merge_commit_sha=$mergeCommitSha" >> $env:GITHUB_OUTPUT
83+
84+
# Fetch the merge commit details to get its message body
85+
if (-not [string]::IsNullOrWhiteSpace($mergeCommitSha)) {
86+
try {
87+
$commitData = Invoke-RestMethod -Uri "https://api.github.com/repos/$repo/commits/$mergeCommitSha" -Headers $headers -UseBasicParsing
88+
$commitMessageParts = $commitData.commit.message -split "`n", 2
89+
if ($commitMessageParts.Count -gt 1) {
90+
$body = $commitMessageParts[1].Trim()
91+
} else {
92+
$body = ""
93+
}
94+
} catch {
95+
Write-Output "Warning: Could not fetch merge commit body, using empty string"
96+
$body = ""
97+
}
98+
} else {
99+
$body = ""
100+
}
81101
Write-Output "merge_body=$body" >> $env:GITHUB_OUTPUT
82102
83103
- name: Check if source files changed
@@ -202,6 +222,8 @@ jobs:
202222
if: (github.event_name == 'workflow_dispatch' && steps.override.outputs.should_release == 'true') || (github.event_name != 'workflow_dispatch' && steps.check_files.outputs.should_release == 'true')
203223
id: parse_commit
204224
shell: pwsh
225+
env:
226+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
205227
run: |
206228
Write-Output "DEBUG: Starting parse_commit"
207229
@@ -217,11 +239,43 @@ jobs:
217239
Write-Output "DEBUG: Base SHA: $baseSha"
218240
Write-Output "DEBUG: Head SHA: $headSha"
219241
220-
# Get the merge commit (HEAD) message body for personal release notes
242+
# Get the merge commit message body for personalized release notes
243+
# This extracts the extended description from the merge commit (not the PR description)
244+
# The merge commit body allows writing custom release notes during PR merge
221245
if ("${{ github.event_name }}" -eq "workflow_dispatch") {
246+
# For manual runs, use the merge commit body from resolve_pr step
222247
$mergeCommitBody = "${{ steps.resolve_pr.outputs.merge_body }}"
223248
} else {
224-
$mergeCommitBody = git log -1 --pretty=format:"%b" HEAD
249+
# For PR events, get the merge commit SHA and fetch its body
250+
$mergeCommitSha = "${{ github.event.pull_request.merge_commit_sha }}"
251+
Write-Output "DEBUG: Merge commit SHA: $mergeCommitSha"
252+
253+
if (-not [string]::IsNullOrWhiteSpace($mergeCommitSha)) {
254+
try {
255+
$repo = "${{ github.repository }}"
256+
$headers = @{"Authorization" = "token $env:GITHUB_TOKEN"; "Accept" = "application/vnd.github.v3+json"}
257+
$commitData = Invoke-RestMethod -Uri "https://api.github.com/repos/$repo/commits/$mergeCommitSha" -Headers $headers -UseBasicParsing
258+
$commitMessage = $commitData.commit.message
259+
# Split the message to get just the body (everything after the first line)
260+
$messageParts = $commitMessage -split "`n", 2
261+
if ($messageParts.Count -gt 1) {
262+
$mergeCommitBody = $messageParts[1].Trim()
263+
} else {
264+
$mergeCommitBody = ""
265+
}
266+
} catch {
267+
Write-Output "DEBUG: Could not fetch merge commit body via API, falling back to git log"
268+
# Fallback to git log if API fails
269+
$mergeCommitBody = git log -1 --pretty=format:"%b" "$mergeCommitSha" 2>$null
270+
if ([string]::IsNullOrWhiteSpace($mergeCommitBody)) {
271+
Write-Output "DEBUG: Git log fallback returned empty result for merge commit"
272+
$mergeCommitBody = ""
273+
}
274+
}
275+
} else {
276+
Write-Output "DEBUG: No merge commit SHA available, using empty body"
277+
$mergeCommitBody = ""
278+
}
225279
}
226280
Write-Output "DEBUG: Merge commit body: $mergeCommitBody"
227281
@@ -284,10 +338,12 @@ jobs:
284338
}
285339
}
286340
287-
# Build release notes
341+
# Build release notes with BOTH merge commit body AND PR commit history
342+
# The merge commit body appears first (for personalized notes), followed by
343+
# categorized commit history from the PR
288344
$releaseNotes = ""
289345
290-
# Add merge commit body at the top if it exists
346+
# Add merge commit body at the top if it exists (personalized release notes)
291347
if (-not [string]::IsNullOrWhiteSpace($mergeCommitBody)) {
292348
$releaseNotes += "$mergeCommitBody`n`n---`n`n"
293349
}

0 commit comments

Comments
 (0)