Skip to content

Commit a87e5dc

Browse files
authored
Merge pull request #6 from link-foundation/issue-5-00a06dc29d4a
Fix release formatting to support Major/Minor/Patch changes
2 parents eb42a0e + 461bf30 commit a87e5dc

File tree

3 files changed

+173
-19
lines changed

3 files changed

+173
-19
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'gh-download-pull-request': patch
3+
---
4+
5+
Fix GitHub release formatting to remove incorrect section headers for major/minor/patch versions and properly link related pull requests

experiments/test-regex-pattern.mjs

Lines changed: 143 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,143 @@
1+
#!/usr/bin/env node
2+
3+
/**
4+
* Test script to verify the regex pattern handles all changeset types
5+
*/
6+
7+
// Test cases for different changeset formats
8+
const testCases = [
9+
{
10+
name: 'Patch Changes with commit hash',
11+
body: `### Patch Changes
12+
13+
- abc1234: Fix bug in authentication module`,
14+
expected: {
15+
changeType: 'Patch',
16+
commitHash: 'abc1234',
17+
description: 'Fix bug in authentication module',
18+
},
19+
},
20+
{
21+
name: 'Minor Changes with commit hash',
22+
body: `### Minor Changes
23+
24+
- 2bcef5f: Add support for google/gemini-3-pro model alias
25+
- Added 'google/gemini-3-pro' as an alias to 'gemini-3-pro-preview'
26+
- Updated README.md with Google Gemini usage examples`,
27+
expected: {
28+
changeType: 'Minor',
29+
commitHash: '2bcef5f',
30+
description: `Add support for google/gemini-3-pro model alias
31+
- Added 'google/gemini-3-pro' as an alias to 'gemini-3-pro-preview'
32+
- Updated README.md with Google Gemini usage examples`,
33+
},
34+
},
35+
{
36+
name: 'Major Changes with commit hash',
37+
body: `### Major Changes
38+
39+
- def5678: Breaking API changes for v2.0`,
40+
expected: {
41+
changeType: 'Major',
42+
commitHash: 'def5678',
43+
description: 'Breaking API changes for v2.0',
44+
},
45+
},
46+
{
47+
name: 'Patch Changes without commit hash',
48+
body: `### Patch Changes
49+
50+
- Small typo fix in documentation`,
51+
expected: {
52+
changeType: 'Patch',
53+
commitHash: null,
54+
description: 'Small typo fix in documentation',
55+
},
56+
},
57+
{
58+
name: 'Minor Changes without commit hash',
59+
body: `### Minor Changes
60+
61+
- Added new feature for user preferences`,
62+
expected: {
63+
changeType: 'Minor',
64+
commitHash: null,
65+
description: 'Added new feature for user preferences',
66+
},
67+
},
68+
];
69+
70+
// The updated regex pattern from the fix
71+
const changesPattern =
72+
/### (Major|Minor|Patch) Changes\s*\n\s*-\s+(?:([a-f0-9]+):\s+)?(.+?)$/s;
73+
74+
console.log('🧪 Testing regex pattern for changeset detection\n');
75+
76+
let passedTests = 0;
77+
let failedTests = 0;
78+
79+
for (const testCase of testCases) {
80+
console.log(`Testing: ${testCase.name}`);
81+
82+
const changesMatch = testCase.body.match(changesPattern);
83+
84+
if (!changesMatch) {
85+
console.log(` ❌ FAILED: Pattern did not match`);
86+
failedTests++;
87+
continue;
88+
}
89+
90+
const [, changeType, commitHash, rawDescription] = changesMatch;
91+
92+
// Handle case where commit hash might be in the description
93+
let finalCommitHash = commitHash;
94+
let finalDescription = rawDescription;
95+
96+
if (!finalCommitHash && rawDescription) {
97+
const descWithHashMatch = rawDescription.match(/^([a-f0-9]+):\s+(.+)$/s);
98+
if (descWithHashMatch) {
99+
[, finalCommitHash, finalDescription] = descWithHashMatch;
100+
}
101+
}
102+
103+
// Verify results
104+
const errors = [];
105+
106+
if (changeType !== testCase.expected.changeType) {
107+
errors.push(
108+
`changeType: expected "${testCase.expected.changeType}", got "${changeType}"`
109+
);
110+
}
111+
112+
// Compare commit hash (handle null vs undefined)
113+
const expectedHash = testCase.expected.commitHash;
114+
if ((finalCommitHash || null) !== (expectedHash || null)) {
115+
errors.push(
116+
`commitHash: expected "${expectedHash}", got "${finalCommitHash}"`
117+
);
118+
}
119+
120+
if (finalDescription !== testCase.expected.description) {
121+
errors.push(
122+
`description: expected "${testCase.expected.description}", got "${finalDescription}"`
123+
);
124+
}
125+
126+
if (errors.length > 0) {
127+
console.log(` ❌ FAILED:`);
128+
errors.forEach((error) => console.log(` - ${error}`));
129+
failedTests++;
130+
} else {
131+
console.log(` ✅ PASSED`);
132+
passedTests++;
133+
}
134+
135+
console.log();
136+
}
137+
138+
console.log('━'.repeat(60));
139+
console.log(`Results: ${passedTests} passed, ${failedTests} failed`);
140+
141+
if (failedTests > 0) {
142+
process.exit(1);
143+
}

