Skip to content

Commit 651d17e

Browse files
authored
Merge pull request #29 from Updater/fix-missing-context
Fix missing context
2 parents cd62616 + abe1f7c commit 651d17e

9 files changed

Lines changed: 1919 additions & 298 deletions

bin/semantic-release-github-pr.js

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,16 @@ const { getCurrentBranchName } = require('../src/git-utils');
2020
// Set `dry-run` to keep `semantic-release` from publishing an actual release.
2121
`--dry-run`,
2222
`--branch=${branch}`,
23-
// We hard-set our versions of `analyze-commits` and `generate-notes`.
23+
// We hard-set our version of `analyze-commits (preventing accidental override)`.
2424
`--analyze-commits=${plugins}`,
25-
`--generate-notes=${plugins}`,
25+
26+
// TODO: Used to hard-set our version of `generateNotes` as well, but no
27+
// longer seems possible after it became a "multi plugin" (array)
28+
// configuration in `semantic-release` 15.7.0. Instead, it's soft-set set
29+
// via the shareable config option below (`--extends`). It doesn't matter
30+
// other than it allows the user to break the plugin by (inadvertently)
31+
// overriding our version of `generateNotes`.
32+
2633
// We use `extends` here to pick up a soft-set default for `verifyConditions`,
2734
// allowing users to override it (setting a plugin directly from the CLI
2835
// trumps plugins read from a config file).

