Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: verify Changelog entry is not added to a released section #44

Merged
merged 3 commits into from
Oct 17, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Changelog

## 2.4.0

### Features

- Danger - check that a changelog entry is not added to an already released section ([#44](https://github.com/getsentry/github-workflows/pull/44))
vaind marked this conversation as resolved.
Show resolved Hide resolved

## 2.3.0

### Features
Expand Down
29 changes: 21 additions & 8 deletions danger/dangerfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,19 +79,32 @@ async function checkChangelog() {
changelogFile
);

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

if (hasChangelogEntry) {
return;
// check if a changelog entry exists
if (!changelogMatch) {
return reportMissingChangelog(changelogFile);
}

// Report missing changelog entry
fail(
"Please consider adding a changelog entry for the next release.",
changelogFile
);
// Check if the entry is added to an Unreleased section (or rather, check that it's not added to a released one)
const textBeforeEntry = changelogMatch[1]
const section = RegExp('^(## +v?[0-9.]+)([\-\n _]|$)', 'm').exec(textBeforeEntry)
if (section) {
const lineNr = 1 + textBeforeEntry.split(/\r\n|\r|\n/).length
fail(
`The changelog entry seems to be part of an already released section \`${section[1]}\`.
Consider moving the entry to the \`## Unreleased\` section, please.`,
changelogFile,
lineNr
);
}
}

/// Report missing changelog entry
function reportMissingChangelog(changelogFile) {
fail("Please consider adding a changelog entry for the next release.", changelogFile);

const prTitleFormatted = danger.github.pr.title
.split(": ")
Expand Down