Skip to content

Commit

Permalink
feat: allow defining multiple generateNotes plugins
Browse files Browse the repository at this point in the history
As of `semantic-release` 15.7, the `generateNotes` plugin hook went from supporting a "solo" plugin to a "multi" plugin configuration, meaning it accepts an array of plugin definitions instead of just a single definition.

https://github.com/semantic-release/semantic-release/releases/tag/v15.7.0
  • Loading branch information
pmowrer committed Sep 11, 2018
1 parent ae45267 commit abe1f7c
Show file tree
Hide file tree
Showing 4 changed files with 125 additions and 138 deletions.
11 changes: 9 additions & 2 deletions bin/semantic-release-github-pr.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,16 @@ const { getCurrentBranchName } = require('../src/git-utils');
// Set `dry-run` to keep `semantic-release` from publishing an actual release.
`--dry-run`,
`--branch=${branch}`,
// We hard-set our versions of `analyze-commits` and `generate-notes`.
// We hard-set our version of `analyze-commits (preventing accidental override)`.
`--analyze-commits=${plugins}`,
`--generate-notes=${plugins}`,

// TODO: Used to hard-set our version of `generateNotes` as well, but no
// longer seems possible after it became a "multi plugin" (array)
// configuration in `semantic-release` 15.7.0. Instead, it's soft-set set
// via the shareable config option below (`--extends`). It doesn't matter
// other than it allows the user to break the plugin by (inadvertently)
// overriding our version of `generateNotes`.

// We use `extends` here to pick up a soft-set default for `verifyConditions`,
// allowing users to override it (setting a plugin directly from the CLI
// trumps plugins read from a config file).
Expand Down
7 changes: 5 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@
"version": "0.0.0-development",
"description": " A `semantic-release` plugin that creates a changelog comment on Github PRs.",
"main": "src/index.js",
"files": ["src", "bin"],
"files": [
"src",
"bin"
],
"repository": "https://github.com/Updater/semantic-release-github-pr.git",
"scripts": {
"format": "prettier --write --single-quote --trailing-comma es5",
Expand All @@ -22,7 +25,7 @@
"parse-github-url": "^1.0.1",
"ramda": "^0.25.0",
"read-pkg": "^3.0.0",
"semantic-release-plugin-decorators": "^1.2.1"
"semantic-release-plugin-decorators": "^2.0.0"
},
"devDependencies": {
"debug": "^3.1.0",
Expand Down
23 changes: 13 additions & 10 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
const { compose } = require('ramda');
const { wrapPlugin } = require('semantic-release-plugin-decorators');
const {
wrapPlugin,
appendMultiPlugin,
} = require('semantic-release-plugin-decorators');
const pluginDefinitions = require('semantic-release/lib/definitions/plugins');

const { parse } = require('./comment-tag');
Expand All @@ -12,7 +15,7 @@ const withMatchingPullRequests = require('./with-matching-pull-requests');

const NAMESPACE = 'githubPr';

const decoratePlugins = compose(
const decoratePlugin = compose(
withGithub,
withGitHead,
withMatchingPullRequests,
Expand Down Expand Up @@ -57,27 +60,27 @@ const analyzeCommits = wrapPlugin(
pluginDefinitions.analyzeCommits.default
);

const generateNotes = wrapPlugin(
// Append a plugin that generates PR comments from the release notes resulting
// from the configured `generateNotes` plugins that run ahead of it.
const generateNotes = appendMultiPlugin(
NAMESPACE,
'generateNotes',
plugin => async (pluginConfig, context) => {
decoratePlugin(async (pluginConfig, context) => {
const { pullRequests } = pluginConfig;
const { nextRelease } = context;

nextRelease.notes = await plugin(pluginConfig, context);

await pullRequests.forEach(
// Create "release" comment
createChangelog(pluginConfig, { ...context, nextRelease })
createChangelog(pluginConfig, context)
);

return nextRelease.notes;
},
}),
pluginDefinitions.generateNotes.default
);

module.exports = {
verifyConditions: '@semantic-release/github',
analyzeCommits: decoratePlugins(analyzeCommits),
generateNotes: decoratePlugins(generateNotes),
analyzeCommits: decoratePlugin(analyzeCommits),
generateNotes,
};
Loading

0 comments on commit abe1f7c

Please sign in to comment.