Skip to content

Commit 4a66170

Browse files
Bledaicchanche
andauthored
fix: empty template when prs all are excluded by labels (#1429)
* Fix: Move changelog empty check after categorization for accuracy * chore: add tests and update build --------- Co-authored-by: Clément Chanchevrier <[email protected]>
1 parent 7431882 commit 4a66170

4 files changed

Lines changed: 47 additions & 6 deletions

File tree

badges/coverage.svg

Lines changed: 1 addition & 1 deletion
Loading

dist/actions/drafter/run.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/actions/drafter/lib/build-release-payload/generate-changelog.ts

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,21 @@ export const generateChangeLog = (params: {
1919
}) => {
2020
const { pullRequests, config } = params
2121

22-
if (pullRequests.length === 0) {
23-
return config['no-changes-template']
24-
}
25-
2622
const [uncategorizedPullRequests, categorizedPullRequests] =
2723
categorizePullRequests({ pullRequests, config })
2824

25+
const categorizedPullRequestsCount = categorizedPullRequests.reduce(
26+
(sum, category) => sum + category.pullRequests.length,
27+
0,
28+
)
29+
30+
const totalPullRequestsInChangelog =
31+
categorizedPullRequestsCount + uncategorizedPullRequests.length
32+
33+
if (totalPullRequestsInChangelog === 0) {
34+
return config['no-changes-template']
35+
}
36+
2937
const changeLog: string[] = []
3038

3139
if (uncategorizedPullRequests.length > 0) {

src/tests/drafter/build-release-payload.test.ts

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,39 @@ describe('generate changelog', () => {
191191
* Adds @nullable annotations to the 1*1+2*4 test in \`tests.java\` (#0) @Happypig375"
192192
`)
193193
})
194+
195+
it('returns no-changes-template when no pull requests are provided', () => {
196+
const changelog = generateChangeLog({
197+
config,
198+
pullRequests: [],
199+
})
200+
201+
expect(changelog).toBe('* No changes')
202+
})
203+
204+
it('returns no-changes-template when all pull requests are excluded by exclude-labels', () => {
205+
const changelog = generateChangeLog({
206+
config: {
207+
...config,
208+
'exclude-labels': ['bug', 'feature', 'bugfix', 'dependencies'],
209+
},
210+
pullRequests,
211+
})
212+
213+
expect(changelog).toBe('* No changes')
214+
})
215+
216+
it('returns no-changes-template when no pull requests match include-labels', () => {
217+
const changelog = generateChangeLog({
218+
config: {
219+
...config,
220+
'include-labels': ['non-existent-label'],
221+
},
222+
pullRequests,
223+
})
224+
225+
expect(changelog).toBe('* No changes')
226+
})
194227
})
195228

196229
const pullRequests: Parameters<typeof buildReleasePayload>[0]['pullRequests'] =

0 commit comments

Comments
 (0)