File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 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
Original file line number Diff line number Diff 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 ( ": " )
You can’t perform that action at this time.
0 commit comments