@semantic-release/github 8.1.0 → 9.0.0-beta.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -10,7 +10,7 @@
10
10
  [![npm beta version](https://img.shields.io/npm/v/@semantic-release/github/beta.svg)](https://www.npmjs.com/package/@semantic-release/github)
11
11
 
12
12
  | Step | Description |
13
- |--------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
13
+ | ------------------ | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
14
14
  | `verifyConditions` | Verify the presence and the validity of the authentication (set via [environment variables](#environment-variables)) and the [assets](#assets) option configuration. |
15
15
  | `publish` | Publish a [GitHub release](https://help.github.com/articles/about-releases), optionally uploading file assets. |
16
16
  | `addChannel` | Update a [GitHub release](https://help.github.com/articles/about-releases)'s `pre-release` field. |
@@ -32,12 +32,15 @@ The plugin can be configured in the [**semantic-release** configuration file](ht
32
32
  "plugins": [
33
33
  "@semantic-release/commit-analyzer",
34
34
  "@semantic-release/release-notes-generator",
35
- ["@semantic-release/github", {
36
- "assets": [
37
- {"path": "dist/asset.min.css", "label": "CSS distribution"},
38
- {"path": "dist/asset.min.js", "label": "JS distribution"}
39
- ]
40
- }],
35
+ [
36
+ "@semantic-release/github",
37
+ {
38
+ "assets": [
39
+ { "path": "dist/asset.min.css", "label": "CSS distribution" },
40
+ { "path": "dist/asset.min.js", "label": "JS distribution" }
41
+ ]
42
+ }
43
+ ]
41
44
  ]
42
45
  }
43
46
  ```
@@ -57,7 +60,7 @@ When creating the token, the **minimum required scopes** are:
57
60
  - [`repo`](https://github.com/settings/tokens/new?scopes=repo) for a private repository
58
61
  - [`public_repo`](https://github.com/settings/tokens/new?scopes=public_repo) for a public repository
59
62
 
60
- _Notes on GitHub Actions:_ You can use the default token which is provided in the secret _GITHUB_TOKEN_. However releases done with this token will NOT trigger release events to start other workflows.
63
+ _Note on GitHub Actions:_ You can use the default token which is provided in the secret _GITHUB_TOKEN_. However releases done with this token will NOT trigger release events to start other workflows.
61
64
  If you have actions that trigger on newly created releases, please use a generated token for that and store it in your repository's secrets (any other name than GITHUB_TOKEN is fine).
62
65
 
63
66
  When using the _GITHUB_TOKEN_, the **minimum required permissions** are:
@@ -68,35 +71,35 @@ When using the _GITHUB_TOKEN_, the **minimum required permissions** are:
68
71
 
69
72
  ### Environment variables
70
73
 
71
- | Variable | Description |
72
- | -------------------------------------------------- | --------------------------------------------------------- |
73
- | `GH_TOKEN` or `GITHUB_TOKEN` | **Required.** The token used to authenticate with GitHub. |
74
- | `GITHUB_API_URL` or `GH_URL` or `GITHUB_URL` | The GitHub Enterprise endpoint. |
75
- | `GH_PREFIX` or `GITHUB_PREFIX` | The GitHub Enterprise API prefix. |
74
+ | Variable | Description |
75
+ | -------------------------------------------- | --------------------------------------------------------- |
76
+ | `GH_TOKEN` or `GITHUB_TOKEN` | **Required.** The token used to authenticate with GitHub. |
77
+ | `GITHUB_API_URL` or `GH_URL` or `GITHUB_URL` | The GitHub Enterprise endpoint. |
78
+ | `GH_PREFIX` or `GITHUB_PREFIX` | The GitHub Enterprise API prefix. |
76
79
 
77
80
  ### Options
78
81
 
79
82
  | Option | Description | Default |
80
- |-----------------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|------------------------------------------------------------------------------------------------------------------------------------------------------|
83
+ | --------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | ---------------------------------------------------------------------------------------------------------------------------------------------------- |
81
84
  | `githubUrl` | The GitHub Enterprise endpoint. | `GH_URL` or `GITHUB_URL` environment variable. |
82
85
  | `githubApiPathPrefix` | The GitHub Enterprise API prefix. | `GH_PREFIX` or `GITHUB_PREFIX` environment variable. |
83
- | `proxy` | The proxy to use to access the GitHub API. Set to `false` to disable usage of proxy. See [proxy](#proxy). | `HTTP_PROXY` environment variable. |
86
+ | `proxy` | The proxy to use to access the GitHub API. Set to `false` to disable usage of proxy. See [proxy](#proxy). | `HTTP_PROXY` environment variable. |
84
87
  | `assets` | An array of files to upload to the release. See [assets](#assets). | - |
85
88
  | `successComment` | The comment to add to each issue and pull request resolved by the release. Set to `false` to disable commenting on issues and pull requests. See [successComment](#successcomment). | `:tada: This issue has been resolved in version ${nextRelease.version} :tada:\n\nThe release is available on [GitHub release](<github_release_url>)` |
86
89
  | `failComment` | The content of the issue created when a release fails. Set to `false` to disable opening an issue when a release fails. See [failComment](#failcomment). | Friendly message with links to **semantic-release** documentation and support, with the list of errors that caused the release to fail. |
87
90
  | `failTitle` | The title of the issue created when a release fails. Set to `false` to disable opening an issue when a release fails. | `The automated release is failing 🚨` |
88
91
  | `labels` | The [labels](https://help.github.com/articles/about-labels) to add to the issue created when a release fails. Set to `false` to not add any label. | `['semantic-release']` |
89
92
  | `assignees` | The [assignees](https://help.github.com/articles/assigning-issues-and-pull-requests-to-other-github-users) to add to the issue created when a release fails. | - |
90
- | `releasedLabels` | The [labels](https://help.github.com/articles/about-labels) to add to each issue and pull request resolved by the release. Set to `false` to not add any label. See [releasedLabels](#releasedlabels). | `['released<%= nextRelease.channel ? \` on @\${nextRelease.channel}\` : "" %>']- |
91
- | `addReleases` | Will add release links to the GitHub Release. Can be `false`, `"bottom"` or `"top"`. See [addReleases](#addReleases). | `false` |
92
- | `draftRelease` | A boolean indicating if a GitHub Draft Release should be created instead of publishing an actual GitHub Release. | `false` |
93
+ | `releasedLabels` | The [labels](https://help.github.com/articles/about-labels) to add to each issue and pull request resolved by the release. Set to `false` to not add any label. See [releasedLabels](#releasedlabels). | `['released<%= nextRelease.channel ? \` on @\${nextRelease.channel}\` : "" %>']- |
94
+ | `addReleases` | Will add release links to the GitHub Release. Can be `false`, `"bottom"` or `"top"`. See [addReleases](#addReleases). | `false` |
95
+ | `draftRelease` | A boolean indicating if a GitHub Draft Release should be created instead of publishing an actual GitHub Release. | `false` |
93
96
 
94
97
  #### proxy
95
98
 
96
99
  Can be `false`, a proxy URL or an `Object` with the following properties:
97
100
 
98
101
  | Property | Description | Default |
99
- |---------------|----------------------------------------------------------------|--------------------------------------|
102
+ | ------------- | -------------------------------------------------------------- | ------------------------------------ |
100
103
  | `host` | **Required.** Proxy host to connect to. | - |
101
104
  | `port` | **Required.** Proxy port to connect to. | File name extracted from the `path`. |
102
105
  | `secureProxy` | If `true`, then use TLS to connect to the proxy. | `false` |
@@ -129,7 +132,7 @@ If a directory is configured, all the files under this directory and its childre
129
132
  The `name` and `label` for each assets are generated with [Lodash template](https://lodash.com/docs#template). The following variables are available:
130
133
 
131
134
  | Parameter | Description |
132
- |---------------|-------------------------------------------------------------------------------------|
135
+ | ------------- | ----------------------------------------------------------------------------------- |
133
136
  | `branch` | The branch from which the release is done. |
134
137
  | `lastRelease` | `Object` with `version`, `gitTag` and `gitHead` of the last release. |
135
138
  | `nextRelease` | `Object` with `version`, `gitTag`, `gitHead` and `notes` of the release being done. |
@@ -144,9 +147,7 @@ The `name` and `label` for each assets are generated with [Lodash template](http
144
147
  `[['dist', '!**/*.css']]`: include all the files in the `dist` directory and its sub-directories excluding the `css`
145
148
  files.
146
149
 
147
- `[{path: 'dist/MyLibrary.js', label: 'MyLibrary JS distribution'}, {path: 'dist/MyLibrary.css', label: 'MyLibrary CSS
148
- distribution'}]`: include the `dist/MyLibrary.js` and `dist/MyLibrary.css` files, and label them `MyLibrary JS
149
- distribution` and `MyLibrary CSS distribution` in the GitHub release.
150
+ `[{path: 'dist/MyLibrary.js', label: 'MyLibrary JS distribution'}, {path: 'dist/MyLibrary.css', label: 'MyLibrary CSS distribution'}]`: include the `dist/MyLibrary.js` and `dist/MyLibrary.css` files, and label them `MyLibrary JS distribution` and `MyLibrary CSS distribution` in the GitHub release.
150
151
 
151
152
  `[['dist/**/*.{js,css}', '!**/*.min.*'], {path: 'build/MyLibrary.zip', label: 'MyLibrary'}]`: include all the `js` and
152
153
  `css` files in the `dist` directory and its sub-directories excluding the minified version, plus the
@@ -161,7 +162,7 @@ distribution` and `MyLibrary CSS distribution` in the GitHub release.
161
162
  The message for the issue comments is generated with [Lodash template](https://lodash.com/docs#template). The following variables are available:
162
163
 
163
164
  | Parameter | Description |
164
- |---------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
165
+ | ------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
165
166
  | `branch` | `Object` with `name`, `type`, `channel`, `range` and `prerelease` properties of the branch from which the release is done. |
166
167
  | `lastRelease` | `Object` with `version`, `channel`, `gitTag` and `gitHead` of the last release. |
167
168
  | `nextRelease` | `Object` with `version`, `channel`, `gitTag`, `gitHead` and `notes` of the release being done. |
@@ -180,7 +181,7 @@ The `successComment` `This ${issue.pull_request ? 'pull request' : 'issue'} is i
180
181
  The message for the issue content is generated with [Lodash template](https://lodash.com/docs#template). The following variables are available:
181
182
 
182
183
  | Parameter | Description |
183
- |-----------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
184
+ | --------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
184
185
  | `branch` | The branch from which the release had failed. |
185
186
  | `errors` | An `Array` of [SemanticReleaseError](https://github.com/semantic-release/error). Each error has the `message`, `code`, `pluginName` and `details` properties.<br>`pluginName` contains the package name of the plugin that threw the error.<br>`details` contains a information about the error formatted in markdown. |
186
187
 
@@ -189,6 +190,7 @@ The message for the issue content is generated with [Lodash template](https://lo
189
190
  The `failComment` `This release from branch ${branch.name} had failed due to the following errors:\n- ${errors.map(err => err.message).join('\\n- ')}` will generate the comment:
190
191
 
191
192
  > This release from branch master had failed due to the following errors:
193
+ >
192
194
  > - Error message 1
193
195
  > - Error message 2
194
196
 
@@ -197,7 +199,7 @@ The `failComment` `This release from branch ${branch.name} had failed due to the
197
199
  Each label name is generated with [Lodash template](https://lodash.com/docs#template). The following variables are available:
198
200
 
199
201
  | Parameter | Description |
200
- |---------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
202
+ | ------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
201
203
  | `branch` | `Object` with `name`, `type`, `channel`, `range` and `prerelease` properties of the branch from which the release is done. |
202
204
  | `lastRelease` | `Object` with `version`, `channel`, `gitTag` and `gitHead` of the last release. |
203
205
  | `nextRelease` | `Object` with `version`, `channel`, `gitTag`, `gitHead` and `notes` of the release being done. |
@@ -207,7 +209,7 @@ Each label name is generated with [Lodash template](https://lodash.com/docs#temp
207
209
 
208
210
  ##### releasedLabels example
209
211
 
210
- The `releasedLabels` ```['released<%= nextRelease.channel ? ` on @\${nextRelease.channel}` : "" %> from <%= branch.name %>']``` will generate the label:
212
+ The `releasedLabels` `` ['released<%= nextRelease.channel ? ` on @\${nextRelease.channel}` : "" %> from <%= branch.name %>'] `` will generate the label:
211
213
 
212
214
  > released on @next from branch next
213
215
 
package/index.js CHANGED
@@ -1,67 +1,101 @@
1
1
  /* eslint require-atomic-updates: off */
2
2
 
3
- const {defaultTo, castArray} = require('lodash');
4
- const verifyGitHub = require('./lib/verify');
5
- const addChannelGitHub = require('./lib/add-channel');
6
- const publishGitHub = require('./lib/publish');
7
- const successGitHub = require('./lib/success');
8
- const failGitHub = require('./lib/fail');
3
+ import { defaultTo, castArray } from "lodash-es";
4
+
5
+ import verifyGitHub from "./lib/verify.js";
6
+ import addChannelGitHub from "./lib/add-channel.js";
7
+ import publishGitHub from "./lib/publish.js";
8
+ import successGitHub from "./lib/success.js";
9
+ import failGitHub from "./lib/fail.js";
10
+ import { SemanticReleaseOctokit } from "./lib/octokit.js";
9
11
 
10
12
  let verified;
11
13
 
12
- async function verifyConditions(pluginConfig, context) {
13
- const {options} = context;
14
+ export async function verifyConditions(
15
+ pluginConfig,
16
+ context,
17
+ { Octokit = SemanticReleaseOctokit } = {}
18
+ ) {
19
+ const { options } = context;
14
20
  // If the GitHub publish plugin is used and has `assets`, `successComment`, `failComment`, `failTitle`, `labels` or `assignees` configured, validate it now in order to prevent any release if the configuration is wrong
15
21
  if (options.publish) {
16
22
  const publishPlugin =
17
- castArray(options.publish).find((config) => config.path && config.path === '@semantic-release/github') || {};
23
+ castArray(options.publish).find(
24
+ (config) => config.path && config.path === "@semantic-release/github"
25
+ ) || {};
18
26
 
19
27
  pluginConfig.assets = defaultTo(pluginConfig.assets, publishPlugin.assets);
20
- pluginConfig.successComment = defaultTo(pluginConfig.successComment, publishPlugin.successComment);
21
- pluginConfig.failComment = defaultTo(pluginConfig.failComment, publishPlugin.failComment);
22
- pluginConfig.failTitle = defaultTo(pluginConfig.failTitle, publishPlugin.failTitle);
28
+ pluginConfig.successComment = defaultTo(
29
+ pluginConfig.successComment,
30
+ publishPlugin.successComment
31
+ );
32
+ pluginConfig.failComment = defaultTo(
33
+ pluginConfig.failComment,
34
+ publishPlugin.failComment
35
+ );
36
+ pluginConfig.failTitle = defaultTo(
37
+ pluginConfig.failTitle,
38
+ publishPlugin.failTitle
39
+ );
23
40
  pluginConfig.labels = defaultTo(pluginConfig.labels, publishPlugin.labels);
24
- pluginConfig.assignees = defaultTo(pluginConfig.assignees, publishPlugin.assignees);
41
+ pluginConfig.assignees = defaultTo(
42
+ pluginConfig.assignees,
43
+ publishPlugin.assignees
44
+ );
25
45
  }
26
46
 
27
- await verifyGitHub(pluginConfig, context);
47
+ await verifyGitHub(pluginConfig, context, { Octokit });
28
48
  verified = true;
29
49
  }
30
50
 
31
- async function publish(pluginConfig, context) {
51
+ export async function publish(
52
+ pluginConfig,
53
+ context,
54
+ { Octokit = SemanticReleaseOctokit } = {}
55
+ ) {
32
56
  if (!verified) {
33
- await verifyGitHub(pluginConfig, context);
57
+ await verifyGitHub(pluginConfig, context, { Octokit });
34
58
  verified = true;
35
59
  }
36
60
 
37
- return publishGitHub(pluginConfig, context);
61
+ return publishGitHub(pluginConfig, context, { Octokit });
38
62
  }
39
63
 
40
- async function addChannel(pluginConfig, context) {
64
+ export async function addChannel(
65
+ pluginConfig,
66
+ context,
67
+ { Octokit = SemanticReleaseOctokit } = {}
68
+ ) {
41
69
  if (!verified) {
42
- await verifyGitHub(pluginConfig, context);
70
+ await verifyGitHub(pluginConfig, context, { Octokit });
43
71
  verified = true;
44
72
  }
45
73
 
46
- return addChannelGitHub(pluginConfig, context);
74
+ return addChannelGitHub(pluginConfig, context, { Octokit });
47
75
  }
48
76
 
49
- async function success(pluginConfig, context) {
77
+ export async function success(
78
+ pluginConfig,
79
+ context,
80
+ { Octokit = SemanticReleaseOctokit } = {}
81
+ ) {
50
82
  if (!verified) {
51
- await verifyGitHub(pluginConfig, context);
83
+ await verifyGitHub(pluginConfig, context, { Octokit });
52
84
  verified = true;
53
85
  }
54
86
 
55
- await successGitHub(pluginConfig, context);
87
+ await successGitHub(pluginConfig, context, { Octokit });
56
88
  }
57
89
 
58
- async function fail(pluginConfig, context) {
90
+ export async function fail(
91
+ pluginConfig,
92
+ context,
93
+ { Octokit = SemanticReleaseOctokit } = {}
94
+ ) {
59
95
  if (!verified) {
60
- await verifyGitHub(pluginConfig, context);
96
+ await verifyGitHub(pluginConfig, context, { Octokit });
61
97
  verified = true;
62
98
  }
63
99
 
64
- await failGitHub(pluginConfig, context);
100
+ await failGitHub(pluginConfig, context, { Octokit });
65
101
  }
66
-
67
- module.exports = {verifyConditions, addChannel, publish, success, fail};
@@ -1,52 +1,81 @@
1
- const debug = require('debug')('semantic-release:github');
2
- const {RELEASE_NAME} = require('./definitions/constants');
3
- const parseGithubUrl = require('./parse-github-url');
4
- const resolveConfig = require('./resolve-config');
5
- const getClient = require('./get-client');
6
- const isPrerelease = require('./is-prerelease');
7
-
8
- module.exports = async (pluginConfig, context) => {
1
+ import debugFactory from "debug";
2
+
3
+ import { RELEASE_NAME } from "./definitions/constants.js";
4
+ import parseGithubUrl from "./parse-github-url.js";
5
+ import resolveConfig from "./resolve-config.js";
6
+ import isPrerelease from "./is-prerelease.js";
7
+ import { toOctokitOptions } from "./octokit.js";
8
+
9
+ const debug = debugFactory("semantic-release:github");
10
+
11
+ export default async function addChannel(pluginConfig, context, { Octokit }) {
9
12
  const {
10
- options: {repositoryUrl},
13
+ options: { repositoryUrl },
11
14
  branch,
12
- nextRelease: {name, gitTag, notes},
15
+ nextRelease: { name, gitTag, notes },
13
16
  logger,
14
17
  } = context;
15
- const {githubToken, githubUrl, githubApiPathPrefix, proxy} = resolveConfig(pluginConfig, context);
16
- const {owner, repo} = parseGithubUrl(repositoryUrl);
17
- const octokit = getClient({githubToken, githubUrl, githubApiPathPrefix, proxy});
18
+ const { githubToken, githubUrl, githubApiPathPrefix, proxy } = resolveConfig(
19
+ pluginConfig,
20
+ context
21
+ );
22
+ const { owner, repo } = parseGithubUrl(repositoryUrl);
23
+ const octokit = new Octokit(
24
+ toOctokitOptions({
25
+ githubToken,
26
+ githubUrl,
27
+ githubApiPathPrefix,
28
+ proxy,
29
+ })
30
+ );
18
31
  let releaseId;
19
32
 
20
- const release = {owner, repo, name, prerelease: isPrerelease(branch), tag_name: gitTag};
33
+ const release = {
34
+ owner,
35
+ repo,
36
+ name,
37
+ prerelease: isPrerelease(branch),
38
+ tag_name: gitTag,
39
+ };
21
40
 
22
- debug('release object: %O', release);
41
+ debug("release object: %O", release);
23
42
 
24
43
  try {
25
44
  ({
26
- data: {id: releaseId},
27
- } = await octokit.request('GET /repos/{owner}/{repo}/releases/tags/{tag}', {owner, repo, tag: gitTag}));
45
+ data: { id: releaseId },
46
+ } = await octokit.request("GET /repos/{owner}/{repo}/releases/tags/{tag}", {
47
+ owner,
48
+ repo,
49
+ tag: gitTag,
50
+ }));
28
51
  } catch (error) {
29
52
  if (error.status === 404) {
30
- logger.log('There is no release for tag %s, creating a new one', gitTag);
53
+ logger.log("There is no release for tag %s, creating a new one", gitTag);
31
54
 
32
55
  const {
33
- data: {html_url: url},
34
- } = await octokit.request('POST /repos/{owner}/{repo}/releases', {...release, body: notes});
56
+ data: { html_url: url },
57
+ } = await octokit.request("POST /repos/{owner}/{repo}/releases", {
58
+ ...release,
59
+ body: notes,
60
+ });
35
61
 
36
- logger.log('Published GitHub release: %s', url);
37
- return {url, name: RELEASE_NAME};
62
+ logger.log("Published GitHub release: %s", url);
63
+ return { url, name: RELEASE_NAME };
38
64
  }
39
65
 
40
66
  throw error;
41
67
  }
42
68
 
43
- debug('release release_id: %o', releaseId);
69
+ debug("release release_id: %o", releaseId);
44
70
 
45
71
  const {
46
- data: {html_url: url},
47
- } = await octokit.request('PATCH /repos/{owner}/{repo}/releases/{release_id}', {...release, release_id: releaseId});
72
+ data: { html_url: url },
73
+ } = await octokit.request(
74
+ "PATCH /repos/{owner}/{repo}/releases/{release_id}",
75
+ { ...release, release_id: releaseId }
76
+ );
48
77
 
49
- logger.log('Updated GitHub release: %s', url);
78
+ logger.log("Updated GitHub release: %s", url);
50
79
 
51
- return {url, name: RELEASE_NAME};
52
- };
80
+ return { url, name: RELEASE_NAME };
81
+ }
@@ -1,5 +1,3 @@
1
- const ISSUE_ID = '<!-- semantic-release:github -->';
1
+ export const ISSUE_ID = "<!-- semantic-release:github -->";
2
2
 
3
- const RELEASE_NAME = 'GitHub release';
4
-
5
- module.exports = {ISSUE_ID, RELEASE_NAME};
3
+ export const RELEASE_NAME = "GitHub release";