fork of hey-api/openapi-ts because I need some additional things
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

Merge pull request #2727 from hey-api/chore/changeset-fix-4

chore: fix changelog

authored by

Lubos and committed by
GitHub
2a192e4a 596c3e8c

+105 -4
+33 -2
.changeset/changelog.js
··· 33 33 /** @type string[] */ 34 34 const usersFromSummary = []; 35 35 36 + // Remove PR, commit, author/user lines from summary 36 37 const replacedChangelog = changeset.summary 37 38 .replace(/^\s*(?:pr|pull|pull\s+request):\s*#?(\d+)/im, (_, pr) => { 38 39 const num = Number(pr); ··· 68 69 } 69 70 const commitToFetchFrom = commitFromSummary || changeset.commit; 70 71 if (commitToFetchFrom) { 71 - const { links } = await getInfo({ commit: commitToFetchFrom, repo }); 72 + let { links } = await getInfo({ commit: commitToFetchFrom, repo }); 73 + const shortCommitId = commitToFetchFrom.slice(0, 7); 74 + links = { 75 + ...links, 76 + commit: `[\`${shortCommitId}\`](https://github.com/${repo}/commit/${commitToFetchFrom})`, 77 + }; 72 78 return links; 73 79 } 74 80 return { ··· 93 99 users === null ? '' : ` by ${users}`, 94 100 ].join(''); 95 101 96 - return `\n- ${replacedChangelog}${metadata}`; 102 + // Split summary into first line and the rest 103 + const [firstLine, ...rest] = replacedChangelog.split('\n'); 104 + const restSummary = rest.join('\n').trim(); 105 + 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 + 123 + let releaseLine = `\n- ${firstLine}${metadata}`; 124 + if (restSummary) { 125 + releaseLine += '\n\n' + convertCodeBlocks(restSummary); 126 + } 127 + return releaseLine; 97 128 }, 98 129 };
+70
__tests__/changelog.test.ts
··· 134 134 ); 135 135 }); 136 136 137 + it('places metadata on the first line and does not append it after code blocks', async () => { 138 + const summary = [ 139 + 'refactor(config): replace `off` with null to disable options', 140 + '', 141 + '### Updated `output` options', 142 + '', 143 + 'We made the `output` configuration more consistent by using `null` to represent disabled options. [This change](https://heyapi.dev/openapi-ts/migrating#updated-output-options) does not affect boolean options.', 144 + '', 145 + '```js', 146 + 'export default {', 147 + ' input: "hey-api/backend", // sign up at app.heyapi.dev', 148 + ' output: {', 149 + ' format: null,', 150 + ' lint: null,', 151 + ' path: "src/client",', 152 + ' tsConfigPath: null,', 153 + ' },', 154 + '};', 155 + '```', 156 + ].join('\n'); 157 + const changeset = { 158 + commit: 'fcdd73b816d74babf47e6a1f46032f5b8ebb4b48', 159 + id: 'fake-id', 160 + releases: [], 161 + summary, 162 + }; 163 + const line = await changelog.getReleaseLine(changeset, 'minor', { 164 + repo: 'hey-api/openapi-ts', 165 + }); 166 + // Metadata should be on the first line 167 + expect(line).toMatch( 168 + /^\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\)/, 169 + ); 170 + // There should be no metadata at the end 171 + expect(line.trim().endsWith('```')).toBe(false); 172 + // Should not contain quadruple backticks 173 + expect(line).not.toContain('````'); 174 + // Should contain indented code block 175 + expect(line).toContain(' export default {'); 176 + }); 177 + 178 + it('converts multiple code blocks and preserves non-code content', async () => { 179 + const summary = [ 180 + 'feat: add foo', 181 + '', 182 + '```js', 183 + 'console.log(1);', 184 + '```', 185 + '', 186 + 'Some text.', 187 + '', 188 + '```ts', 189 + 'console.log(2);', 190 + '```', 191 + ].join('\n'); 192 + const changeset = { 193 + commit: 'abc123', 194 + id: 'fake-id', 195 + releases: [], 196 + summary, 197 + }; 198 + const line = await changelog.getReleaseLine(changeset, 'minor', { 199 + repo: 'hey-api/openapi-ts', 200 + }); 201 + expect(line).toContain(' console.log(1);'); 202 + expect(line).toContain(' console.log(2);'); 203 + expect(line).toContain('Some text.'); 204 + expect(line).not.toContain('```'); 205 + }); 206 + 137 207 describe.each(['author', 'user'])( 138 208 'override author with %s keyword', 139 209 (keyword) => {
+2 -2
package.json
··· 27 27 "lint:fix": "prettier --check --write . && eslint . --fix", 28 28 "lint": "prettier --check . && eslint .", 29 29 "prepare": "husky", 30 - "test:changelog": "vitest run .changeset", 31 - "test:changelog:watch": "vitest watch .changeset", 30 + "test:changelog": "vitest run __tests__/*.test.ts", 31 + "test:changelog:watch": "vitest watch __tests__/*.test.ts", 32 32 "test:coverage": "turbo run test:coverage", 33 33 "test:update": "turbo run test:update", 34 34 "test:watch": "turbo run test:watch",