这是indexloc提供的服务,不要输入任何密码
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 2 additions & 18 deletions .changeset/changelog.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,26 +103,10 @@ export default {
const [firstLine, ...rest] = replacedChangelog.split('\n');
const restSummary = rest.join('\n').trim();

// Post-process code blocks: replace triple backtick code blocks with indented code blocks
function convertCodeBlocks(text) {
// Replace ```lang\n...\n``` with indented code
return text.replace(/```(\w*)\n([\s\S]*?)```/g, (match, lang, code) => {
const langComment = lang ? `// ${lang}\n` : '';
return (
'\n' +
langComment +
code
.split('\n')
.map((line) => ' ' + line)
.join('\n') +
'\n'
);
});
}

// No code block conversion: preserve original triple backtick code blocks and indentation
let releaseLine = `\n- ${firstLine}${metadata}`;
if (restSummary) {
releaseLine += '\n\n' + convertCodeBlocks(restSummary);
releaseLine += '\n\n' + restSummary;
}
return releaseLine;
},
Expand Down
24 changes: 16 additions & 8 deletions __tests__/changelog.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ describe('changelog', () => {
);
});

it('places metadata on the first line and does not append it after code blocks', async () => {
it('places metadata on the first line and preserves markdown code blocks', async () => {
const summary = [
'refactor(config): replace `off` with null to disable options',
'',
Expand Down Expand Up @@ -167,12 +167,21 @@ describe('changelog', () => {
expect(line).toMatch(
/^\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\)/,
);
// There should be no metadata at the end
expect(line.trim().endsWith('```')).toBe(false);
// Should not contain quadruple backticks
expect(line).not.toContain('````');
// Should contain indented code block
expect(line).toContain(' export default {');
// Should contain a markdown code block
expect(line).toContain('```js\nexport default {');
expect(line).toContain(
' input: "hey-api/backend", // sign up at app.heyapi.dev',
);
expect(line).toContain(' output: {');
expect(line).toContain(' format: null,');
expect(line).toContain(' lint: null,');
expect(line).toContain(' path: "src/client",');
expect(line).toContain(' tsConfigPath: null,');
expect(line).toContain(' },');
expect(line).toContain('};');
expect(line).toContain('```');
});

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

describe.each(['author', 'user'])(
Expand Down
Loading