Skip to content

Commit bf5331f

Browse files
authored
Merge pull request #2728 from hey-api/chore/changeset-fix-5
chore: fix changelog
2 parents 2a192e4 + e8e8842 commit bf5331f

File tree

2 files changed

+18
-26
lines changed

2 files changed

+18
-26
lines changed

.changeset/changelog.js

Lines changed: 2 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -103,26 +103,10 @@ export default {
103103
const [firstLine, ...rest] = replacedChangelog.split('\n');
104104
const restSummary = rest.join('\n').trim();
105105

106-
// Post-process code blocks: replace triple backtick code blocks with indented code blocks
107-
function convertCodeBlocks(text) {
108-
// Replace ```lang\n...\n``` with indented code
109-
return text.replace(/```(\w*)\n([\s\S]*?)```/g, (match, lang, code) => {
110-
const langComment = lang ? `// ${lang}\n` : '';
111-
return (
112-
'\n' +
113-
langComment +
114-
code
115-
.split('\n')
116-
.map((line) => ' ' + line)
117-
.join('\n') +
118-
'\n'
119-
);
120-
});
121-
}
122-
106+
// No code block conversion: preserve original triple backtick code blocks and indentation
123107
let releaseLine = `\n- ${firstLine}${metadata}`;
124108
if (restSummary) {
125-
releaseLine += '\n\n' + convertCodeBlocks(restSummary);
109+
releaseLine += '\n\n' + restSummary;
126110
}
127111
return releaseLine;
128112
},

__tests__/changelog.test.ts

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ describe('changelog', () => {
134134
);
135135
});
136136

137-
it('places metadata on the first line and does not append it after code blocks', async () => {
137+
it('places metadata on the first line and preserves markdown code blocks', async () => {
138138
const summary = [
139139
'refactor(config): replace `off` with null to disable options',
140140
'',
@@ -167,12 +167,21 @@ describe('changelog', () => {
167167
expect(line).toMatch(
168168
/^\n- refactor\(config\): replace `off` with null to disable options \(\[#1613\]\(https:\/\/github.com\/hey-api\/openapi-ts\/pull\/1613\)\) \(\[`fcdd73b`\]\(https:\/\/github.com\/hey-api\/openapi-ts\/commit\/fcdd73b816d74babf47e6a1f46032f5b8ebb4b48\)\) by \[@someone\]\(https:\/\/github.com\/someone\)/,
169169
);
170-
// There should be no metadata at the end
171-
expect(line.trim().endsWith('```')).toBe(false);
172170
// Should not contain quadruple backticks
173171
expect(line).not.toContain('````');
174-
// Should contain indented code block
175-
expect(line).toContain(' export default {');
172+
// Should contain a markdown code block
173+
expect(line).toContain('```js\nexport default {');
174+
expect(line).toContain(
175+
' input: "hey-api/backend", // sign up at app.heyapi.dev',
176+
);
177+
expect(line).toContain(' output: {');
178+
expect(line).toContain(' format: null,');
179+
expect(line).toContain(' lint: null,');
180+
expect(line).toContain(' path: "src/client",');
181+
expect(line).toContain(' tsConfigPath: null,');
182+
expect(line).toContain(' },');
183+
expect(line).toContain('};');
184+
expect(line).toContain('```');
176185
});
177186

178187
it('converts multiple code blocks and preserves non-code content', async () => {
@@ -198,10 +207,9 @@ describe('changelog', () => {
198207
const line = await changelog.getReleaseLine(changeset, 'minor', {
199208
repo: 'hey-api/openapi-ts',
200209
});
201-
expect(line).toContain(' console.log(1);');
202-
expect(line).toContain(' console.log(2);');
210+
expect(line).toContain('```js\nconsole.log(1);\n```');
211+
expect(line).toContain('```ts\nconsole.log(2);\n```');
203212
expect(line).toContain('Some text.');
204-
expect(line).not.toContain('```');
205213
});
206214

207215
describe.each(['author', 'user'])(

0 commit comments

Comments
 (0)