Skip to content

Commit

Permalink
fix: dont create chore only PRs (#433)
Browse files Browse the repository at this point in the history
  • Loading branch information
lukekarrys authored Apr 22, 2024
1 parent 2e7a6dd commit df03d8b
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 59 deletions.
10 changes: 5 additions & 5 deletions lib/content/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -199,10 +199,10 @@ module.exports = {
},
allowedPackages: [],
changelogTypes: [
{ type: 'feat', section: 'Features', hidden: false, collapse: false },
{ type: 'fix', section: 'Bug Fixes', hidden: false, collapse: false },
{ type: 'docs', section: 'Documentation', hidden: false, collapse: false },
{ type: 'deps', section: 'Dependencies', hidden: false, collapse: false },
{ type: 'chore', section: 'Chores', hidden: false, collapse: false },
{ type: 'feat', section: 'Features', hidden: false },
{ type: 'fix', section: 'Bug Fixes', hidden: false },
{ type: 'docs', section: 'Documentation', hidden: false },
{ type: 'deps', section: 'Dependencies', hidden: false },
{ type: 'chore', section: 'Chores', hidden: true },
],
}
28 changes: 14 additions & 14 deletions lib/release/changelog.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,28 +29,28 @@ class Changelog {
}

#getEntries (type) {
const section = this.#sections[type]
const entries = this.#entries[type].map(list)
// Ignoring coverage until we use this again
/* istanbul ignore next */
if (section?.collapse) {
entries.unshift('<details><summary>Commits</summary>\n')
entries.push('\n</details>')
}
return entries.join('\n')
return this.#entries[type].map(list).join('\n')
}

toString () {
const body = [this.#title]
const includedTypes = []

for (const type of this.#types) {
const title = this.#titles[type]
if (this.#entries[type]?.length) {
body.push(
`### ${title}`,
this.#getEntries(type)
)
includedTypes.push(type)
body.push(`### ${this.#titles[type]}`, this.#getEntries(type))
}
}

// If every commit is from a hidden section then we return an
// empty string which will skip the release PR being created.
// We do this because we don't want PRs opened if they only contain
// chores but we do want to rebuild existing PRs if chores are added.
if (includedTypes.every((type) => this.#sections[type]?.hidden)) {
return ''
}

return body.join('\n\n').trim()
}
}
Expand Down
15 changes: 5 additions & 10 deletions release-please-config.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,32 +3,27 @@
{
"type": "feat",
"section": "Features",
"hidden": false,
"collapse": false
"hidden": false
},
{
"type": "fix",
"section": "Bug Fixes",
"hidden": false,
"collapse": false
"hidden": false
},
{
"type": "docs",
"section": "Documentation",
"hidden": false,
"collapse": false
"hidden": false
},
{
"type": "deps",
"section": "Dependencies",
"hidden": false,
"collapse": false
"hidden": false
},
{
"type": "chore",
"section": "Chores",
"hidden": false,
"collapse": false
"hidden": true
}
],
"packages": {
Expand Down
45 changes: 15 additions & 30 deletions tap-snapshots/test/apply/source-snapshots.js.test.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -1368,32 +1368,27 @@ release-please-config.json
{
"type": "feat",
"section": "Features",
"hidden": false,
"collapse": false
"hidden": false
},
{
"type": "fix",
"section": "Bug Fixes",
"hidden": false,
"collapse": false
"hidden": false
},
{
"type": "docs",
"section": "Documentation",
"hidden": false,
"collapse": false
"hidden": false
},
{
"type": "deps",
"section": "Dependencies",
"hidden": false,
"collapse": false
"hidden": false
},
{
"type": "chore",
"section": "Chores",
"hidden": false,
"collapse": false
"hidden": true
}
],
"prerelease-type": "pre",
Expand Down Expand Up @@ -3031,32 +3026,27 @@ release-please-config.json
{
"type": "feat",
"section": "Features",
"hidden": false,
"collapse": false
"hidden": false
},
{
"type": "fix",
"section": "Bug Fixes",
"hidden": false,
"collapse": false
"hidden": false
},
{
"type": "docs",
"section": "Documentation",
"hidden": false,
"collapse": false
"hidden": false
},
{
"type": "deps",
"section": "Dependencies",
"hidden": false,
"collapse": false
"hidden": false
},
{
"type": "chore",
"section": "Chores",
"hidden": false,
"collapse": false
"hidden": true
}
],
"prerelease-type": "pre",
Expand Down Expand Up @@ -4410,32 +4400,27 @@ release-please-config.json
{
"type": "feat",
"section": "Features",
"hidden": false,
"collapse": false
"hidden": false
},
{
"type": "fix",
"section": "Bug Fixes",
"hidden": false,
"collapse": false
"hidden": false
},
{
"type": "docs",
"section": "Documentation",
"hidden": false,
"collapse": false
"hidden": false
},
{
"type": "deps",
"section": "Dependencies",
"hidden": false,
"collapse": false
"hidden": false
},
{
"type": "chore",
"section": "Chores",
"hidden": false,
"collapse": false
"hidden": true
}
],
"prerelease-type": "pre",
Expand Down
22 changes: 22 additions & 0 deletions test/release/changelog.js
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,10 @@ t.test('filters out multiple template oss commits', async t => {
const changelog = await mockChangelog({
authors: false,
commits: [{
sha: 'z',
type: 'fix',
bareMessage: 'just a fix',
}, {
sha: 'a',
type: 'chore',
bareMessage: 'postinstall for dependabot template-oss PR',
Expand Down Expand Up @@ -152,10 +156,28 @@ t.test('filters out multiple template oss commits', async t => {
})
t.strictSame(changelog, [
'## [1.0.0](https://github.com/npm/cli/compare/v0.1.0...v1.0.0) (DATE)',
'### Bug Fixes',
'* [`z`](https://github.com/npm/cli/commit/z) just a fix',
'### Chores',
// eslint-disable-next-line max-len
'* [`b`](https://github.com/npm/cli/commit/b) [#101](https://github.com/npm/cli/pull/101) postinstall for dependabot template-oss PR',
// eslint-disable-next-line max-len
'* [`c`](https://github.com/npm/cli/commit/c) [#101](https://github.com/npm/cli/pull/101) bump @npmcli/template-oss from 1 to 2',
])
})

t.test('empty change log with only chore commits', async t => {
const changelog = await mockChangelog({
authors: false,
commits: [{
sha: 'a',
type: 'chore',
bareMessage: 'some chore',
}, {
sha: 'a',
type: 'chore',
bareMessage: 'another chore',
}],
})
t.strictSame(changelog, [])
})

0 comments on commit df03d8b

Please sign in to comment.