|
1 | 1 | /** |
2 | 2 | * Custom Changesets changelog formatter |
3 | | - * Generates clean, professional changelog entries without technical noise |
| 3 | + * Generates clean, professional changelog entries with PR links |
4 | 4 | */ |
5 | 5 |
|
6 | | -const getReleaseLine = async (changeset, _type) => { |
| 6 | +const getReleaseLine = async (changeset, _type, options) => { |
7 | 7 | const [firstLine, ...futureLines] = changeset.summary.split('\n').map(l => l.trimEnd()); |
8 | 8 |
|
9 | | - // Clean up the first line - remove conventional commit prefix if present |
| 9 | + // Extract PR number if present (format: "PR: #123") |
| 10 | + const prMatch = changeset.summary.match(/PR:\s*#(\d+)/); |
| 11 | + const prNumber = prMatch ? prMatch[1] : null; |
| 12 | + |
| 13 | + // Clean up the first line - remove conventional commit prefix and PR reference |
10 | 14 | let cleanFirstLine = firstLine |
11 | 15 | .replace( |
12 | 16 | /^(feat|fix|docs|style|refactor|perf|test|chore|build|ci|break|breaking)(\(.+?\))?:\s*/i, |
13 | 17 | '' |
14 | 18 | ) |
| 19 | + .replace(/PR:\s*#\d+/g, '') |
15 | 20 | .trim(); |
16 | 21 |
|
17 | 22 | // Capitalize first letter |
18 | 23 | cleanFirstLine = cleanFirstLine.charAt(0).toUpperCase() + cleanFirstLine.slice(1); |
19 | 24 |
|
| 25 | + // Build the changelog entry |
20 | 26 | let returnVal = `- ${cleanFirstLine}`; |
21 | 27 |
|
22 | | - if (futureLines.length > 0) { |
23 | | - returnVal += `\n${futureLines.map(l => ` ${l}`).join('\n')}`; |
| 28 | + // Add PR link if available |
| 29 | + if (prNumber && options?.repo) { |
| 30 | + returnVal += ` ([#${prNumber}](https://github.com/${options.repo}/pull/${prNumber}))`; |
| 31 | + } |
| 32 | + |
| 33 | + // Add additional lines if present (excluding PR reference line) |
| 34 | + const additionalLines = futureLines.filter(line => !line.match(/PR:\s*#\d+/)); |
| 35 | + if (additionalLines.length > 0) { |
| 36 | + returnVal += `\n${additionalLines.map(l => ` ${l}`).join('\n')}`; |
24 | 37 | } |
25 | 38 |
|
26 | 39 | return returnVal; |
|
0 commit comments