scripts/format-release-notes.mjs

Lines changed: 25 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
*/
2525

2626
// TODO: Update this to match your package name in package.json
27-
const PACKAGE_NAME = 'my-package';
27+
const PACKAGE_NAME = 'gh-download-pull-request';
2828

2929
// Load use-m dynamically
3030
const { use } = eval(
@@ -89,28 +89,34 @@ try {
8989
process.exit(0);
9090
}
9191

92-
// Extract the patch changes section
93-
// This regex handles two formats:
94-
// 1. With commit hash: "- abc1234: Description"
95-
// 2. Without commit hash: "- Description"
96-
const patchChangesMatchWithHash = currentBody.match(
97-
/### Patch Changes\s*\n\s*-\s+([a-f0-9]+):\s+(.+?)$/s
98-
);
99-
const patchChangesMatchNoHash = currentBody.match(
100-
/### Patch Changes\s*\n\s*-\s+(.+?)$/s
101-
);
92+
// Extract changes section (Major, Minor, or Patch)
93+
// This regex handles multiple formats:
94+
// 1. With commit hash: "### [Major|Minor|Patch] Changes\n- abc1234: Description"
95+
// 2. Without commit hash: "### [Major|Minor|Patch] Changes\n- Description"
96+
const changesPattern =
97+
/### (Major|Minor|Patch) Changes\s*\n\s*-\s+(?:([a-f0-9]+):\s+)?(.+?)$/s;
98+
const changesMatch = currentBody.match(changesPattern);
10299

103100
let commitHash = null;
104101
let rawDescription = null;
105-
106-
if (patchChangesMatchWithHash) {
107-
// Format: - abc1234: Description
108-
[, commitHash, rawDescription] = patchChangesMatchWithHash;
109-
} else if (patchChangesMatchNoHash) {
110-
// Format: - Description (no commit hash)
111-
[, rawDescription] = patchChangesMatchNoHash;
102+
let changeType = null;
103+
104+
if (changesMatch) {
105+
// Extract: [full match, changeType, commitHash (optional), description]
106+
[, changeType, commitHash, rawDescription] = changesMatch;
107+
console.log(`ℹ️ Found ${changeType} Changes section`);
108+
109+
// If commitHash is undefined and description contains it, try to extract
110+
if (!commitHash && rawDescription) {
111+
// This handles the case where description itself might be null/undefined
112+
// and we need to safely check for commit hash at the start
113+
const descWithHashMatch = rawDescription.match(/^([a-f0-9]+):\s+(.+)$/s);
114+
if (descWithHashMatch) {
115+
[, commitHash, rawDescription] = descWithHashMatch;
116+
}
117+
}
112118
} else {
113-
console.log('⚠️ Could not parse patch changes from release notes');
119+
console.log('⚠️ Could not parse changes from release notes');
114120
process.exit(0);
115121
}
116122

0 commit comments

Comments
 (0)