Skip to content

Commit

Permalink
Remove trailing newline from changelog entries (#192)
Browse files Browse the repository at this point in the history
  • Loading branch information
stormwarning authored Jan 18, 2024
1 parent ed20541 commit 5d9ec67
Show file tree
Hide file tree
Showing 7 changed files with 713 additions and 5 deletions.
5 changes: 5 additions & 0 deletions .changeset/seven-forks-live.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@zazen/changesets-changelog": patch
---

Remove trailing newline for changesets without a description
3 changes: 3 additions & 0 deletions .eslintrc.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ const config = {
parserOptions: {
ecmaVersion: 2021,
},
settings: {
'import/ignore': ['node_modules'],
},
extends: ['@zazen', '@zazen/eslint-config/node'],
rules: {
'no-return-await': 'off',
Expand Down
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,9 @@
"lint-staged": "15.2.0",
"prettier": "3.1.1",
"prettier-plugin-packagejson": "2.4.7",
"typescript": "5.3.3"
"typescript": "5.3.3",
"vite": "5.0.11",
"vitest": "1.2.1"
},
"packageManager": "pnpm@8.6.12",
"engines": {
Expand Down
186 changes: 186 additions & 0 deletions packages/changesets-changelog/__tests__/index.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,186 @@
import parse from '@changesets/parse'
import { vi, describe, test, it, expect } from 'vitest'

import changelogFunctions from '../index.js'

const { getReleaseLine } = changelogFunctions

const DOUBLE_SPACE = ` `
const MOCK_DATA = {
commit: 'a085003',
user: 'stormwarning',
pull: 420,
repo: 'stormwarning/zazen',
}

vi.mock('@changesets/get-github-info', () => {
// This is duplicated because `vi.mock` is hoisted.
let data = {
commit: 'a085003',
user: 'stormwarning',
pull: 420,
repo: 'stormwarning/zazen',
}
let links = {
user: `[@${data.user}](https://github.com/${data.user})`,
pull: `[#${data.pull}](https://github.com/${data.repo}/pull/${data.pull})`,
commit: `[\`${data.commit}\`](https://github.com/${data.repo}/commit/${data.commit})`,
}

return {
async getInfo({ commit, repo }) {
expect(commit).toBe(data.commit)
expect(repo).toBe(data.repo)
return {
pull: data.pull,
user: data.user,
links,
}
},
async getInfoFromPullRequest({ pull, repo }) {
expect(pull).toBe(data.pull)
expect(repo).toBe(data.repo)
return {
commit: data.commit,
user: data.user,
links,
}
},
}
})

/**
* @param {string} content
* @param {string} [commit]
*/
function getChangeset(content, commit) {
return [
{
...parse(
`---
pkg: "minor"
---
Change
Description of change.
${content}
`,
),
id: 'some-id',
commit,
},
'minor',
{ repo: MOCK_DATA.repo },
]
}

describe.each([MOCK_DATA.commit])(
'with commit from changeset of %s',
(commitFromChangeset) => {
describe.each(['pr', 'pull request', 'pull'])(
'override pr with %s keyword',
(keyword) => {
test.each(['with #', 'without #'])('%s', async (kind) => {
let output = `
- Change ([#420](https://github.com/stormwarning/zazen/pull/420))
${DOUBLE_SPACE}
Description of change.`

expect(
await getReleaseLine(
...getChangeset(
`${keyword}: ${kind === 'with #' ? '#' : ''}${
MOCK_DATA.pull
}`,
commitFromChangeset,
),
),
).toEqual(output)
})
},
)
test('override commit with commit keyword', async () => {
let output = `
- Change ([#420](https://github.com/stormwarning/zazen/pull/420))
${DOUBLE_SPACE}
Description of change.`

expect(
await getReleaseLine(
...getChangeset(
`commit: ${MOCK_DATA.commit}`,
commitFromChangeset,
),
),
).toEqual(output)
})
},
)

describe.each(['author', 'user'])(
'override author with %s keyword',
(keyword) => {
describe.each(['with @', 'without @'])('%s', async (kind) => {
it('ignores author if they are the repo owner', async () => {
let output = `
- Change ([#420](https://github.com/stormwarning/zazen/pull/420))
${DOUBLE_SPACE}
Description of change.`

expect(
await getReleaseLine(
...getChangeset(
`${keyword}: ${
kind === 'with @' ? '@' : ''
}stormwarning`,
MOCK_DATA.commit,
),
),
).toEqual(output)
})

it('thanks author if they are not the repo owner', async () => {
let output = `
- Change ([#420](https://github.com/stormwarning/zazen/pull/420))
Thanks [@hubot](https://github.com/hubot)!
${DOUBLE_SPACE}
Description of change.`

expect(
await getReleaseLine(
...getChangeset(
`${keyword}: ${kind === 'with @' ? '@' : ''}hubot`,
MOCK_DATA.commit,
),
),
).toEqual(output)
})

it('thanks multiple authors', async () => {
let output = `
- Change ([#420](https://github.com/stormwarning/zazen/pull/420))
Thanks [@hubot](https://github.com/hubot), [@tidaltheory](https://github.com/tidaltheory)!
${DOUBLE_SPACE}
Description of change.`

expect(
await getReleaseLine(
...getChangeset(
[
`${keyword}: ${
kind === 'with @' ? '@' : ''
}hubot`,
`${keyword}: ${
kind === 'with @' ? '@' : ''
}tidaltheory`,
].join('\n'),

MOCK_DATA.commit,
),
),
).toEqual(output)
})
})
},
)
8 changes: 5 additions & 3 deletions packages/changesets-changelog/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -124,10 +124,12 @@ const changelogFunctions = {
let userThanks = users === null ? '' : `\n Thanks ${users}!`
let versionInfo =
links.pull === null ? ` ${links.commit}` : ` (${links.pull})`
let description =
futureLines.length > 0
? `\n${futureLines.map((l) => ` ${l}`).join('\n')}`
: undefined

return `\n- ${firstLine}${versionInfo}${userThanks}\n${futureLines
.map((l) => ` ${l}`)
.join('\n')}`
return `\n- ${firstLine}${versionInfo}${userThanks}${description}`
},
}

Expand Down
3 changes: 2 additions & 1 deletion packages/changesets-changelog/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@
},
"main": "dist/index.cjs",
"scripts": {
"build": "esbuild index.js --format=cjs --outfile=dist/index.cjs"
"build": "esbuild index.js --format=cjs --outfile=dist/index.cjs",
"test": "vitest run"
},
"dependencies": {
"@changesets/get-github-info": "0.6.0",
Expand Down
Loading

0 comments on commit 5d9ec67

Please sign in to comment.