Skip to content

Commit 46fe875

Browse files
authored
feat: verify Changelog entry is not added to a released section (#44)
1 parent 2a7982d commit 46fe875

File tree

2 files changed

+27
-8
lines changed

2 files changed

+27
-8
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# Changelog
22

3+
## 2.4.0
4+
5+
### Features
6+
7+
- Danger - check that a changelog entry is not added to an already released section ([#44](https://github.com/getsentry/github-workflows/pull/44))
8+
39
## 2.3.0
410

511
### Features

danger/dangerfile.js

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -79,19 +79,32 @@ async function checkChangelog() {
7979
changelogFile
8080
);
8181

82-
const hasChangelogEntry = RegExp(`#${danger.github.pr.number}\\b`).test(
82+
const changelogMatch = RegExp(`^(.*)\n[^\n]+#${danger.github.pr.number}\\b`, 's').exec(
8383
changelogContents
8484
);
8585

86-
if (hasChangelogEntry) {
87-
return;
86+
// check if a changelog entry exists
87+
if (!changelogMatch) {
88+
return reportMissingChangelog(changelogFile);
8889
}
8990

90-
// Report missing changelog entry
91-
fail(
92-
"Please consider adding a changelog entry for the next release.",
93-
changelogFile
94-
);
91+
// Check if the entry is added to an Unreleased section (or rather, check that it's not added to a released one)
92+
const textBeforeEntry = changelogMatch[1]
93+
const section = RegExp('^(## +v?[0-9.]+)([\-\n _]|$)', 'm').exec(textBeforeEntry)
94+
if (section) {
95+
const lineNr = 1 + textBeforeEntry.split(/\r\n|\r|\n/).length
96+
fail(
97+
`The changelog entry seems to be part of an already released section \`${section[1]}\`.
98+
Consider moving the entry to the \`## Unreleased\` section, please.`,
99+
changelogFile,
100+
lineNr
101+
);
102+
}
103+
}
104+
105+
/// Report missing changelog entry
106+
function reportMissingChangelog(changelogFile) {
107+
fail("Please consider adding a changelog entry for the next release.", changelogFile);
95108

96109
const prTitleFormatted = danger.github.pr.title
97110
.split(": ")

0 commit comments

Comments
 (0)