diff --git a/.changeset/warm-dragons-collect.md b/.changeset/warm-dragons-collect.md new file mode 100644 index 0000000..f938075 --- /dev/null +++ b/.changeset/warm-dragons-collect.md @@ -0,0 +1,5 @@ +--- +'@mheob/changeset-changelog': minor +--- + +Rework the output and use also the commit information diff --git a/package.json b/package.json index 13fc929..78664b9 100644 --- a/package.json +++ b/package.json @@ -16,10 +16,6 @@ "license": "MIT", "author": "Alexander Böhm ", "main": "dist/index.js", - "types": "dist/index.d.ts", - "files": [ - "dist" - ], "scripts": { "build": "tsup", "changeset": "changeset", @@ -45,7 +41,8 @@ }, "dependencies": { "@changesets/get-github-info": "^0.5.1", - "@changesets/types": "^5.2.0" + "@changesets/types": "^5.2.0", + "dotenv": "^16.0.3" }, "devDependencies": { "@changesets/cli": "^2.25.0", @@ -56,7 +53,7 @@ "@mheob/prettier-config": "^2.0.2", "@mheob/tsconfig": "^1.0.1", "@types/node": "^18.11.0", - "@vitest/coverage-c8": "^0.24.3", + "@vitest/coverage-istanbul": "^0.24.3", "husky": "^8.0.1", "lint-staged": "^13.0.3", "ts-node": "^10.9.1", @@ -69,7 +66,6 @@ "clean": true, "entry": [ "src/index.ts" - ], - "dts": true + ] } } diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 3693063..061bc3d 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -11,7 +11,8 @@ specifiers: '@mheob/prettier-config': ^2.0.2 '@mheob/tsconfig': ^1.0.1 '@types/node': ^18.11.0 - '@vitest/coverage-c8': ^0.24.3 + '@vitest/coverage-istanbul': ^0.24.3 + dotenv: ^16.0.3 husky: ^8.0.1 lint-staged: ^13.0.3 ts-node: ^10.9.1 @@ -23,6 +24,7 @@ specifiers: dependencies: '@changesets/get-github-info': 0.5.1 '@changesets/types': 5.2.0 + dotenv: 16.0.3 devDependencies: '@changesets/cli': 2.25.0 @@ -33,7 +35,7 @@ devDependencies: '@mheob/prettier-config': 2.0.2_prettier@2.7.1 '@mheob/tsconfig': 1.0.1 '@types/node': 18.11.0 - '@vitest/coverage-c8': 0.24.3 + '@vitest/coverage-istanbul': 0.24.3 husky: 8.0.1 lint-staged: 13.0.3 ts-node: 10.9.1_o6ib7qqltxpe7qrskddglns2ga @@ -70,14 +72,14 @@ packages: dependencies: '@ampproject/remapping': 2.2.0 '@babel/code-frame': 7.18.6 - '@babel/generator': 7.17.7 + '@babel/generator': 7.19.5 '@babel/helper-compilation-targets': 7.19.3_@babel+core@7.17.8 '@babel/helper-module-transforms': 7.19.0 '@babel/helpers': 7.19.4 - '@babel/parser': 7.18.9 + '@babel/parser': 7.19.4 '@babel/template': 7.18.10 - '@babel/traverse': 7.17.3 - '@babel/types': 7.17.0 + '@babel/traverse': 7.19.4 + '@babel/types': 7.19.4 convert-source-map: 1.9.0 debug: 4.3.4 gensync: 1.0.0-beta.2 @@ -91,7 +93,7 @@ packages: resolution: {integrity: sha512-oLcVCTeIFadUoArDTwpluncplrYBmTCCZZgXCbgNGvOBBiSDDK3eWO4b/+eOTli5tKv1lg+a5/NAXg+nTcei1w==} engines: {node: '>=6.9.0'} dependencies: - '@babel/types': 7.17.0 + '@babel/types': 7.19.4 jsesc: 2.5.2 source-map: 0.5.7 dev: true @@ -215,7 +217,7 @@ packages: engines: {node: '>=6.0.0'} hasBin: true dependencies: - '@babel/types': 7.17.0 + '@babel/types': 7.19.4 dev: true /@babel/parser/7.19.4: @@ -260,8 +262,8 @@ packages: '@babel/helper-function-name': 7.19.0 '@babel/helper-hoist-variables': 7.18.6 '@babel/helper-split-export-declaration': 7.18.6 - '@babel/parser': 7.18.9 - '@babel/types': 7.17.0 + '@babel/parser': 7.19.4 + '@babel/types': 7.19.4 debug: 4.3.4 globals: 11.12.0 transitivePeerDependencies: @@ -303,10 +305,6 @@ packages: to-fast-properties: 2.0.0 dev: true - /@bcoe/v8-coverage/0.2.3: - resolution: {integrity: sha512-0hYQ8SB4Db5zvZB4axdMHGwEaQjkZzFjQiN9LVYvIFB2nSUHW9tYpxWriPrWDASIxiaXax83REcLxuSdnGPZtw==} - dev: true - /@changesets/apply-release-plan/6.1.1: resolution: {integrity: sha512-LaQiP/Wf0zMVR0HNrLQAjz3rsNsr0d/RlnP6Ef4oi8VafOwnY1EoWdK4kssuUJGgNgDyHpomS50dm8CU3D7k7g==} dependencies: @@ -908,10 +906,6 @@ packages: ci-info: 3.5.0 dev: true - /@types/istanbul-lib-coverage/2.0.4: - resolution: {integrity: sha512-z/QT1XN4K4KYuslS23k62yDIDLwLFkzxOuMplDtObz0+y7VqJCaO2o+SPwHCvLFZh7xazvvoor2tA/hPz9ee7g==} - dev: true - /@types/json-schema/7.0.11: resolution: {integrity: sha512-wOuvG1SN4Us4rez+tylwwwCV1psiNVOkJeM3AUWUNWg/jDQY2+HE/444y5gc+jBmRqASOm2Oeh5c1axHobwRKQ==} dev: true @@ -1080,10 +1074,15 @@ packages: eslint-visitor-keys: 3.3.0 dev: true - /@vitest/coverage-c8/0.24.3: - resolution: {integrity: sha512-tAmMyHxWYnAwGeJb7QgTuEX8aLasTg4X1/6INobXa/7wYGEJ28CACFO5iLn1HzFVPoLvhsS3luQjiflGjjSMRQ==} + /@vitest/coverage-istanbul/0.24.3: + resolution: {integrity: sha512-cPQ5icP/TPih3qeZ29qA2zg1lxAM+wAUuh1ZkQJ75OK7am/8isqhP5QCCeGCLdFOakDsm4Ik8vHHfcDffuxW9Q==} dependencies: - c8: 7.12.0 + istanbul-lib-coverage: 3.2.0 + istanbul-lib-instrument: 5.2.1 + istanbul-lib-report: 3.0.0 + istanbul-lib-source-maps: 4.0.1 + istanbul-reports: 3.1.5 + test-exclude: 6.0.0 vitest: 0.24.3 transitivePeerDependencies: - '@edge-runtime/vm' @@ -1355,25 +1354,6 @@ packages: load-tsconfig: 0.2.3 dev: true - /c8/7.12.0: - resolution: {integrity: sha512-CtgQrHOkyxr5koX1wEUmN/5cfDa2ckbHRA4Gy5LAL0zaCFtVWJS5++n+w4/sr2GWGerBxgTjpKeDclk/Qk6W/A==} - engines: {node: '>=10.12.0'} - hasBin: true - dependencies: - '@bcoe/v8-coverage': 0.2.3 - '@istanbuljs/schema': 0.1.3 - find-up: 5.0.0 - foreground-child: 2.0.0 - istanbul-lib-coverage: 3.2.0 - istanbul-lib-report: 3.0.0 - istanbul-reports: 3.1.5 - rimraf: 3.0.2 - test-exclude: 6.0.0 - v8-to-istanbul: 9.0.1 - yargs: 16.2.0 - yargs-parser: 20.2.9 - dev: true - /cac/6.7.14: resolution: {integrity: sha512-b6Ilus+c3RrdDk+JhLKUAQfzzgLEPy6wcXqS7f/xe1EETvsDP6GORG7SFuOs6cID5YkqchW/LXZbX5bc8j7ZcQ==} engines: {node: '>=8'} @@ -1509,14 +1489,6 @@ packages: wrap-ansi: 6.2.0 dev: true - /cliui/7.0.4: - resolution: {integrity: sha512-OcRE68cOsVMXp1Yvonl/fzkQOyjLSu/8bhPDfQt0e0/Eb283TKP20Fs2MqoPsr9SwA595rRCA+QMzYc9nBP+JQ==} - dependencies: - string-width: 4.2.3 - strip-ansi: 6.0.1 - wrap-ansi: 7.0.0 - dev: true - /cliui/8.0.1: resolution: {integrity: sha512-BSeNnyus75C4//NQ9gQt1/csTXyo/8Sb+afLAkzAptFuMsod9HFokGNudZpi/oQV73hnVK+sR+5PVRMd+Dr7YQ==} engines: {node: '>=12'} @@ -1808,6 +1780,11 @@ packages: is-obj: 2.0.0 dev: true + /dotenv/16.0.3: + resolution: {integrity: sha512-7GO6HghkA5fYG9TYnNxi14/7K9f5occMlp3zXAuSxn7CKCxt9xbNWG7yF8hTCSUchlfWSe3uLmlPfigevRItzQ==} + engines: {node: '>=12'} + dev: false + /eastasianwidth/0.2.0: resolution: {integrity: sha512-I88TYZWc9XiYHRQ4/3c5rjjfgkjhLyW2luGIheGERbNQ6OY7yTybanSpDXZa8y7VUP9YmDcYa+eyq4ca7iLqWA==} dev: true @@ -2574,14 +2551,6 @@ packages: resolution: {integrity: sha512-5nqDSxl8nn5BSNxyR3n4I6eDmbolI6WT+QqR547RwxQapgjQBmtktdP+HTBb/a/zLsbzERTONyUB5pefh5TtjQ==} dev: true - /foreground-child/2.0.0: - resolution: {integrity: sha512-dCIq9FpEcyQyXKCkyzmlPTFNgrCzPudOe+mhvJU5zAtlBnGVy2yKxtfsxK2tQBThwq225jcvBjpw1Gr40uzZCA==} - engines: {node: '>=8.0.0'} - dependencies: - cross-spawn: 7.0.3 - signal-exit: 3.0.7 - dev: true - /fs-extra/10.1.0: resolution: {integrity: sha512-oRXApq54ETRj4eMiFzGnHWGy+zo5raudjuxN0b8H7s/RU2oW0Wvsx9O0ACRN/kRq9E8Vu/ReskGB5o3ji+FzHQ==} engines: {node: '>=12'} @@ -3083,6 +3052,19 @@ packages: engines: {node: '>=8'} dev: true + /istanbul-lib-instrument/5.2.1: + resolution: {integrity: sha512-pzqtp31nLv/XFOzXGuvhCb8qhjmTVo5vjVk19XE4CRlSWz0KoeJ3bw9XsA7nOp9YBf4qHjwBxkDzKcME/J29Yg==} + engines: {node: '>=8'} + dependencies: + '@babel/core': 7.17.8 + '@babel/parser': 7.19.4 + '@istanbuljs/schema': 0.1.3 + istanbul-lib-coverage: 3.2.0 + semver: 6.3.0 + transitivePeerDependencies: + - supports-color + dev: true + /istanbul-lib-report/3.0.0: resolution: {integrity: sha512-wcdi+uAKzfiGT2abPpKZ0hSU1rGQjUQnLvtY5MpQ7QCTahD3VODhcu4wcfY1YtkGaDD5yuydOLINXsfbus9ROw==} engines: {node: '>=8'} @@ -3092,6 +3074,17 @@ packages: supports-color: 7.2.0 dev: true + /istanbul-lib-source-maps/4.0.1: + resolution: {integrity: sha512-n3s8EwkdFIJCG3BPKBYvskgXGoy88ARzvegkitk60NxRdwltLOTaH7CUiMRXvwYorl0Q712iEjcWB+fK/MrWVw==} + engines: {node: '>=10'} + dependencies: + debug: 4.3.4 + istanbul-lib-coverage: 3.2.0 + source-map: 0.6.1 + transitivePeerDependencies: + - supports-color + dev: true + /istanbul-reports/3.1.5: resolution: {integrity: sha512-nUsEMa9pBt/NOHqbcbeJEgqIlY/K7rVWUX6Lql2orY5e9roQOthbR3vtY4zzf2orPELg80fnxxk9zUyPlgwD1w==} engines: {node: '>=8'} @@ -4206,6 +4199,11 @@ packages: engines: {node: '>=0.10.0'} dev: true + /source-map/0.6.1: + resolution: {integrity: sha512-UjgapumWlbMhkBgzT7Ykc5YXUT46F0iKu8SGXq0bcwP5dz/h0Plj6enJqjz1Zbq2l5WaqYnrVbwWOWMyF3F47g==} + engines: {node: '>=0.10.0'} + dev: true + /source-map/0.8.0-beta.0: resolution: {integrity: sha512-2ymg6oRBpebeZi9UUNsgQ89bhx01TcTkmNTGnNO88imTmbSgy4nfujrgVEFKWpMTEGA11EDkTt7mqObTPdigIA==} engines: {node: '>= 8'} @@ -4729,15 +4727,6 @@ packages: resolution: {integrity: sha512-wa7YjyUGfNZngI/vtK0UHAN+lgDCxBPCylVXGp0zu59Fz5aiGtNXaq3DhIov063MorB+VfufLh3JlF2KdTK3xg==} dev: true - /v8-to-istanbul/9.0.1: - resolution: {integrity: sha512-74Y4LqY74kLE6IFyIjPtkSTWzUZmj8tdHT9Ii/26dvQ6K9Dl2NbEfj0XgU2sHCtKgt5VupqhlO/5aWuqS+IY1w==} - engines: {node: '>=10.12.0'} - dependencies: - '@jridgewell/trace-mapping': 0.3.17 - '@types/istanbul-lib-coverage': 2.0.4 - convert-source-map: 1.9.0 - dev: true - /validate-npm-package-license/3.0.4: resolution: {integrity: sha512-DpKm2Ui/xN7/HQKCtpZxoRWBhZ9Z0kqtygG8XCgNQ8ZlDnxuQmWhj566j8fN4Cu3/JmbhsDo7fcAJq4s9h27Ew==} dependencies: @@ -4968,19 +4957,6 @@ packages: yargs-parser: 18.1.3 dev: true - /yargs/16.2.0: - resolution: {integrity: sha512-D1mvvtDG0L5ft/jGWkLpG1+m0eQxOfaBvTNELraWj22wSVUMWxZUvYgJYcKh6jGGIkJFhH4IZPQhR4TKpc8mBw==} - engines: {node: '>=10'} - dependencies: - cliui: 7.0.4 - escalade: 3.1.1 - get-caller-file: 2.0.5 - require-directory: 2.1.1 - string-width: 4.2.3 - y18n: 5.0.8 - yargs-parser: 20.2.9 - dev: true - /yargs/17.6.0: resolution: {integrity: sha512-8H/wTDqlSwoSnScvV2N/JHfLWOKuh5MVla9hqLjK3nsfyy6Y4kDSYSvkU5YCUEPOSnRXfIyx3Sq+B/IWudTo4g==} engines: {node: '>=12'} diff --git a/src/index.test.ts b/src/index.test.ts index ae6d29f..8f1e546 100644 --- a/src/index.test.ts +++ b/src/index.test.ts @@ -58,28 +58,6 @@ const getChangeset = (content: string, commit?: string): NewChangesetWithCommit }; }; -describe('getReplacedChangelog', () => { - it('should throw an error if options.repo is missing', async () => { - const changeset = getChangeset('An awesome feature.', data.commit); - const result = getReleaseLine(changeset, 'minor', {}); - await expect(result).rejects.toThrowError(errorMessage); - }); - - it('should return the changelog in a string format', async () => { - const changeset = getChangeset('An awesome feature.\npr: #2\nauthor: @mheob', data.commit); - const result = await getReleaseLine(changeset, 'minor', { repo: data.repo }); - expect(result).toBe( - '\n- An awesome feature. ([[#2](https://github.com/mheob/changeset-changelog/pull/2)] - Thanks [@mheob](https://github.com/mheob)!)\n', - ); - }); - - it('should return the changelog in a string format but without meta data', async () => { - const changeset = getChangeset('An awesome feature.', data.commit); - const result = await getReleaseLine(changeset, 'minor', { repo: data.repo }); - expect(result).toBe('\n- An awesome feature.\n'); - }); -}); - describe('getDependencyReleaseLine', () => { it('should throw an error if options.repo is missing', async () => { const changeset = getChangeset('An awesome feature.', data.commit); @@ -118,3 +96,36 @@ describe('getDependencyReleaseLine', () => { ); }); }); + +describe('getReplacedChangelog', () => { + it('should throw an error if options.repo is missing', async () => { + const changeset = getChangeset('An awesome feature.', data.commit); + const result = getReleaseLine(changeset, 'minor', {}); + await expect(result).rejects.toThrowError(errorMessage); + }); + + it('should return the changelog in a string format', async () => { + const changeset = getChangeset( + 'An awesome feature.\npr: #2\ncommit: 38f35f8\nauthor: @mheob', + data.commit, + ); + const result = await getReleaseLine(changeset, 'minor', { repo: data.repo }); + expect(result).toBe( + '\n- An awesome feature. ([[#2](https://github.com/mheob/changeset-changelog/pull/2)] [`38f35f8`](https://github.com/mheob/changeset-changelog/commit/38f35f8) by [@mheob](https://github.com/mheob))\n', + ); + }); + + it('should return the changelog in a string format but without meta data', async () => { + const changeset = getChangeset('An awesome feature.', data.commit); + const result = await getReleaseLine(changeset, 'minor', { repo: data.repo }); + expect(result).toBe( + '\n- An awesome feature. ([[#2](https://github.com/mheob/changeset-changelog/pull/2)] [`38f35f8`](https://github.com/mheob/changeset-changelog/commit/38f35f8) by [@mheob](https://github.com/mheob))\n', + ); + }); + + it('should return the changelog in a string format but without meta data', async () => { + const changeset = getChangeset('An awesome feature.'); + const result = await getReleaseLine(changeset, 'minor', { repo: data.repo }); + expect(result).toBe('\n- An awesome feature.\n'); + }); +}); diff --git a/src/index.ts b/src/index.ts index 65e04ee..9780cd9 100644 --- a/src/index.ts +++ b/src/index.ts @@ -3,6 +3,7 @@ import type { GetDependencyReleaseLine, GetReleaseLine, } from '@changesets/types'; +import { config } from 'dotenv'; import { errorMessage, @@ -12,20 +13,7 @@ import { getUserLink, } from './utils'; -export const getReleaseLine: GetReleaseLine = async (changeset, _type, options) => { - if (!options?.['repo']) throw new Error(errorMessage); - - const { prFromSummary, replacedChangelog, usersFromSummary } = getReplacedChangelog(changeset); - const { pull, user } = await getGitHubLinks(options['repo'], prFromSummary); - const userLink = getUserLink(usersFromSummary, user); - const [firstLine, ...futureLines] = replacedChangelog.split('\n').map((line) => line.trimEnd()); - - const suffix = [pull ? `[${pull}]` : '', userLink ? ` - Thanks ${userLink}!` : ''].join(''); - const suffixedMessage = suffix ? ` (${suffix})` : ''; - const futureLinesMessage = futureLines.map((line) => ` ${line}`).join('\n'); - - return `\n- ${firstLine}${suffixedMessage}\n${futureLinesMessage}`; -}; +config(); export const getDependencyReleaseLine: GetDependencyReleaseLine = async ( changesets, @@ -44,6 +32,27 @@ export const getDependencyReleaseLine: GetDependencyReleaseLine = async ( return [headerMessage, ...updatedDependenciesList].join('\n'); }; +export const getReleaseLine: GetReleaseLine = async (changeset, _type, options) => { + if (!options?.['repo']) throw new Error(errorMessage); + + const { commitFromSummary, prFromSummary, replacedChangelog, usersFromSummary } = + getReplacedChangelog(changeset); + const { commit, pull, user } = await getGitHubLinks( + options['repo'], + changeset.commit, + commitFromSummary, + prFromSummary, + ); + const userLink = getUserLink(usersFromSummary, user); + const [firstLine, ...futureLines] = replacedChangelog.split('\n').map((line) => line.trimEnd()); + + const suffix = [pull ? `[${pull}]` : '', commit ?? '', userLink ?? ''].join(' '); + const suffixedMessage = suffix.trim() ? ` (${suffix})` : ''; + const futureLinesMessage = futureLines.map((line) => ` ${line}`).join('\n'); + + return `\n- ${firstLine}${suffixedMessage}\n${futureLinesMessage}`; +}; + const changelogFunctions: ChangelogFunctions = { getDependencyReleaseLine, getReleaseLine, diff --git a/src/utils.test.ts b/src/utils.test.ts index 1746e75..1c4671a 100644 --- a/src/utils.test.ts +++ b/src/utils.test.ts @@ -79,15 +79,20 @@ describe('getReplacedChangelog', () => { describe('getGitHubLinks', () => { it('should return the github links', async () => { - const result = await getGitHubLinks(data.repo, data.pull); + const changeset = getChangeset('', data.commit); + const result = await getGitHubLinks(data.repo, data.commit, changeset.commit, data.pull); + expect(result.commit).toBe( + '[`38f35f8`](https://github.com/mheob/changeset-changelog/commit/38f35f8)', + ); expect(result.pull).toBe('[#2](https://github.com/mheob/changeset-changelog/pull/2)'); expect(result.user).toBe('[@mheob](https://github.com/mheob)'); }); it('should return the empty github links if no pr is given', async () => { const result = await getGitHubLinks(data.repo); - expect(result.pull).toBe(''); - expect(result.user).toBeNull(); + expect(result.commit).toBeUndefined(); + expect(result.pull).toBeUndefined(); + expect(result.user).toBeUndefined(); }); }); @@ -95,19 +100,19 @@ describe('getUserLink', () => { it('should return the user links on no giving user', () => { const userLink = '[@mheob](https://github.com/mheob)'; const result = getUserLink([], userLink); - expect(result).toBe(userLink); + expect(result).toBe(`by ${userLink}`); }); it('should return the user links on one giving user', () => { const userLink = '[@mheob](https://github.com/mheob)'; const result = getUserLink([data.user], `defect ${userLink}`); - expect(result).toBe(userLink); + expect(result).toBe(`by ${userLink}`); }); it('should return the user links on multiple giving user', () => { const userLink = '[@mheob](https://github.com/mheob), [@mheob](https://github.com/mheob)'; const result = getUserLink([data.user, data.user], `defect ${userLink}`); - expect(result).toBe(userLink); + expect(result).toBe(`by ${userLink}`); }); }); diff --git a/src/utils.ts b/src/utils.ts index be1ee50..4957d9b 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -4,15 +4,36 @@ import type { NewChangesetWithCommit } from '@changesets/types'; export const errorMessage = `Please provide a repo to this changelog generator like this: "changelog": ["@mheob/changeset-changelog", { "repo": "org/repo" }]`; +export async function getDependencyReleaseLinks( + changesets: NewChangesetWithCommit[], + repository: string, +): Promise { + const changesetLinks = await Promise.all( + changesets.map(async (cs) => { + if (!cs.commit) return; + const { links } = await getInfo({ repo: repository, commit: cs.commit }); + return links.commit; + }), + ); + + return changesetLinks.filter(Boolean).join(', '); +} + export function getReplacedChangelog(changeset: NewChangesetWithCommit): { + commitFromSummary: string | undefined; prFromSummary: number | undefined; - usersFromSummary: string[]; replacedChangelog: string; + usersFromSummary: string[]; } { let prFromSummary: number | undefined; + let commitFromSummary: string | undefined; const usersFromSummary: string[] = []; const replacedChangelog = changeset.summary + .replace(/^\s*commit:\s*(\S+)/im, (_, commit) => { + commitFromSummary = commit; + return ''; + }) .replace(/^\s*(?:pr|pull|pull\s+request):\s*#?(\d+)/im, (_, pr) => { const prNumber = Number(pr); if (!Number.isNaN(prNumber)) prFromSummary = prNumber; @@ -25,48 +46,65 @@ export function getReplacedChangelog(changeset: NewChangesetWithCommit): { .trim(); return { + commitFromSummary, prFromSummary, - usersFromSummary, replacedChangelog, + usersFromSummary, }; } +type MaybeString = string | undefined; +type GithubLinks = { commit: MaybeString; pull: MaybeString; user: MaybeString }; export async function getGitHubLinks( repository: string, + commit?: string, + commitFromSummary?: string, prFromSummary?: number, -): Promise<{ pull: string; user: string | null }> { +): Promise { + let githubLinks: GithubLinks = { commit: undefined, pull: undefined, user: undefined }; + if (prFromSummary) { const { links } = await getInfoFromPullRequest({ pull: prFromSummary, repo: repository }); - return { + githubLinks = { + ...githubLinks, pull: links.pull, - user: links.user, + // istanbul ignore next: because of our mocked get-github-info + user: links.user ?? undefined, }; + + if (commitFromSummary) { + githubLinks = { + ...githubLinks, + commit: `[\`${commitFromSummary}\`](https://github.com/${repository}/commit/${commitFromSummary})`, + }; + } + + return githubLinks; } - return { pull: '', user: null }; -} + const commitToFetchFrom = commitFromSummary || commit; -type UserLink = string | null; + if (commitToFetchFrom) { + const { links } = await getInfo({ repo: repository, commit: commitToFetchFrom }); + return { + commit: links.commit, + // istanbul ignore next: because of our mocked get-github-info + pull: links.pull ?? undefined, + // istanbul ignore next: because of our mocked get-github-info + user: links.user ?? undefined, + }; + } -export function getUserLink(usersFromSummary: string[], user: UserLink): UserLink { - return usersFromSummary.length > 0 - ? usersFromSummary - .map((userFromSummary) => `[@${userFromSummary}](https://github.com/${userFromSummary})`) - .join(', ') - : user; + return githubLinks; } -export async function getDependencyReleaseLinks( - changesets: NewChangesetWithCommit[], - repository: string, -): Promise { - const changesetLinks = await Promise.all( - changesets.map(async (cs) => { - if (!cs.commit) return; - const { links } = await getInfo({ repo: repository, commit: cs.commit }); - return links.commit; - }), - ); +export function getUserLink(usersFromSummary: string[], user?: string): string | undefined { + const userLink = + usersFromSummary.length > 0 + ? usersFromSummary + .map((userFromSummary) => `[@${userFromSummary}](https://github.com/${userFromSummary})`) + .join(', ') + : user; - return changesetLinks.filter(Boolean).join(', '); + return userLink ? `by ${userLink}` : undefined; } diff --git a/vitest.config.ts b/vitest.config.ts index 1eab83a..3589e04 100644 --- a/vitest.config.ts +++ b/vitest.config.ts @@ -2,5 +2,7 @@ import { defineConfig } from 'vitest/config'; export default defineConfig({ - test: {}, + test: { + coverage: { provider: 'istanbul' }, + }, });