package.json

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,10 @@
33
"version": "0.0.0-development",
44
"description": " A `semantic-release` plugin that creates a changelog comment on Github PRs.",
55
"main": "src/index.js",
6-
"files": ["src", "bin"],
6+
"files": [
7+
"src",
8+
"bin"
9+
],
710
"repository": "https://github.com/Updater/semantic-release-github-pr.git",
811
"scripts": {
912
"format": "prettier --write --single-quote --trailing-comma es5",
@@ -22,7 +25,7 @@
2225
"parse-github-url": "^1.0.1",
2326
"ramda": "^0.25.0",
2427
"read-pkg": "^3.0.0",
25-
"semantic-release-plugin-decorators": "^1.2.1"
28+
"semantic-release-plugin-decorators": "^2.0.0"
2629
},
2730
"devDependencies": {
2831
"debug": "^3.1.0",

src/github-init.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,12 @@ const { parse } = require('url');
77
* https://github.com/semantic-release/github/blob/d49ce22a7c2d4b0861de31ba00c0b213b23e5051/lib/publish.js#L11
88
*
99
* @param pluginConfig The config object passed to `semantic-release` plugins.
10+
* @param context The context object passed to `semantic-release` plugins.
1011
* @returns An initialized instance of `github`.
1112
*/
12-
module.exports = pluginConfig => {
13+
module.exports = (pluginConfig, context) => {
1314
const { githubToken, githubUrl, githubApiPathPrefix } = resolveConfig(
14-
pluginConfig
15+
pluginConfig, context
1516
);
1617

1718
let { port, protocol, hostname: host } = githubUrl ? parse(githubUrl) : {};

src/index.js

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
const { compose } = require('ramda');
2-
const { wrapPlugin } = require('semantic-release-plugin-decorators');
2+
const {
3+
wrapPlugin,
4+
appendMultiPlugin,
5+
} = require('semantic-release-plugin-decorators');
36
const pluginDefinitions = require('semantic-release/lib/definitions/plugins');
47

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

1316
const NAMESPACE = 'githubPr';
1417

15-
const decoratePlugins = compose(
18+
const decoratePlugin = compose(
1619
withGithub,
1720
withGitHead,
1821
withMatchingPullRequests,
@@ -25,14 +28,14 @@ const decoratePlugins = compose(
2528
const analyzeCommits = wrapPlugin(
2629
NAMESPACE,
2730
'analyzeCommits',
28-
plugin => async (pluginConfig, config) => {
31+
plugin => async (pluginConfig, context) => {
2932
const { githubRepo, pullRequests } = pluginConfig;
30-
const nextRelease = await plugin(pluginConfig, config);
33+
const nextRelease = await plugin(pluginConfig, context);
3134

3235
if (!nextRelease) {
3336
await pullRequests.forEach(async pr => {
3437
const { number } = pr;
35-
const createChangelogOnPr = createChangelog(pluginConfig, config);
38+
const createChangelogOnPr = createChangelog(pluginConfig, context);
3639
const { data: comments } = await githubRepo.getIssueComments({
3740
number,
3841
});
@@ -49,35 +52,35 @@ const analyzeCommits = wrapPlugin(
4952
// Clean up stale changelog comments, possibly sparing the "no release"
5053
// comment if this package doesn't have a new release.
5154
await pullRequests.forEach(
52-
deleteStaleChangelogs(!nextRelease)(pluginConfig, config)
55+
deleteStaleChangelogs(!nextRelease)(pluginConfig, context)
5356
);
5457

5558
return nextRelease;
5659
},
5760
pluginDefinitions.analyzeCommits.default
5861
);
5962

60-
const generateNotes = wrapPlugin(
63+
// Append a plugin that generates PR comments from the release notes resulting
64+
// from the configured `generateNotes` plugins that run ahead of it.
65+
const generateNotes = appendMultiPlugin(
6166
NAMESPACE,
6267
'generateNotes',
63-
plugin => async (pluginConfig, config) => {
68+
decoratePlugin(async (pluginConfig, context) => {
6469
const { pullRequests } = pluginConfig;
65-
const { nextRelease } = config;
66-
67-
nextRelease.notes = await plugin(pluginConfig, config);
70+
const { nextRelease } = context;
6871

6972
await pullRequests.forEach(
7073
// Create "release" comment
71-
createChangelog(pluginConfig, { ...config, nextRelease })
74+
createChangelog(pluginConfig, context)
7275
);
7376

7477
return nextRelease.notes;
75-
},
78+
}),
7679
pluginDefinitions.generateNotes.default
7780
);
7881

7982
module.exports = {
8083
verifyConditions: '@semantic-release/github',
81-
analyzeCommits: decoratePlugins(analyzeCommits),
82-
generateNotes: decoratePlugins(generateNotes),
84+
analyzeCommits: decoratePlugin(analyzeCommits),
85+
generateNotes,
8386
};

src/with-git-head.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,12 @@ const { gitHead: getGitHead } = require('semantic-release/lib/git');
88
* https://github.com/semantic-release/semantic-release/blob/754b420fd6f26444eea53155fc0dbd08a51b4dcb/index.js#L38
99
* @param plugin
1010
*/
11-
const withGitHead = plugin => async (pluginConfig, config) => {
12-
const { nextRelease } = config;
11+
const withGitHead = plugin => async (pluginConfig, context) => {
12+
const { nextRelease } = context;
1313
const gitHead = nextRelease ? nextRelease.gitHead : await getGitHead();
1414

1515
return plugin(pluginConfig, {
16-
...config,
16+
...context,
1717
nextRelease: {
1818
...nextRelease,
1919
gitHead,

src/with-github.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,17 @@ const githubInit = require('./github-init');
22
const githubRepo = require('./github-repo');
33
const parseGithubUrl = require('parse-github-url');
44

5-
const withGithub = plugin => (pluginConfig, config) => {
6-
const github = githubInit(pluginConfig);
7-
const { options: { repositoryUrl } } = config;
5+
const withGithub = plugin => (pluginConfig, context) => {
6+
const github = githubInit(pluginConfig, context);
7+
const { options: { repositoryUrl } } = context;
88
const { name: repo, owner } = parseGithubUrl(repositoryUrl);
99

1010
return plugin(
1111
{
1212
...pluginConfig,
1313
githubRepo: githubRepo(github, { owner, repo }),
1414
},
15-
config
15+
context
1616
);
1717
};
1818

src/with-matching-pull-requests.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
const isMatchingPullRequestFor = require('./is-matching-pull-request-for');
22
const { getCurrentBranchName } = require('./git-utils');
33

4-
const withMatchingPullRequests = plugin => async (pluginConfig, config) => {
4+
const withMatchingPullRequests = plugin => async (pluginConfig, context) => {
55
const { githubRepo } = pluginConfig;
6-
const { nextRelease: { gitHead }, options: { branch } } = config;
6+
const { nextRelease: { gitHead }, options: { branch } } = context;
77
const matchingPrFilter = isMatchingPullRequestFor(gitHead);
88
const { data: openPullRequests = [] } = await githubRepo.getAllPullRequests({
99
// Determine whether the user provided a custom `branch` value.
@@ -17,7 +17,7 @@ const withMatchingPullRequests = plugin => async (pluginConfig, config) => {
1717
...pluginConfig,
1818
pullRequests: openPullRequests.filter(matchingPrFilter),
1919
},
20-
config
20+
context
2121
);
2222
};
2323

src/with-npm-package.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
const readPkg = require('read-pkg');
22

3-
const withNpmPackage = plugin => async (pluginConfig, config) => {
3+
const withNpmPackage = plugin => async (pluginConfig, context) => {
44
const npmPackage = await readPkg();
5-
return plugin({ ...pluginConfig, npmPackage }, config);
5+
return plugin({ ...pluginConfig, npmPackage }, context);
66
};
77

88
module.exports = withNpmPackage;

0 commit comments

Comments
 (0)