@semantic-release/github 8.0.9 → 9.0.0-beta.1

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,34 +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` |
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` |
92
96
 
93
97
  #### proxy
94
98
 
95
99
  Can be `false`, a proxy URL or an `Object` with the following properties:
96
100
 
97
101
  | Property | Description | Default |
98
- |---------------|----------------------------------------------------------------|--------------------------------------|
102
+ | ------------- | -------------------------------------------------------------- | ------------------------------------ |
99
103
  | `host` | **Required.** Proxy host to connect to. | - |
100
104
  | `port` | **Required.** Proxy port to connect to. | File name extracted from the `path`. |
101
105
  | `secureProxy` | If `true`, then use TLS to connect to the proxy. | `false` |
@@ -128,7 +132,7 @@ If a directory is configured, all the files under this directory and its childre
128
132
  The `name` and `label` for each assets are generated with [Lodash template](https://lodash.com/docs#template). The following variables are available:
129
133
 
130
134
  | Parameter | Description |
131
- |---------------|-------------------------------------------------------------------------------------|
135
+ | ------------- | ----------------------------------------------------------------------------------- |
132
136
  | `branch` | The branch from which the release is done. |
133
137
  | `lastRelease` | `Object` with `version`, `gitTag` and `gitHead` of the last release. |
134
138
  | `nextRelease` | `Object` with `version`, `gitTag`, `gitHead` and `notes` of the release being done. |
@@ -143,9 +147,7 @@ The `name` and `label` for each assets are generated with [Lodash template](http
143
147
  `[['dist', '!**/*.css']]`: include all the files in the `dist` directory and its sub-directories excluding the `css`
144
148
  files.
145
149
 
146
- `[{path: 'dist/MyLibrary.js', label: 'MyLibrary JS distribution'}, {path: 'dist/MyLibrary.css', label: 'MyLibrary CSS
147
- distribution'}]`: include the `dist/MyLibrary.js` and `dist/MyLibrary.css` files, and label them `MyLibrary JS
148
- 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.
149
151
 
150
152
  `[['dist/**/*.{js,css}', '!**/*.min.*'], {path: 'build/MyLibrary.zip', label: 'MyLibrary'}]`: include all the `js` and
151
153
  `css` files in the `dist` directory and its sub-directories excluding the minified version, plus the
@@ -160,7 +162,7 @@ distribution` and `MyLibrary CSS distribution` in the GitHub release.
160
162
  The message for the issue comments is generated with [Lodash template](https://lodash.com/docs#template). The following variables are available:
161
163
 
162
164
  | Parameter | Description |
163
- |---------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
165
+ | ------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
164
166
  | `branch` | `Object` with `name`, `type`, `channel`, `range` and `prerelease` properties of the branch from which the release is done. |
165
167
  | `lastRelease` | `Object` with `version`, `channel`, `gitTag` and `gitHead` of the last release. |
166
168
  | `nextRelease` | `Object` with `version`, `channel`, `gitTag`, `gitHead` and `notes` of the release being done. |
@@ -179,7 +181,7 @@ The `successComment` `This ${issue.pull_request ? 'pull request' : 'issue'} is i
179
181
  The message for the issue content is generated with [Lodash template](https://lodash.com/docs#template). The following variables are available:
180
182
 
181
183
  | Parameter | Description |
182
- |-----------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
184
+ | --------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
183
185
  | `branch` | The branch from which the release had failed. |
184
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. |
185
187
 
@@ -188,6 +190,7 @@ The message for the issue content is generated with [Lodash template](https://lo
188
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:
189
191
 
190
192
  > This release from branch master had failed due to the following errors:
193
+ >
191
194
  > - Error message 1
192
195
  > - Error message 2
193
196
 
@@ -196,7 +199,7 @@ The `failComment` `This release from branch ${branch.name} had failed due to the
196
199
  Each label name is generated with [Lodash template](https://lodash.com/docs#template). The following variables are available:
197
200
 
198
201
  | Parameter | Description |
199
- |---------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
202
+ | ------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
200
203
  | `branch` | `Object` with `name`, `type`, `channel`, `range` and `prerelease` properties of the branch from which the release is done. |
201
204
  | `lastRelease` | `Object` with `version`, `channel`, `gitTag` and `gitHead` of the last release. |
202
205
  | `nextRelease` | `Object` with `version`, `channel`, `gitTag`, `gitHead` and `notes` of the release being done. |
@@ -206,7 +209,7 @@ Each label name is generated with [Lodash template](https://lodash.com/docs#temp
206
209
 
207
210
  ##### releasedLabels example
208
211
 
209
- 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:
210
213
 
211
214
  > released on @next from branch next
212
215
 
@@ -218,4 +221,4 @@ Valid values for this option are `false`, `"top"` or `"bottom"`.
218
221
 
219
222
  ##### addReleases example
220
223
 
221
- See [The introducing PR](https://github.com/semantic-release/github/pull/282) for an example on how it will look.
224
+ See [The introducing PR](https://github.com/semantic-release/github/pull/282) for an example on how it will look.
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, SemanticReleaseOctokit } 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";