diff --git a/scripts/release/generate-changelog.js b/scripts/release/generate-changelog.js index 9e128f148f..1c7696e69b 100644 --- a/scripts/release/generate-changelog.js +++ b/scripts/release/generate-changelog.js @@ -10,11 +10,23 @@ const { spawnCommand, printError, runMain } = require('../lib/execution-utils') const { command } = require('../lib/command') const { modifyFile } = require('../lib/files-utils') -const CHANGELOG_FILE = 'CHANGELOG.md' -const CONTRIBUTING_FILE = 'CONTRIBUTING.md' -const EMOJI_PRIORITY = ['๐Ÿ’ฅ', 'โœจ', '๐Ÿ›', 'โš—๏ธ', 'โ™ป๏ธ'] -const START_WITH_EMOJI = /^\p{Emoji_Presentation}/u - +const CHANGELOG_FILE = '../../CHANGELOG.md' +const CONTRIBUTING_FILE = '../../CONTRIBUTING.md' +const PUBLIC_EMOJI_PRIORITY = ['๐Ÿ’ฅ', 'โœจ', '๐Ÿ›', 'โšก๏ธ', '๐Ÿ“', 'โš—๏ธ'] +const INTERNAL_EMOJI_PRIORITY = [ + '๐Ÿ‘ท', + '๐Ÿ”ง', + '๐Ÿ“ฆ', // build conf + 'โ™ป๏ธ', + '๐ŸŽจ', // refactoring + '๐Ÿงช', + 'โœ…', // tests + '๐Ÿ”‡', + '๐Ÿ”Š', // telemetry + '๐Ÿ‘Œ', + '๐Ÿ“„', +] +const EMOJI_REGEX = /^\p{Emoji_Presentation}/u runMain(async () => { if (!process.env.EDITOR) { printError('Please configure your environment variable EDITOR') @@ -64,6 +76,8 @@ async function getEmojisLegend() { } } + lines.push('>', '> See [Gitmoji](https://gitmoji.dev/) for a guide on the emojis used.') + return lines.join('\n') } @@ -73,30 +87,44 @@ function getChangesList() { const lastTagName = command`git describe --tags ${lastTagHash}`.run() const commits = command`git log ${lastTagName.trimEnd()}..HEAD --pretty=format:%s`.run() - const changesWithEmojis = emojiNameToUnicode(commits) - const allowedChanges = changesWithEmojis - .split('\n') - .filter(isNotVersionEntry) - .filter(isNotMaintenanceEntry) - .sort(byEmojiPriority) - .map((entry) => `- ${entry}`) - .join('\n') - - // changes with pull request links - return allowedChanges.replace( - /\(#(\d+)\)/gm, - (_, id) => `([#${id}](https://github.com/DataDog/browser-sdk/pull/${id}))` - ) -} + let changes = changesWithEmojis.split('\n').filter(isNotVersionEntry) + let internalChanges = [] + let publicChanges = [] -function isNotVersionEntry(line) { - return !/^v\d+\.\d+\.\d+/.test(line) + changes.forEach((entry) => { + let trimmedEntry = entry.trim() + if (PUBLIC_EMOJI_PRIORITY.some((emoji) => trimmedEntry.startsWith(emoji))) { + publicChanges.push(entry) + } else { + internalChanges.push(entry) + } + }) + + const sortAndFormat = (entries, priority) => + entries.sort((a, b) => sortByEmojiPriority(a, b, priority)).map((entry) => `- ${entry}`) + internalChanges = sortAndFormat(internalChanges, INTERNAL_EMOJI_PRIORITY) + publicChanges = sortAndFormat(publicChanges, PUBLIC_EMOJI_PRIORITY) + + return ` +**Public Changes:** + +${publicChanges.join('\n')} + +**Internal Changes:** + +${internalChanges.join('\n')} +`.replace(/\(#(\d+)\)/gm, (_, id) => `([#${id}](https://github.com/DataDog/browser-sdk/pull/${id}))`) } -function isNotMaintenanceEntry(line) { - return !/^๐Ÿ‘ท/.test(line) +function sortByEmojiPriority(a, b, priorityList) { + const getFirstRelevantEmojiIndex = (text) => { + const matches = text.match(EMOJI_REGEX) || [] + const emoji = matches.find((emoji) => priorityList.includes(emoji)) + return emoji ? priorityList.indexOf(emoji) : Number.MAX_VALUE + } + return getFirstRelevantEmojiIndex(a) - getFirstRelevantEmojiIndex(b) } function emojiNameToUnicode(changes) { @@ -104,22 +132,6 @@ function emojiNameToUnicode(changes) { return changes.replace(emojiNameRegex, (emoji) => emojiNameMap.get(emoji) || emoji) } -function byEmojiPriority(a, b) { - const priorityA = computeEmojiPriority(a) - const priorityB = computeEmojiPriority(b) - if (priorityA < priorityB) { - return -1 - } - if (priorityB > priorityA) { - return 1 - } - return 0 -} - -function computeEmojiPriority(entry) { - const match = START_WITH_EMOJI.exec(entry) - if (match && EMOJI_PRIORITY.includes(match[0])) { - return EMOJI_PRIORITY.indexOf(match[0]) - } - return Number.MAX_VALUE +function isNotVersionEntry(line) { + return !/^v\d+\.\d+\.\d+/.test(line) }