File tree Expand file tree Collapse file tree 2 files changed +27
-8
lines changed Expand file tree Collapse file tree 2 files changed +27
-8
lines changed Original file line number Diff line number Diff line change 1
1
# Changelog
2
2
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
+
3
9
## 2.3.0
4
10
5
11
### Features
Original file line number Diff line number Diff line change @@ -79,19 +79,32 @@ async function checkChangelog() {
79
79
changelogFile
80
80
) ;
81
81
82
- const hasChangelogEntry = RegExp ( `#${ danger . github . pr . number } \\b` ) . test (
82
+ const changelogMatch = RegExp ( `^(.*)\n[^\n]+ #${ danger . github . pr . number } \\b` , 's' ) . exec (
83
83
changelogContents
84
84
) ;
85
85
86
- if ( hasChangelogEntry ) {
87
- return ;
86
+ // check if a changelog entry exists
87
+ if ( ! changelogMatch ) {
88
+ return reportMissingChangelog ( changelogFile ) ;
88
89
}
89
90
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 ) ;
95
108
96
109
const prTitleFormatted = danger . github . pr . title
97
110
. split ( ": " )
You can’t perform that action at this time.
0 commit comments