From e1887f2df4c8ba2e66894de2fb0058f71787b26e Mon Sep 17 00:00:00 2001 From: Daniel Lockyer Date: Fri, 1 Oct 2021 16:53:40 +0100 Subject: [PATCH] Exposed `getFinalChangelog` helper no issue - this is needed so I can generate the release changelog for the Slack notifications in action-ghost-release --- ghost/release-utils/lib/releases.js | 30 ++--------------------------- ghost/release-utils/lib/utils.js | 28 +++++++++++++++++++++++++++ 2 files changed, 30 insertions(+), 28 deletions(-) diff --git a/ghost/release-utils/lib/releases.js b/ghost/release-utils/lib/releases.js index 8ee8596a0c..f8600a9ab9 100644 --- a/ghost/release-utils/lib/releases.js +++ b/ghost/release-utils/lib/releases.js @@ -7,32 +7,6 @@ const request = require('request'); const localUtils = require('./utils'); -function getFinalChangelog(options) { - let filterEmojiCommits = true; - let changelog = fs.readFileSync(options.changelogPath).toString('utf8').split(os.EOL); - let finalChangelog = []; - - if (Object.prototype.hasOwnProperty.call(options, 'filterEmojiCommits')) { - filterEmojiCommits = options.filterEmojiCommits; - } - // @NOTE: optional array of string lines, which we pre-pend - if (Object.prototype.hasOwnProperty.call(options, 'content') && _.isArray(options.content)) { - finalChangelog = finalChangelog.concat(options.content); - } - - if (filterEmojiCommits) { - changelog = localUtils.filterEmojiCommits(changelog); - localUtils.sortByEmoji(changelog); - } - - if (_.isEmpty(changelog)) { - changelog = ['No user-visible changes in this release.']; - } - - finalChangelog = finalChangelog.concat(changelog); - return finalChangelog; -} - module.exports.create = (options = {}) => { let draft = true; let prerelease = false; @@ -59,11 +33,11 @@ module.exports.create = (options = {}) => { // CASE: changelogPath can be array of paths with content if (_.isArray(options.changelogPath)) { options.changelogPath.forEach((opts) => { - body = body.concat(getFinalChangelog(opts)); + body = body.concat(localUtils.getFinalChangelog(opts)); }); } else { // CASE: changelogPath can be a single path(For backward compatibility) - body = body.concat(getFinalChangelog(options)); + body = body.concat(localUtils.getFinalChangelog(options)); } // CASE: clean before upload diff --git a/ghost/release-utils/lib/utils.js b/ghost/release-utils/lib/utils.js index 60ddc27ac5..b90608bb92 100644 --- a/ghost/release-utils/lib/utils.js +++ b/ghost/release-utils/lib/utils.js @@ -1,4 +1,6 @@ const emojiRegex = require('emoji-regex'); +const fs = require('fs'); +const os = require('os'); const _ = require('lodash'); const {IncorrectUsageError} = require('@tryghost/errors'); @@ -63,3 +65,29 @@ module.exports.checkMissingOptions = (options = {}, ...requiredFields) => { }); } }; + +module.exports.getFinalChangelog = function getFinalChangelog(options) { + let filterEmojiCommits = true; + let changelog = fs.readFileSync(options.changelogPath).toString('utf8').split(os.EOL); + let finalChangelog = []; + + if (Object.prototype.hasOwnProperty.call(options, 'filterEmojiCommits')) { + filterEmojiCommits = options.filterEmojiCommits; + } + // @NOTE: optional array of string lines, which we pre-pend + if (Object.prototype.hasOwnProperty.call(options, 'content') && _.isArray(options.content)) { + finalChangelog = finalChangelog.concat(options.content); + } + + if (filterEmojiCommits) { + changelog = module.exports.filterEmojiCommits(changelog); + module.exports.sortByEmoji(changelog); + } + + if (_.isEmpty(changelog)) { + changelog = ['No user-visible changes in this release.']; + } + + finalChangelog = finalChangelog.concat(changelog); + return finalChangelog; +};