Skip to content

Commit 8cb068a

Browse files
committed
style: xo
1 parent a946687 commit 8cb068a

37 files changed

+1092
-1734
lines changed

index.js

+8-6
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
22

33
import {defaultTo, castArray} from 'lodash';
44

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';
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';
1010

1111
let verified;
1212

@@ -65,4 +65,6 @@ async function fail(pluginConfig, context) {
6565
await failGitHub(pluginConfig, context);
6666
}
6767

68-
export default {verifyConditions, addChannel, publish, success, fail};
68+
const plugin = {verifyConditions, addChannel, publish, success, fail};
69+
70+
export default plugin;

lib/add-channel.js

+8-7
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
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';
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 getClient from './get-client.js';
7+
import isPrerelease from './is-prerelease.js';
78

89
const debug = debugFactory('semantic-release:github');
910

10-
export default async (pluginConfig, context) => {
11+
export default async function addChannel(pluginConfig, context) {
1112
const {
1213
options: {repositoryUrl},
1314
branch,
@@ -51,4 +52,4 @@ export default async (pluginConfig, context) => {
5152
logger.log('Updated GitHub release: %s', url);
5253

5354
return {url, name: RELEASE_NAME};
54-
};
55+
}

lib/definitions/constants.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,6 @@ const ISSUE_ID = '<!-- semantic-release:github -->';
22

33
const RELEASE_NAME = 'GitHub release';
44

5-
export default {ISSUE_ID, RELEASE_NAME};
5+
const CONSTANTS = {ISSUE_ID, RELEASE_NAME};
6+
7+
export default CONSTANTS;

lib/definitions/errors.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import {isString} from 'lodash';
55
const HOMEPAGE = 'https://github.com/semantic-release/github#readme';
66

77
const stringify = (object) =>
8-
isString(object) ? object : inspect(object, {breakLength: Infinity, depth: 2, maxArrayLength: 5});
8+
isString(object) ? object : inspect(object, {breakLength: Number.POSITIVE_INFINITY, depth: 2, maxArrayLength: 5});
99
const linkify = (file) => `${HOMEPAGE}/blob/master/${file}`;
1010

1111
export function EINVALIDASSETS({assets}) {

lib/definitions/rate-limit.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,6 @@ const RATE_LIMITS = {
2424
*/
2525
const GLOBAL_RATE_LIMIT = 1000;
2626

27-
export default {RETRY_CONF, RATE_LIMITS, GLOBAL_RATE_LIMIT};
27+
const RATE_LIMIT = {RETRY_CONF, RATE_LIMITS, GLOBAL_RATE_LIMIT};
28+
29+
export default RATE_LIMIT;

lib/fail.js

+17-9
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
11
import {template} from 'lodash';
22
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';
3+
4+
import parseGithubUrl from './parse-github-url.js';
5+
import {ISSUE_ID} from './definitions/constants.js';
6+
import resolveConfig from './resolve-config.js';
7+
import getClient from './get-client.js';
8+
import findSRIssues from './find-sr-issues.js';
9+
import getFailComment from './get-fail-comment.js';
910

1011
const debug = debugFactory('semantic-release:github');
1112

12-
export default async (pluginConfig, context) => {
13+
export default async function fail(pluginConfig, context) {
1314
const {
1415
options: {repositoryUrl},
1516
branch,
@@ -39,12 +40,19 @@ export default async (pluginConfig, context) => {
3940
} = await github.issues.createComment(comment);
4041
logger.log('Added comment to issue #%d: %s.', srIssue.number, url);
4142
} else {
42-
const newIssue = {owner, repo, title: failTitle, body: `${body}\n\n${ISSUE_ID}`, labels: labels || [], assignees};
43+
const newIssue = {
44+
owner,
45+
repo,
46+
title: failTitle,
47+
body: `${body}\n\n${ISSUE_ID}`,
48+
labels: labels || [],
49+
assignees,
50+
};
4351
debug('create issue: %O', newIssue);
4452
const {
4553
data: {html_url: url, number},
4654
} = await github.issues.create(newIssue);
4755
logger.log('Created issue #%d: %s.', number, url);
4856
}
4957
}
50-
};
58+
}

lib/find-sr-issues.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
import {ISSUE_ID} from './definitions/constants';
1+
import {ISSUE_ID} from './definitions/constants.js';
22

3-
export default async (github, title, owner, repo) => {
3+
export default async function findIssues(github, title, owner, repo) {
44
const {
55
data: {items: issues},
66
} = await github.search.issuesAndPullRequests({
77
q: `in:title+repo:${owner}/${repo}+type:issue+state:open+${title}`,
88
});
99

1010
return issues.filter((issue) => issue.body && issue.body.includes(ISSUE_ID));
11-
};
11+
}

lib/get-client.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import urljoin from 'url-join';
66
import HttpProxyAgent from 'http-proxy-agent';
77
import HttpsProxyAgent from 'https-proxy-agent';
88

9-
import {RETRY_CONF, RATE_LIMITS, GLOBAL_RATE_LIMIT} from './definitions/rate-limit';
9+
import {RETRY_CONF, RATE_LIMITS, GLOBAL_RATE_LIMIT} from './definitions/rate-limit.js';
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-
export default ({githubToken, githubUrl, githubApiPathPrefix, proxy}) => {
29+
export default function getClient({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({
@@ -60,4 +60,4 @@ export default ({githubToken, githubUrl, githubApiPathPrefix, proxy}) => {
6060
});
6161

6262
return github;
63-
};
63+
}

lib/get-error.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import SemanticReleaseError from '@semantic-release/error';
22

3-
import * as ERROR_DEFINITIONS from './definitions/errors';
3+
import * as ERROR_DEFINITIONS from './definitions/errors.js';
44

5-
export default (code, ctx = {}) => {
5+
export default function getError(code, ctx = {}) {
66
const {message, details} = ERROR_DEFINITIONS[code](ctx);
77
return new SemanticReleaseError(message, code, details);
8-
};
8+
}

lib/get-fail-comment.js

+5-5
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,8 @@ ${
1515
}`
1616
}`;
1717

18-
export default (branch, errors) => `## :rotating_light: The automated release from the \`${
19-
branch.name
20-
}\` branch failed. :rotating_light:
18+
export default function getFailComment(branch, errors) {
19+
return `## :rotating_light: The automated release from the \`${branch.name}\` branch failed. :rotating_light:
2120
2221
I recommend you give this issue a high priority, so other packages depending on you can benefit from your bug fixes and new features again.
2322
@@ -26,8 +25,8 @@ You can find below the list of errors reported by **semantic-release**. Each one
2625
Errors are usually caused by a misconfiguration or an authentication problem. With each error reported below you will find explanation and guidance to help you to resolve it.
2726
2827
Once all the errors are resolved, **semantic-release** will release your package the next time you push a commit to the \`${
29-
branch.name
30-
}\` branch. You can also manually restart the failed CI job that runs **semantic-release**.
28+
branch.name
29+
}\` branch. You can also manually restart the failed CI job that runs **semantic-release**.
3130
3231
If you are not sure how to resolve this, here are some links that can help you:
3332
- [Usage documentation](${USAGE_DOC_URL})
@@ -45,3 +44,4 @@ ${errors.map((error) => formatError(error)).join('\n\n---\n\n')}
4544
Good luck with your project ✨
4645
4746
Your **[semantic-release](${HOME_URL})** bot :package::rocket:`;
47+
}

lib/get-release-links.js

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import {RELEASE_NAME} from './definitions/constants';
1+
import {RELEASE_NAME} from './definitions/constants.js';
22

33
const linkify = (releaseInfo) =>
44
`${
@@ -12,11 +12,12 @@ const linkify = (releaseInfo) =>
1212
const filterReleases = (releaseInfos) =>
1313
releaseInfos.filter((releaseInfo) => releaseInfo.name && releaseInfo.name !== RELEASE_NAME);
1414

15-
export default (releaseInfos) =>
16-
`${
15+
export default function getReleaseLinks(releaseInfos) {
16+
return `${
1717
filterReleases(releaseInfos).length > 0
1818
? `This release is also available on:\n${filterReleases(releaseInfos)
1919
.map((releaseInfo) => `- ${linkify(releaseInfo)}`)
2020
.join('\n')}`
2121
: ''
2222
}`;
23+
}

lib/get-search-queries.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
export default (base, commits, separator = '+') => {
1+
export default function getSearchQueries(base, commits, separator = '+') {
22
return commits.reduce((searches, commit) => {
33
const lastSearch = searches[searches.length - 1];
44

@@ -10,4 +10,4 @@ export default (base, commits, separator = '+') => {
1010

1111
return searches;
1212
}, []);
13-
};
13+
}

lib/get-success-comment.js

+3-2
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ const HOME_URL = 'https://github.com/semantic-release/semantic-release';
22
const linkify = (releaseInfo) =>
33
`${releaseInfo.url ? `[${releaseInfo.name}](${releaseInfo.url})` : `\`${releaseInfo.name}\``}`;
44

5-
export default (issue, releaseInfos, nextRelease) =>
6-
`:tada: This ${issue.pull_request ? 'PR is included' : 'issue has been resolved'} in version ${
5+
export default function getSuccessComment(issue, releaseInfos, nextRelease) {
6+
return `:tada: This ${issue.pull_request ? 'PR is included' : 'issue has been resolved'} in version ${
77
nextRelease.version
88
} :tada:${
99
releaseInfos.length > 0
@@ -16,3 +16,4 @@ export default (issue, releaseInfos, nextRelease) =>
1616
}
1717
1818
Your **[semantic-release](${HOME_URL})** bot :package::rocket:`;
19+
}

lib/glob-assets.js

+48-47
Original file line numberDiff line numberDiff line change
@@ -7,62 +7,63 @@ import debugFactory from 'debug';
77

88
const debug = debugFactory('semantic-release:github');
99

10-
export default async ({cwd}, assets) =>
11-
uniqWith(
12-
[]
13-
.concat(
14-
...(await Promise.all(
15-
assets.map(async (asset) => {
16-
// Wrap single glob definition in Array
17-
let glob = castArray(isPlainObject(asset) ? asset.path : asset);
18-
// TODO Temporary workaround for https://github.com/mrmlnc/fast-glob/issues/47
19-
glob = uniq([...(await dirGlob(glob, {cwd})), ...glob]);
10+
export default async function globAssets({cwd}, assets) {
11+
return uniqWith(
12+
(
13+
await Promise.all(
14+
assets.map(async (asset) => {
15+
// Wrap single glob definition in Array
16+
let glob = castArray(isPlainObject(asset) ? asset.path : asset);
17+
// TODO Temporary workaround for https://github.com/mrmlnc/fast-glob/issues/47
18+
glob = uniq([...(await dirGlob(glob, {cwd})), ...glob]);
2019

21-
// Skip solo negated pattern (avoid to include every non js file with `!**/*.js`)
22-
if (glob.length <= 1 && glob[0].startsWith('!')) {
23-
debug(
24-
'skipping the negated glob %o as its alone in its group and would retrieve a large amount of files',
25-
glob[0]
26-
);
27-
return [];
28-
}
29-
30-
const globbed = await globby(glob, {
31-
cwd,
32-
expandDirectories: false, // TODO Temporary workaround for https://github.com/mrmlnc/fast-glob/issues/47
33-
gitignore: false,
34-
dot: true,
35-
onlyFiles: false,
36-
});
20+
// Skip solo negated pattern (avoid to include every non js file with `!**/*.js`)
21+
if (glob.length <= 1 && glob[0].startsWith('!')) {
22+
debug(
23+
'skipping the negated glob %o as its alone in its group and would retrieve a large amount of files',
24+
glob[0]
25+
);
26+
return [];
27+
}
3728

38-
if (isPlainObject(asset)) {
39-
if (globbed.length > 1) {
40-
// If asset is an Object with a glob the `path` property that resolve to multiple files,
41-
// Output an Object definition for each file matched and set each one with:
42-
// - `path` of the matched file
43-
// - `name` based on the actual file name (to avoid assets with duplicate `name`)
44-
// - other properties of the original asset definition
45-
return globbed.map((file) => ({...asset, path: file, name: basename(file)}));
46-
}
29+
const globbed = await globby(glob, {
30+
cwd,
31+
expandDirectories: false, // TODO Temporary workaround for https://github.com/mrmlnc/fast-glob/issues/47
32+
gitignore: false,
33+
dot: true,
34+
onlyFiles: false,
35+
});
4736

48-
// If asset is an Object, output an Object definition with:
49-
// - `path` of the matched file if there is one, or the original `path` definition (will be considered as a missing file)
37+
if (isPlainObject(asset)) {
38+
if (globbed.length > 1) {
39+
// If asset is an Object with a glob the `path` property that resolve to multiple files,
40+
// Output an Object definition for each file matched and set each one with:
41+
// - `path` of the matched file
42+
// - `name` based on the actual file name (to avoid assets with duplicate `name`)
5043
// - other properties of the original asset definition
51-
return {...asset, path: globbed[0] || asset.path};
44+
return globbed.map((file) => ({...asset, path: file, name: basename(file)}));
5245
}
5346

54-
if (globbed.length > 0) {
55-
// If asset is a String definition, output each files matched
56-
return globbed;
57-
}
47+
// If asset is an Object, output an Object definition with:
48+
// - `path` of the matched file if there is one, or the original `path` definition (will be considered as a missing file)
49+
// - other properties of the original asset definition
50+
return {...asset, path: globbed[0] || asset.path};
51+
}
52+
53+
if (globbed.length > 0) {
54+
// If asset is a String definition, output each files matched
55+
return globbed;
56+
}
5857

59-
// If asset is a String definition but no match is found, output the elements of the original glob (each one will be considered as a missing file)
60-
return glob;
61-
})
62-
// Sort with Object first, to prioritize Object definition over Strings in dedup
63-
))
58+
// If asset is a String definition but no match is found, output the elements of the original glob (each one will be considered as a missing file)
59+
return glob;
60+
})
61+
// Sort with Object first, to prioritize Object definition over Strings in dedup
6462
)
63+
)
64+
.flat()
6565
.sort((asset) => (isPlainObject(asset) ? -1 : 1)),
6666
// Compare `path` property if Object definition, value itself if String
6767
(a, b) => resolve(cwd, isPlainObject(a) ? a.path : a) === resolve(cwd, isPlainObject(b) ? b.path : b)
6868
);
69+
}

lib/is-prerelease.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
1-
export default ({type, main}) => type === 'prerelease' || (type === 'release' && !main);
1+
export default function isPrerelease({type, main}) {
2+
return type === 'prerelease' || (type === 'release' && !main);
3+
}

lib/parse-github-url.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
export default (repositoryUrl) => {
1+
export default function parseGitHubUrl(repositoryUrl) {
22
const [match, auth, host, path] = /^(?!.+:\/\/)(?:(?<auth>.*)@)?(?<host>.*?):(?<path>.*)$/.exec(repositoryUrl) || [];
33
try {
44
const [, owner, repo] = /^\/(?<owner>[^/]+)?\/?(?<repo>.+?)(?:\.git)?$/.exec(
@@ -8,4 +8,4 @@ export default (repositoryUrl) => {
88
} catch {
99
return {};
1010
}
11-
};
11+
}

0 commit comments

Comments
 (0)