Skip to content

Commit 62cea49

Browse files
committed
Format release notes with github script
The previous function was throwing errors in some cases when the gh cli expected a local .git directory. Instead we should avoid an interactive CLI for steps like this. Change-type: patch Signed-off-by: Kyle Harding <[email protected]>
1 parent c160582 commit 62cea49

File tree

2 files changed

+149
-2
lines changed

2 files changed

+149
-2
lines changed

.github/workflows/flowzone.yml

Lines changed: 73 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

flowzone.yml

Lines changed: 76 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1420,7 +1420,7 @@ jobs:
14201420
14211421
# Get Renovate release notes from PR body, massage a little and draft a comment.
14221422
- name: Format release notes
1423-
id: format_release_notes
1423+
id: format_release_notes_old
14241424
continue-on-error: true
14251425
env:
14261426
# We need pull_requests: read to get the PR title and body but that permission
@@ -1496,6 +1496,81 @@ jobs:
14961496
fi
14971497
fi
14981498
1499+
# Get Renovate release notes from PR body, massage a little and draft a comment.
1500+
- name: Format release notes
1501+
id: format_release_notes
1502+
continue-on-error: true
1503+
uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # v7.0.1
1504+
with:
1505+
github-token: ${{ steps.gh_app_token.outputs.token || secrets.FLOWZONE_TOKEN }}
1506+
result-encoding: string
1507+
script: |
1508+
const { data: pr } = await github.rest.pulls.get({
1509+
owner: context.repo.owner,
1510+
repo: context.repo.repo,
1511+
pull_number: context.issue.number
1512+
});
1513+
1514+
if (!pr.title) {
1515+
return;
1516+
}
1517+
1518+
let releaseNotes = '';
1519+
let releaseNotesComment = '';
1520+
1521+
// Check if PR is from Renovate
1522+
const isRenovate = pr.user.type === 'Bot' && pr.user.login.includes('renovate');
1523+
const hasReleaseNotes = pr.body.includes('### Release Notes');
1524+
1525+
if (isRenovate && hasReleaseNotes) {
1526+
// Extract release notes section
1527+
const releaseNotesMatch = pr.body.match(/### Release Notes\n([\s\S]*?)---/);
1528+
if (releaseNotesMatch) {
1529+
const prBody = releaseNotesMatch[1].trim();
1530+
1531+
// Extract notable changes
1532+
const notableChanges = prBody
1533+
.split('\n')
1534+
.filter(line => line.match(/^> -|^-|^<summary>/))
1535+
.map(line => line.replace(/^<summary>(.*)<\/summary>/, '-$1'))
1536+
.filter((line, index, self) => self.indexOf(line) === index)
1537+
.slice(1);
1538+
1539+
// Format release notes
1540+
const releaseNotesChanges = notableChanges
1541+
.map(line => line.replace(/^> -(.*)/, ' -$1'))
1542+
.join('\n');
1543+
1544+
releaseNotes = `## ${pr.title}\n\n### Notable changes\n\n${releaseNotesChanges}\n\n${prBody}`;
1545+
core.setOutput('body', releaseNotes);
1546+
1547+
// Format comment
1548+
const notableChangesFormatted = notableChanges
1549+
.map(line => `* ${line.replace(/^> -|^-/, '')}`)
1550+
.join('\n');
1551+
1552+
releaseNotesComment = `#release-notes ${pr.title}\n\nNotable changes\n* [only keep the important and rephrase, leaving this in place will avoid posting release notes]\n${notableChangesFormatted}\n\n${prBody}`;
1553+
core.setOutput('comment', releaseNotesComment);
1554+
1555+
return releaseNotes;
1556+
}
1557+
}
1558+
1559+
// Handle non-Renovate cases
1560+
if (pr.body.match(/## Release Notes/i)) {
1561+
1562+
const releaseNotesMatch = pr.body.match(/## Release Notes\n([\s\S]*?)(?=## |$)/i);
1563+
if (releaseNotesMatch) {
1564+
const releaseNotesBody = releaseNotesMatch[1].trim();
1565+
1566+
releaseNotes = `## ${pr.title}\n${releaseNotesBody}`;
1567+
core.setOutput('body', releaseNotes);
1568+
1569+
return releaseNotes;
1570+
}
1571+
}
1572+
1573+
14991574
# https://octokit.github.io/rest.js/v21/#repos-list-tags
15001575
# https://docs.github.com/en/rest/git/refs
15011576
# https://octokit.github.io/rest.js/v21/#repos-compare-commits-with-basehead

0 commit comments

Comments
 (0)