Skip to content

Commit a946687

Browse files
committed
WIP convert to import
1 parent d41f112 commit a946687

37 files changed

+700
-893
lines changed

index.js

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
/* eslint require-atomic-updates: off */
22

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';
4+
5+
import verifyGitHub from './lib/verify';
6+
import addChannelGitHub from './lib/add-channel';
7+
import publishGitHub from './lib/publish';
8+
import successGitHub from './lib/success';
9+
import failGitHub from './lib/fail';
910

1011
let verified;
1112

@@ -64,4 +65,4 @@ async function fail(pluginConfig, context) {
6465
await failGitHub(pluginConfig, context);
6566
}
6667

67-
module.exports = {verifyConditions, addChannel, publish, success, fail};
68+
export default {verifyConditions, addChannel, publish, success, fail};

lib/add-channel.js

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
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+
import {RELEASE_NAME} from './definitions/constants';
3+
import parseGithubUrl from './parse-github-url';
4+
import resolveConfig from './resolve-config';
5+
import getClient from './get-client';
6+
import isPrerelease from './is-prerelease';
7+
8+
const debug = debugFactory('semantic-release:github');
9+
10+
export default async (pluginConfig, context) => {
911
const {
1012
options: {repositoryUrl},
1113
branch,

lib/definitions/constants.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@ const ISSUE_ID = '<!-- semantic-release:github -->';
22

33
const RELEASE_NAME = 'GitHub release';
44

5-
module.exports = {ISSUE_ID, RELEASE_NAME};
5+
export default {ISSUE_ID, RELEASE_NAME};

lib/definitions/errors.js

Lines changed: 75 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,84 +1,115 @@
1-
const {inspect} = require('util');
2-
const {isString} = require('lodash');
3-
const pkg = require('../../package.json');
1+
import {inspect} from 'node:util';
2+
3+
import {isString} from 'lodash';
4+
5+
const HOMEPAGE = 'https://github.com/semantic-release/github#readme';
46

5-
const [homepage] = pkg.homepage.split('#');
67
const stringify = (object) =>
78
isString(object) ? object : inspect(object, {breakLength: Infinity, depth: 2, maxArrayLength: 5});
8-
const linkify = (file) => `${homepage}/blob/master/${file}`;
9+
const linkify = (file) => `${HOMEPAGE}/blob/master/${file}`;
910

10-
module.exports = {
11-
EINVALIDASSETS: ({assets}) => ({
11+
export function EINVALIDASSETS({assets}) {
12+
return {
1213
message: 'Invalid `assets` option.',
1314
details: `The [assets option](${linkify(
1415
'README.md#assets'
1516
)}) must be an \`Array\` of \`Strings\` or \`Objects\` with a \`path\` property.
1617
1718
Your configuration for the \`assets\` option is \`${stringify(assets)}\`.`,
18-
}),
19-
EINVALIDSUCCESSCOMMENT: ({successComment}) => ({
19+
};
20+
}
21+
22+
export function EINVALIDSUCCESSCOMMENT({successComment}) {
23+
return {
2024
message: 'Invalid `successComment` option.',
2125
details: `The [successComment option](${linkify(
2226
'README.md#successcomment'
2327
)}) if defined, must be a non empty \`String\`.
2428
2529
Your configuration for the \`successComment\` option is \`${stringify(successComment)}\`.`,
26-
}),
27-
EINVALIDFAILTITLE: ({failTitle}) => ({
30+
};
31+
}
32+
33+
export function EINVALIDFAILTITLE({failTitle}) {
34+
return {
2835
message: 'Invalid `failTitle` option.',
2936
details: `The [failTitle option](${linkify('README.md#failtitle')}) if defined, must be a non empty \`String\`.
3037
3138
Your configuration for the \`failTitle\` option is \`${stringify(failTitle)}\`.`,
32-
}),
33-
EINVALIDFAILCOMMENT: ({failComment}) => ({
39+
};
40+
}
41+
42+
export function EINVALIDFAILCOMMENT({failComment}) {
43+
return {
3444
message: 'Invalid `failComment` option.',
3545
details: `The [failComment option](${linkify('README.md#failcomment')}) if defined, must be a non empty \`String\`.
3646
3747
Your configuration for the \`failComment\` option is \`${stringify(failComment)}\`.`,
38-
}),
39-
EINVALIDLABELS: ({labels}) => ({
48+
};
49+
}
50+
51+
export function EINVALIDLABELS({labels}) {
52+
return {
4053
message: 'Invalid `labels` option.',
4154
details: `The [labels option](${linkify(
4255
'README.md#options'
4356
)}) if defined, must be an \`Array\` of non empty \`String\`.
4457
4558
Your configuration for the \`labels\` option is \`${stringify(labels)}\`.`,
46-
}),
47-
EINVALIDASSIGNEES: ({assignees}) => ({
59+
};
60+
}
61+
62+
export function EINVALIDASSIGNEES({assignees}) {
63+
return {
4864
message: 'Invalid `assignees` option.',
4965
details: `The [assignees option](${linkify('README.md#options')}) must be an \`Array\` of non empty \`Strings\`.
5066
5167
Your configuration for the \`assignees\` option is \`${stringify(assignees)}\`.`,
52-
}),
53-
EINVALIDRELEASEDLABELS: ({releasedLabels}) => ({
68+
};
69+
}
70+
71+
export function EINVALIDRELEASEDLABELS({releasedLabels}) {
72+
return {
5473
message: 'Invalid `releasedLabels` option.',
5574
details: `The [releasedLabels option](${linkify(
5675
'README.md#options'
5776
)}) if defined, must be an \`Array\` of non empty \`String\`.
5877
5978
Your configuration for the \`releasedLabels\` option is \`${stringify(releasedLabels)}\`.`,
60-
}),
61-
EINVALIDADDRELEASES: ({addReleases}) => ({
79+
};
80+
}
81+
82+
export function EINVALIDADDRELEASES({addReleases}) {
83+
return {
6284
message: 'Invalid `addReleases` option.',
6385
details: `The [addReleases option](${linkify('README.md#options')}) if defined, must be one of \`false|top|bottom\`.
6486
6587
Your configuration for the \`addReleases\` option is \`${stringify(addReleases)}\`.`,
66-
}),
67-
EINVALIDGITHUBURL: () => ({
88+
};
89+
}
90+
91+
export function EINVALIDGITHUBURL() {
92+
return {
6893
message: 'The git repository URL is not a valid GitHub URL.',
6994
details: `The **semantic-release** \`repositoryUrl\` option must a valid GitHub URL with the format \`<GitHub_or_GHE_URL>/<owner>/<repo>.git\`.
7095
7196
By default the \`repositoryUrl\` option is retrieved from the \`repository\` property of your \`package.json\` or the [git origin url](https://git-scm.com/book/en/v2/Git-Basics-Working-with-Remotes) of the repository cloned by your CI environment.`,
72-
}),
73-
EINVALIDPROXY: ({proxy}) => ({
97+
};
98+
}
99+
100+
export function EINVALIDPROXY({proxy}) {
101+
return {
74102
message: 'Invalid `proxy` option.',
75103
details: `The [proxy option](${linkify(
76104
'README.md#proxy'
77105
)}) must be a \`String\` or an \`Objects\` with a \`host\` and a \`port\` property.
78106
79107
Your configuration for the \`proxy\` option is \`${stringify(proxy)}\`.`,
80-
}),
81-
EMISSINGREPO: ({owner, repo}) => ({
108+
};
109+
}
110+
111+
export function EMISSINGREPO({owner, repo}) {
112+
return {
82113
message: `The repository ${owner}/${repo} doesn't exist.`,
83114
details: `The **semantic-release** \`repositoryUrl\` option must refer to your GitHub repository. The repository must be accessible with the [GitHub API](https://developer.github.com/v3).
84115
@@ -87,29 +118,38 @@ By default the \`repositoryUrl\` option is retrieved from the \`repository\` pro
87118
If you are using [GitHub Enterprise](https://enterprise.github.com) please make sure to configure the \`githubUrl\` and \`githubApiPathPrefix\` [options](${linkify(
88119
'README.md#options'
89120
)}).`,
90-
}),
91-
EGHNOPERMISSION: ({owner, repo}) => ({
121+
};
122+
}
123+
124+
export function EGHNOPERMISSION({owner, repo}) {
125+
return {
92126
message: `The GitHub token doesn't allow to push on the repository ${owner}/${repo}.`,
93127
details: `The user associated with the [GitHub token](${linkify(
94128
'README.md#github-authentication'
95129
)}) configured in the \`GH_TOKEN\` or \`GITHUB_TOKEN\` environment variable must allows to push to the repository ${owner}/${repo}.
96130
97131
Please make sure the GitHub user associated with the token is an [owner](https://help.github.com/articles/permission-levels-for-a-user-account-repository/#owner-access-on-a-repository-owned-by-a-user-account) or a [collaborator](https://help.github.com/articles/permission-levels-for-a-user-account-repository/#collaborator-access-on-a-repository-owned-by-a-user-account) if the reposotory belong to a user account or has [write permissions](https://help.github.com/articles/managing-team-access-to-an-organization-repository) if the repository [belongs to an organization](https://help.github.com/articles/repository-permission-levels-for-an-organization).`,
98-
}),
99-
EINVALIDGHTOKEN: ({owner, repo}) => ({
132+
};
133+
}
134+
135+
export function EINVALIDGHTOKEN({owner, repo}) {
136+
return {
100137
message: 'Invalid GitHub token.',
101138
details: `The [GitHub token](${linkify(
102139
'README.md#github-authentication'
103140
)}) configured in the \`GH_TOKEN\` or \`GITHUB_TOKEN\` environment variable must be a valid [personal token](https://help.github.com/articles/creating-a-personal-access-token-for-the-command-line) allowing to push to the repository ${owner}/${repo}.
104141
105142
Please make sure to set the \`GH_TOKEN\` or \`GITHUB_TOKEN\` environment variable in your CI with the exact value of the GitHub personal token.`,
106-
}),
107-
ENOGHTOKEN: ({owner, repo}) => ({
143+
};
144+
}
145+
146+
export function ENOGHTOKEN({owner, repo}) {
147+
return {
108148
message: 'No GitHub token specified.',
109149
details: `A [GitHub personal token](${linkify(
110150
'README.md#github-authentication'
111151
)}) must be created and set in the \`GH_TOKEN\` or \`GITHUB_TOKEN\` environment variable on your CI environment.
112152
113153
Please make sure to create a [GitHub personal token](https://help.github.com/articles/creating-a-personal-access-token-for-the-command-line) and to set it in the \`GH_TOKEN\` or \`GITHUB_TOKEN\` environment variable on your CI environment. The token must allow to push to the repository ${owner}/${repo}.`,
114-
}),
115-
};
154+
};
155+
}

lib/definitions/rate-limit.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,4 @@ const RATE_LIMITS = {
2424
*/
2525
const GLOBAL_RATE_LIMIT = 1000;
2626

27-
module.exports = {RETRY_CONF, RATE_LIMITS, GLOBAL_RATE_LIMIT};
27+
export default {RETRY_CONF, RATE_LIMITS, GLOBAL_RATE_LIMIT};

lib/fail.js

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
1-
const {template} = require('lodash');
2-
const debug = require('debug')('semantic-release:github');
3-
const parseGithubUrl = require('./parse-github-url');
4-
const {ISSUE_ID} = require('./definitions/constants');
5-
const resolveConfig = require('./resolve-config');
6-
const getClient = require('./get-client');
7-
const findSRIssues = require('./find-sr-issues');
8-
const getFailComment = require('./get-fail-comment');
1+
import {template} from 'lodash';
2+
import debugFactory from 'debug';
3+
import parseGithubUrl from './parse-github-url';
4+
import {ISSUE_ID} from './definitions/constants';
5+
import resolveConfig from './resolve-config';
6+
import getClient from './get-client';
7+
import findSRIssues from './find-sr-issues';
8+
import getFailComment from './get-fail-comment';
99

10-
module.exports = async (pluginConfig, context) => {
10+
const debug = debugFactory('semantic-release:github');
11+
12+
export default async (pluginConfig, context) => {
1113
const {
1214
options: {repositoryUrl},
1315
branch,

lib/find-sr-issues.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
const {ISSUE_ID} = require('./definitions/constants');
1+
import {ISSUE_ID} from './definitions/constants';
22

3-
module.exports = async (github, title, owner, repo) => {
3+
export default async (github, title, owner, repo) => {
44
const {
55
data: {items: issues},
66
} = await github.search.issuesAndPullRequests({

lib/get-client.js

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
const {memoize, get} = require('lodash');
2-
const {Octokit} = require('@octokit/rest');
3-
const pRetry = require('p-retry');
4-
const Bottleneck = require('bottleneck');
5-
const urljoin = require('url-join');
6-
const HttpProxyAgent = require('http-proxy-agent');
7-
const HttpsProxyAgent = require('https-proxy-agent');
1+
import {memoize, get} from 'lodash';
2+
import {Octokit} from '@octokit/rest';
3+
import pRetry, {AbortError} from 'p-retry';
4+
import Bottleneck from 'bottleneck';
5+
import urljoin from 'url-join';
6+
import HttpProxyAgent from 'http-proxy-agent';
7+
import HttpsProxyAgent from 'https-proxy-agent';
88

9-
const {RETRY_CONF, RATE_LIMITS, GLOBAL_RATE_LIMIT} = require('./definitions/rate-limit');
9+
import {RETRY_CONF, RATE_LIMITS, GLOBAL_RATE_LIMIT} from './definitions/rate-limit';
1010

1111
/**
1212
* Http error status for which to not retry.
@@ -26,7 +26,7 @@ const getThrottler = memoize((rate, globalThrottler) =>
2626
new Bottleneck({minTime: get(RATE_LIMITS, rate)}).chain(globalThrottler)
2727
);
2828

29-
module.exports = ({githubToken, githubUrl, githubApiPathPrefix, proxy}) => {
29+
export default ({githubToken, githubUrl, githubApiPathPrefix, proxy}) => {
3030
const baseUrl = githubUrl && urljoin(githubUrl, githubApiPathPrefix);
3131
const globalThrottler = new Bottleneck({minTime: GLOBAL_RATE_LIMIT});
3232
const github = new Octokit({
@@ -51,7 +51,7 @@ module.exports = ({githubToken, githubUrl, githubApiPathPrefix, proxy}) => {
5151
return await getThrottler(limitKey, globalThrottler).wrap(request)(options);
5252
} catch (error) {
5353
if (SKIP_RETRY_CODES.has(error.status)) {
54-
throw new pRetry.AbortError(error);
54+
throw new AbortError(error);
5555
}
5656

5757
throw error;

lib/get-error.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1-
const SemanticReleaseError = require('@semantic-release/error');
2-
const ERROR_DEFINITIONS = require('./definitions/errors');
1+
import SemanticReleaseError from '@semantic-release/error';
32

4-
module.exports = (code, ctx = {}) => {
3+
import * as ERROR_DEFINITIONS from './definitions/errors';
4+
5+
export default (code, ctx = {}) => {
56
const {message, details} = ERROR_DEFINITIONS[code](ctx);
67
return new SemanticReleaseError(message, code, details);
78
};

lib/get-fail-comment.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ ${
1515
}`
1616
}`;
1717

18-
module.exports = (branch, errors) => `## :rotating_light: The automated release from the \`${
18+
export default (branch, errors) => `## :rotating_light: The automated release from the \`${
1919
branch.name
2020
}\` branch failed. :rotating_light:
2121

0 commit comments

Comments
 (0)