Skip to content

Commit f7e5be7

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 f7e5be7

File tree

2 files changed

+151
-2
lines changed

2 files changed

+151
-2
lines changed

.github/workflows/flowzone.yml

Lines changed: 74 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: 77 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,82 @@ 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+
console.log('pr:', JSON.stringify(pr, null, 2));
1515+
1516+
if (!pr.title) {
1517+
return;
1518+
}
1519+
1520+
// Check if PR is from Renovate
1521+
const isRenovate = pr.user.type === 'Bot' && pr.user.login.includes('renovate');
1522+
const hasReleaseNotes = pr.body.includes('### Release Notes');
1523+
1524+
if (isRenovate && hasReleaseNotes) {
1525+
// Extract release notes section
1526+
const releaseNotesMatch = pr.body.match(/### Release Notes\n([\s\S]*?)---/);
1527+
if (releaseNotesMatch) {
1528+
const prBody = releaseNotesMatch[1].trim();
1529+
1530+
// Extract notable changes
1531+
const notableChanges = prBody
1532+
.split('\n')
1533+
.filter(line => line.match(/^> -|^-|^<summary>/))
1534+
.map(line => line.replace(/^<summary>(.*)<\/summary>/, '-$1'))
1535+
.filter((line, index, self) => self.indexOf(line) === index)
1536+
.slice(1);
1537+
1538+
// Format release notes
1539+
const releaseNotesChanges = notableChanges
1540+
.map(line => line.replace(/^> -(.*)/, ' -$1'))
1541+
.join('\n');
1542+
1543+
const releaseNotes = `## ${pr.title}\n\n### Notable changes\n\n${releaseNotesChanges}\n\n${prBody}`;
1544+
core.setOutput('body', releaseNotes);
1545+
1546+
// Format comment
1547+
const notableChangesFormatted = notableChanges
1548+
.map(line => `* ${line.replace(/^> -|^-/, '')}`)
1549+
.join('\n');
1550+
1551+
const 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}`;
1552+
core.setOutput('comment', releaseNotesComment);
1553+
1554+
return releaseNotes;
1555+
}
1556+
}
1557+
1558+
// Handle custom release notes
1559+
const custom_release_notes_regex = /## Release Notes\n([\s\S]*?)(?=## |$)/i;
1560+
const customReleaseNotesMatch = pr.body.match(custom_release_notes_regex);
1561+
1562+
console.log('match:', customReleaseNotesMatch);
1563+
1564+
if (customReleaseNotesMatch[1]) {
1565+
1566+
const releaseNotesBody = customReleaseNotesMatch[1].trim();
1567+
1568+
const releaseNotes = `## ${pr.title}\n${releaseNotesBody}`;
1569+
core.setOutput('body', releaseNotes);
1570+
1571+
return releaseNotes;
1572+
}
1573+
1574+
14991575
# https://octokit.github.io/rest.js/v21/#repos-list-tags
15001576
# https://docs.github.com/en/rest/git/refs
15011577
# https://octokit.github.io/rest.js/v21/#repos-compare-commits-with-basehead

0 commit comments

Comments
 (0)