fork of hey-api/openapi-ts because I need some additional things
1import { getInfo, getInfoFromPullRequest } from '@changesets/get-github-info';
2import { config } from 'dotenv';
3
4config();
5
6/**
7 * @returns {string}
8 */
9function getRepo() {
10 return 'hey-api/openapi-ts';
11}
12
13/** @type {import("@changesets/types").ChangelogFunctions} */
14export default {
15 getDependencyReleaseLine: async (_, dependenciesUpdated) => {
16 if (!dependenciesUpdated.length) {
17 return '';
18 }
19
20 const list = dependenciesUpdated.map(
21 (dependency) => ` - ${dependency.name}@${dependency.newVersion}`,
22 );
23
24 return ['### Updated Dependencies:', ...list].join('\n');
25 },
26 getReleaseLine: async (changeset) => {
27 const repo = getRepo();
28
29 /** @type number | undefined */
30 let prFromSummary;
31 /** @type string | undefined */
32 let commitFromSummary;
33 /** @type string[] */
34 const usersFromSummary = [];
35
36 // Remove PR, commit, author/user lines from summary
37 const replacedChangelog = changeset.summary
38 .replace(/^\s*(?:pr|pull|pull\s+request):\s*#?(\d+)/im, (_, pr) => {
39 const num = Number(pr);
40 if (!Number.isNaN(num)) {
41 prFromSummary = num;
42 }
43 return '';
44 })
45 .replace(/^\s*commit:\s*([^\s]+)/im, (_, commit) => {
46 commitFromSummary = commit;
47 return '';
48 })
49 .replace(/^\s*(?:author|user):\s*@?([^\s]+)/gim, (_, user) => {
50 usersFromSummary.push(user);
51 return '';
52 })
53 .trim();
54
55 const links = await (async () => {
56 if (prFromSummary !== undefined) {
57 let { links } = await getInfoFromPullRequest({
58 pull: prFromSummary,
59 repo,
60 });
61 if (commitFromSummary) {
62 const shortCommitId = commitFromSummary.slice(0, 7);
63 links = {
64 ...links,
65 commit: `[\`${shortCommitId}\`](https://github.com/${repo}/commit/${commitFromSummary})`,
66 };
67 }
68 return links;
69 }
70 const commitToFetchFrom = commitFromSummary || changeset.commit;
71 if (commitToFetchFrom) {
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 };
78 return links;
79 }
80 return {
81 commit: null,
82 pull: null,
83 user: null,
84 };
85 })();
86
87 const users = usersFromSummary.length
88 ? usersFromSummary
89 .map(
90 (userFromSummary) =>
91 `[@${userFromSummary}](https://github.com/${userFromSummary})`,
92 )
93 .join(', ')
94 : links.user;
95
96 const metadata = [
97 links.pull === null ? '' : ` (${links.pull})`,
98 links.commit === null ? '' : ` (${links.commit})`,
99 users === null ? '' : ` by ${users}`,
100 ].join('');
101
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 // No code block conversion: preserve original triple backtick code blocks and indentation
107 let releaseLine = `\n- ${firstLine}${metadata}`;
108 if (restSummary) {
109 releaseLine += '\n\n' + restSummary;
110 }
111 return releaseLine;
112 },
113};