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

Merge pull request #2566 from hey-api/ci/changelog-2

ci: add custom bot

authored by

Lubos and committed by
GitHub
e87e67da 646252e4

+198 -158
-156
.changeset/__tests__/changelog.test.ts
··· 1 - import type * as getGitHubInfo from '@changesets/get-github-info'; 2 - import parse from '@changesets/parse'; 3 - import type { ModCompWithPackage, NewChangesetWithCommit, VersionType } from "@changesets/types"; 4 - import { describe, expect, it, vi } from "vitest"; 5 - 6 - import changelog from "../changelog.js"; 7 - 8 - type GetGitHubInfo = typeof getGitHubInfo; 9 - 10 - const data = { 11 - commit: 'a085003', 12 - pull: 1613, 13 - repo: 'hey-api/openapi-ts', 14 - user: 'someone', 15 - }; 16 - 17 - vi.mock("@changesets/get-github-info", (): GetGitHubInfo => ({ 18 - async getInfo({ commit, repo }) { 19 - const { pull, user } = data; 20 - const links = { 21 - commit: `[\`${commit}\`](https://github.com/${repo}/commit/${commit})`, 22 - pull: `[#${pull}](https://github.com/${repo}/pull/${pull})`, 23 - user: `[@${user}](https://github.com/${user})` 24 - }; 25 - return { 26 - links, 27 - pull, 28 - user, 29 - }; 30 - }, 31 - async getInfoFromPullRequest({ pull, repo }) { 32 - const { commit, user } = data; 33 - const links = { 34 - commit: `[\`${commit}\`](https://github.com/${repo}/commit/${commit})`, 35 - pull: `[#${pull}](https://github.com/${repo}/pull/${pull})`, 36 - user: `[@${user}](https://github.com/${user})` 37 - }; 38 - return { 39 - commit, 40 - links, 41 - user, 42 - }; 43 - }, 44 - })); 45 - 46 - const getChangeset = (content: string, commit: string | undefined): [ 47 - NewChangesetWithCommit, 48 - VersionType, 49 - null | Record<string, any>, 50 - ] => [ 51 - { 52 - ...parse( 53 - `--- 54 - pkg: "minor" 55 - --- 56 - 57 - something 58 - ${content} 59 - ` 60 - ), 61 - commit, 62 - id: 'some-id' 63 - }, 64 - 'minor', 65 - { repo: data.repo } 66 - ]; 67 - 68 - describe("changelog", () => { 69 - it("formats dependency release lines", async () => { 70 - const changesets: NewChangesetWithCommit[] = [ 71 - { 72 - commit: "abc123", 73 - id: "fake-id", 74 - releases: [], 75 - summary: "update deps", 76 - }, 77 - ]; 78 - const deps: ModCompWithPackage[] = [ 79 - { 80 - changesets: ["fake-id"], 81 - dir: "/fake/path", 82 - name: "@hey-api/openapi-ts", 83 - newVersion: "0.0.2", 84 - oldVersion: "0.0.1", 85 - packageJson: { 86 - name: "@hey-api/openapi-ts", 87 - version: "0.0.1", 88 - }, 89 - type: "patch", 90 - }, 91 - ]; 92 - 93 - const line = await changelog.getDependencyReleaseLine( 94 - changesets, 95 - deps, 96 - { repo: "org/repo" } 97 - ); 98 - 99 - expect(line).toEqual("### Updated Dependencies:\n - @hey-api/openapi-ts@0.0.2"); 100 - }); 101 - 102 - it("formats regular release lines", async () => { 103 - const changeset: NewChangesetWithCommit = { 104 - commit: "abc123", 105 - id: "fake-id", 106 - releases: [], 107 - summary: "Fixed bug in parser", 108 - }; 109 - 110 - const line = await changelog.getReleaseLine(changeset, "patch", { 111 - repo: "org/repo", 112 - }); 113 - 114 - expect(line).toContain("Fixed bug in parser"); 115 - expect(line).toContain("abc123"); 116 - }); 117 - 118 - it('with multiple authors', async () => { 119 - expect( 120 - await changelog.getReleaseLine( 121 - ...getChangeset(['author: @one', 'author: @two'].join('\n'), data.commit) 122 - ) 123 - ).toEqual(`\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)`); 124 - }); 125 - 126 - describe.each(['author', 'user'])('override author with %s keyword', (keyword) => { 127 - it.each(['with @', 'without @'])('%s', async (kind) => { 128 - expect( 129 - await changelog.getReleaseLine( 130 - ...getChangeset(`${keyword}: ${kind === 'with @' ? '@' : ''}other`, data.commit) 131 - ) 132 - ).toEqual(`\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)`); 133 - }); 134 - }); 135 - 136 - describe.each([data.commit, 'wrongcommit', undefined])('with commit from changeset of %s', (commitFromChangeset) => { 137 - describe.each(['pr', 'pull request', 'pull'])('override pr with %s keyword', (keyword) => { 138 - it.each(['with #', 'without #'])('%s', async (kind) => { 139 - expect( 140 - await changelog.getReleaseLine( 141 - ...getChangeset( 142 - `${keyword}: ${kind === 'with #' ? '#' : ''}${data.pull}`, 143 - commitFromChangeset 144 - ) 145 - ) 146 - ).toEqual(`\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)`); 147 - }); 148 - }); 149 - 150 - it('override commit with commit keyword', async () => { 151 - expect( 152 - await changelog.getReleaseLine(...getChangeset(`commit: ${data.commit}`, commitFromChangeset)) 153 - ).toEqual(`\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)`); 154 - }); 155 - }); 156 - });
+11 -2
.github/workflows/release.yml
··· 28 28 node-version: 20.x 29 29 cache: 'pnpm' 30 30 31 - - name: Install dependencies 31 + - name: Install Dependencies 32 32 run: pnpm install 33 33 34 34 - name: Build 35 35 run: pnpm build 36 36 37 + - name: Generate GitHub App Token 38 + id: app-token 39 + uses: actions/create-github-app-token@v2.1.1 40 + with: 41 + app-id: ${{ secrets.GIT_APP_CLIENT_ID }} 42 + private-key: ${{ secrets.GIT_APP_PRIVATE_KEY }} 43 + 37 44 - name: Create Release Pull Request 38 45 uses: changesets/action@v1.5.3 39 46 with: 47 + commit: '[ci] release' 40 48 publish: pnpm changeset publish 49 + title: '[ci] release' 41 50 version: pnpm changeset version 42 51 env: 43 - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} 52 + GITHUB_TOKEN: ${{ steps.app-token.outputs.token }} 44 53 NPM_CONFIG_PROVENANCE: true 45 54 NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
+187
__tests__/changelog.test.ts
··· 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/openapi-ts@0.0.2', 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 + });