Skip to content

Commit 27c0521

Browse files
authored
Merge branch 'main' into fix/#2553-handle-plain-text-request-body
2 parents b1a3658 + a312623 commit 27c0521

File tree

91 files changed

+1944
-3483
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

91 files changed

+1944
-3483
lines changed

.changeset/changelog.js

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
import { getInfo, getInfoFromPullRequest } from '@changesets/get-github-info';
2+
import { config } from 'dotenv';
3+
4+
config();
5+
6+
/**
7+
* @returns {string}
8+
*/
9+
function getRepo() {
10+
return 'hey-api/openapi-ts';
11+
}
12+
13+
/** @type {import("@changesets/types").ChangelogFunctions} */
14+
export 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+
const replacedChangelog = changeset.summary
37+
.replace(/^\s*(?:pr|pull|pull\s+request):\s*#?(\d+)/im, (_, pr) => {
38+
const num = Number(pr);
39+
if (!Number.isNaN(num)) {
40+
prFromSummary = num;
41+
}
42+
return '';
43+
})
44+
.replace(/^\s*commit:\s*([^\s]+)/im, (_, commit) => {
45+
commitFromSummary = commit;
46+
return '';
47+
})
48+
.replace(/^\s*(?:author|user):\s*@?([^\s]+)/gim, (_, user) => {
49+
usersFromSummary.push(user);
50+
return '';
51+
})
52+
.trim();
53+
54+
const links = await (async () => {
55+
if (prFromSummary !== undefined) {
56+
let { links } = await getInfoFromPullRequest({
57+
pull: prFromSummary,
58+
repo,
59+
});
60+
if (commitFromSummary) {
61+
const shortCommitId = commitFromSummary.slice(0, 7);
62+
links = {
63+
...links,
64+
commit: `[\`${shortCommitId}\`](https://github.com/${repo}/commit/${commitFromSummary})`,
65+
};
66+
}
67+
return links;
68+
}
69+
const commitToFetchFrom = commitFromSummary || changeset.commit;
70+
if (commitToFetchFrom) {
71+
const { links } = await getInfo({ commit: commitToFetchFrom, repo });
72+
return links;
73+
}
74+
return {
75+
commit: null,
76+
pull: null,
77+
user: null,
78+
};
79+
})();
80+
81+
const users = usersFromSummary.length
82+
? usersFromSummary
83+
.map(
84+
(userFromSummary) =>
85+
`[@${userFromSummary}](https://github.com/${userFromSummary})`,
86+
)
87+
.join(', ')
88+
: links.user;
89+
90+
const metadata = [
91+
links.pull === null ? '' : ` (${links.pull})`,
92+
links.commit === null ? '' : ` (${links.commit})`,
93+
users === null ? '' : ` by ${users}`,
94+
].join('');
95+
96+
return `\n- ${replacedChangelog}${metadata}`;
97+
},
98+
};

.changeset/config.json

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,8 @@
11
{
2-
"$schema": "https://unpkg.com/@changesets/config@2.3.1/schema.json",
2+
"$schema": "https://unpkg.com/@changesets/config@3.1.1/schema.json",
33
"access": "public",
44
"baseBranch": "main",
5-
"changelog": [
6-
"@changesets/changelog-github",
7-
{
8-
"repo": "hey-api/openapi-ts"
9-
}
10-
],
5+
"changelog": "./changelog.js",
116
"commit": false,
127
"fixed": [],
138
"ignore": [],

.changeset/silly-apricots-exist.md

Lines changed: 0 additions & 5 deletions
This file was deleted.

.github/workflows/ci.yml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,6 @@ jobs:
5050
- name: Run unit tests
5151
run: pnpm test
5252

53-
- name: Run e2e tests
54-
run: pnpm test:e2e
55-
5653
- name: Publish preview packages
5754
if: github.event_name == 'pull_request' && matrix.node-version == '22.12.0' && matrix.os == 'ubuntu-latest'
5855
run: ./scripts/publish-preview-packages.sh

.github/workflows/release.yml

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,18 +28,27 @@ jobs:
2828
node-version: 20.x
2929
cache: 'pnpm'
3030

31-
- name: Install dependencies
31+
- name: Install Dependencies
3232
run: pnpm install
3333

3434
- name: Build
3535
run: pnpm build
3636

37+
- name: Generate GitHub App Token
38+
id: app-token
39+
uses: actions/[email protected]
40+
with:
41+
app-id: ${{ secrets.GIT_APP_CLIENT_ID }}
42+
private-key: ${{ secrets.GIT_APP_PRIVATE_KEY }}
43+
3744
- name: Create Release Pull Request
3845
uses: changesets/[email protected]
3946
with:
47+
commit: 'ci: release'
4048
publish: pnpm changeset publish
49+
title: 'ci: release'
4150
version: pnpm changeset version
4251
env:
43-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
52+
GITHUB_TOKEN: ${{ steps.app-token.outputs.token }}
4453
NPM_CONFIG_PROVENANCE: true
4554
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}

.gitignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ coverage
2121

2222
# test files
2323
test/generated
24-
test/e2e/generated
2524

2625
# debug files
2726
openapi-ts-debug-*

.prettierignore

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
**/.changeset
1+
**/.changeset/*.md
22
**/node_modules
33
**/templates
44
**/dist
@@ -8,7 +8,6 @@
88
**/.svelte-kit
99
**/.vitepress/cache
1010
**/.vitepress/dist
11-
**/test/e2e
1211
**/test/generated
1312
**/__snapshots__
1413

__tests__/changelog.test.ts

Lines changed: 187 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,187 @@
1+
import type * as getGitHubInfo from '@changesets/get-github-info';
2+
import parse from '@changesets/parse';
3+
import type {
4+
ModCompWithPackage,
5+
NewChangesetWithCommit,
6+
VersionType,
7+
} from '@changesets/types';
8+
import { describe, expect, it, vi } from 'vitest';
9+
10+
import changelog from '../.changeset/changelog.js';
11+
12+
type GetGitHubInfo = typeof getGitHubInfo;
13+
14+
const data = {
15+
commit: 'a085003',
16+
pull: 1613,
17+
repo: 'hey-api/openapi-ts',
18+
user: 'someone',
19+
};
20+
21+
vi.mock(
22+
'@changesets/get-github-info',
23+
(): GetGitHubInfo => ({
24+
async getInfo({ commit, repo }) {
25+
const { pull, user } = data;
26+
const links = {
27+
commit: `[\`${commit}\`](https://github.com/${repo}/commit/${commit})`,
28+
pull: `[#${pull}](https://github.com/${repo}/pull/${pull})`,
29+
user: `[@${user}](https://github.com/${user})`,
30+
};
31+
return {
32+
links,
33+
pull,
34+
user,
35+
};
36+
},
37+
async getInfoFromPullRequest({ pull, repo }) {
38+
const { commit, user } = data;
39+
const links = {
40+
commit: `[\`${commit}\`](https://github.com/${repo}/commit/${commit})`,
41+
pull: `[#${pull}](https://github.com/${repo}/pull/${pull})`,
42+
user: `[@${user}](https://github.com/${user})`,
43+
};
44+
return {
45+
commit,
46+
links,
47+
user,
48+
};
49+
},
50+
}),
51+
);
52+
53+
const getChangeset = (
54+
content: string,
55+
commit: string | undefined,
56+
): [NewChangesetWithCommit, VersionType, null | Record<string, any>] => [
57+
{
58+
...parse(
59+
`---
60+
pkg: "minor"
61+
---
62+
63+
something
64+
${content}
65+
`,
66+
),
67+
commit,
68+
id: 'some-id',
69+
},
70+
'minor',
71+
{ repo: data.repo },
72+
];
73+
74+
describe('changelog', () => {
75+
it('formats dependency release lines', async () => {
76+
const changesets: NewChangesetWithCommit[] = [
77+
{
78+
commit: 'abc123',
79+
id: 'fake-id',
80+
releases: [],
81+
summary: 'update deps',
82+
},
83+
];
84+
const deps: ModCompWithPackage[] = [
85+
{
86+
changesets: ['fake-id'],
87+
dir: '/fake/path',
88+
name: '@hey-api/openapi-ts',
89+
newVersion: '0.0.2',
90+
oldVersion: '0.0.1',
91+
packageJson: {
92+
name: '@hey-api/openapi-ts',
93+
version: '0.0.1',
94+
},
95+
type: 'patch',
96+
},
97+
];
98+
99+
const line = await changelog.getDependencyReleaseLine(changesets, deps, {
100+
repo: 'org/repo',
101+
});
102+
103+
expect(line).toEqual(
104+
'### Updated Dependencies:\n - @hey-api/[email protected]',
105+
);
106+
});
107+
108+
it('formats regular release lines', async () => {
109+
const changeset: NewChangesetWithCommit = {
110+
commit: 'abc123',
111+
id: 'fake-id',
112+
releases: [],
113+
summary: 'Fixed bug in parser',
114+
};
115+
116+
const line = await changelog.getReleaseLine(changeset, 'patch', {
117+
repo: 'org/repo',
118+
});
119+
120+
expect(line).toContain('Fixed bug in parser');
121+
expect(line).toContain('abc123');
122+
});
123+
124+
it('with multiple authors', async () => {
125+
expect(
126+
await changelog.getReleaseLine(
127+
...getChangeset(
128+
['author: @one', 'author: @two'].join('\n'),
129+
data.commit,
130+
),
131+
),
132+
).toEqual(
133+
`\n- something ([#1613](https://github.com/hey-api/openapi-ts/pull/1613)) ([\`a085003\`](https://github.com/hey-api/openapi-ts/commit/a085003)) by [@one](https://github.com/one), [@two](https://github.com/two)`,
134+
);
135+
});
136+
137+
describe.each(['author', 'user'])(
138+
'override author with %s keyword',
139+
(keyword) => {
140+
it.each(['with @', 'without @'])('%s', async (kind) => {
141+
expect(
142+
await changelog.getReleaseLine(
143+
...getChangeset(
144+
`${keyword}: ${kind === 'with @' ? '@' : ''}other`,
145+
data.commit,
146+
),
147+
),
148+
).toEqual(
149+
`\n- something ([#1613](https://github.com/hey-api/openapi-ts/pull/1613)) ([\`a085003\`](https://github.com/hey-api/openapi-ts/commit/a085003)) by [@other](https://github.com/other)`,
150+
);
151+
});
152+
},
153+
);
154+
155+
describe.each([data.commit, 'wrongcommit', undefined])(
156+
'with commit from changeset of %s',
157+
(commitFromChangeset) => {
158+
describe.each(['pr', 'pull request', 'pull'])(
159+
'override pr with %s keyword',
160+
(keyword) => {
161+
it.each(['with #', 'without #'])('%s', async (kind) => {
162+
expect(
163+
await changelog.getReleaseLine(
164+
...getChangeset(
165+
`${keyword}: ${kind === 'with #' ? '#' : ''}${data.pull}`,
166+
commitFromChangeset,
167+
),
168+
),
169+
).toEqual(
170+
`\n- something ([#1613](https://github.com/hey-api/openapi-ts/pull/1613)) ([\`a085003\`](https://github.com/hey-api/openapi-ts/commit/a085003)) by [@someone](https://github.com/someone)`,
171+
);
172+
});
173+
},
174+
);
175+
176+
it('override commit with commit keyword', async () => {
177+
expect(
178+
await changelog.getReleaseLine(
179+
...getChangeset(`commit: ${data.commit}`, commitFromChangeset),
180+
),
181+
).toEqual(
182+
`\n- something ([#1613](https://github.com/hey-api/openapi-ts/pull/1613)) ([\`a085003\`](https://github.com/hey-api/openapi-ts/commit/a085003)) by [@someone](https://github.com/someone)`,
183+
);
184+
});
185+
},
186+
);
187+
});

docs/openapi-ts/get-started.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,11 +89,11 @@ The above script can be executed by running `npm run openapi-ts` or equivalent c
8989

9090
### Node.js
9191

92-
You can also generate output programmatically by importing `@hey-api/openapi-ts` in a JavaScript/TypeScript file.
92+
You can also generate output programmatically by calling `createClient()` in a JavaScript/TypeScript file.
9393

9494
::: code-group
9595

96-
```ts [openapi-ts.ts]
96+
```ts [script.ts]
9797
import { createClient } from '@hey-api/openapi-ts';
9898

9999
createClient({

docs/partials/contributors-list.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
- [Bogdan ](https://github.com/BogdanMaier)
1212
- [Brian Tarricone](https://github.com/kelnos)
1313
- [Carl Kittelberger](https://github.com/icedream)
14+
- [Changwan](https://github.com/WooWan)
1415
- [Chris Wiggins](https://github.com/chriswiggins)
1516
- [Daniel Roe](https://github.com/danielroe)
1617
- [Daschi](https://github.com/Daschi1)

0 commit comments

Comments
 (0)