Skip to content

Commit

Permalink
chore: update xo to 0.39.1 (#375)
Browse files Browse the repository at this point in the history
This is the last version that supports CommonJS.
  • Loading branch information
fgreinacher committed May 12, 2022
1 parent 45ad46d commit a8d1ce5
Show file tree
Hide file tree
Showing 20 changed files with 2,292 additions and 5,380 deletions.
4 changes: 2 additions & 2 deletions lib/definitions/errors.js
Expand Up @@ -2,8 +2,8 @@ const {inspect} = require('util');
const pkg = require('../../package.json');

const [homepage] = pkg.homepage.split('#');
const linkify = file => `${homepage}/blob/master/${file}`;
const stringify = object => inspect(object, {breakLength: Infinity, depth: 2, maxArrayLength: 5});
const linkify = (file) => `${homepage}/blob/master/${file}`;
const stringify = (object) => inspect(object, {breakLength: Number.POSITIVE_INFINITY, depth: 2, maxArrayLength: 5});

module.exports = {
EINVALIDASSETS: ({assets}) => ({
Expand Down
2 changes: 1 addition & 1 deletion lib/fail.js
Expand Up @@ -31,7 +31,7 @@ module.exports = async (pluginConfig, context) => {
const openFailTitleIssueEndpoint = urlJoin(issuesEndpoint, `?state=opened&search=${encodedFailTitle}`);

const openFailTitleIssues = await got(openFailTitleIssueEndpoint, {...apiOptions}).json();
const existingIssue = openFailTitleIssues.find(openFailTitleIssue => openFailTitleIssue.title === failTitle);
const existingIssue = openFailTitleIssues.find((openFailTitleIssue) => openFailTitleIssue.title === failTitle);

if (existingIssue) {
debug('comment on issue: %O', existingIssue);
Expand Down
10 changes: 6 additions & 4 deletions lib/get-fail-comment.js
Expand Up @@ -5,14 +5,16 @@ const GET_HELP_URL = `${HOME_URL}#get-help`;
const USAGE_DOC_URL = `${HOME_URL}/blob/master/docs/usage/README.md`;
const NEW_ISSUE_URL = `${HOME_URL}/issues/new`;

const formatError = error => `### ${error.message}
const formatError = (error) => `### ${error.message}
${error.details ||
${
error.details ||
`Unfortunately this error doesn't have any additional information.${
error.pluginName
? ` Feel free to kindly ask the author of the \`${error.pluginName}\` plugin to add more helpful information.`
: ''
}`}`;
}`
}`;

module.exports = (branch, errors) => `## :rotating_light: The automated release from the \`${
branch.name
Expand All @@ -37,7 +39,7 @@ If those don't help, or if this issue is reporting something you think isn't rig
---
${errors.map(error => formatError(error)).join('\n\n---\n\n')}
${errors.map((error) => formatError(error)).join('\n\n---\n\n')}
---
Expand Down
4 changes: 2 additions & 2 deletions lib/get-success-comment.js
@@ -1,6 +1,6 @@
const {HOME_URL} = require('./definitions/constants');

const linkify = releaseInfo =>
const linkify = (releaseInfo) =>
`${releaseInfo.url ? `[${releaseInfo.name}](${releaseInfo.url})` : `\`${releaseInfo.name}\``}`;

module.exports = (issueOrMergeRequest, releaseInfos, nextRelease) =>
Expand All @@ -11,7 +11,7 @@ module.exports = (issueOrMergeRequest, releaseInfos, nextRelease) =>
? `\n\nThe release is available on${
releaseInfos.length === 1
? ` ${linkify(releaseInfos[0])}.`
: `:\n${releaseInfos.map(releaseInfo => `- ${linkify(releaseInfo)}`).join('\n')}`
: `:\n${releaseInfos.map((releaseInfo) => `- ${linkify(releaseInfo)}`).join('\n')}`
}`
: ''
}
Expand Down
8 changes: 4 additions & 4 deletions lib/glob-assets.js
@@ -1,5 +1,4 @@
const path = require('path');
const {basename} = require('path');
const {isPlainObject, castArray, uniqWith, uniq} = require('lodash');
const dirGlob = require('dir-glob');
const globby = require('globby');
Expand All @@ -8,9 +7,10 @@ const debug = require('debug')('semantic-release:gitlab');
module.exports = async ({cwd}, assets) =>
uniqWith(
[]
// eslint-disable-next-line unicorn/prefer-spread
.concat(
...(await Promise.all(
assets.map(async asset => {
assets.map(async (asset) => {
// Wrap single glob definition in Array
let glob = castArray(isPlainObject(asset) ? asset.path : asset);
// TODO Temporary workaround for https://github.com/mrmlnc/fast-glob/issues/47
Expand Down Expand Up @@ -42,7 +42,7 @@ module.exports = async ({cwd}, assets) =>
// - `filepath` ignored (also to avoid duplicates)
// - other properties of the original asset definition
const {filepath, ...others} = asset;
return globbed.map(file => ({...others, path: file, label: basename(file)}));
return globbed.map((file) => ({...others, path: file, label: path.basename(file)}));
}

// If asset is an Object, output an Object definition with:
Expand All @@ -62,7 +62,7 @@ module.exports = async ({cwd}, assets) =>
// Sort with Object first, to prioritize Object definition over Strings in dedup
))
)
.sort(asset => (isPlainObject(asset) ? -1 : 1)),
.sort((asset) => (isPlainObject(asset) ? -1 : 1)),
// Compare `path` property if Object definition, value itself if String
(a, b) => path.resolve(cwd, isPlainObject(a) ? a.path : a) === path.resolve(cwd, isPlainObject(b) ? b.path : b)
);
8 changes: 4 additions & 4 deletions lib/publish.js
@@ -1,5 +1,5 @@
const {createReadStream} = require('fs');
const {resolve} = require('path');
const pathlib = require('path');
const {stat} = require('fs-extra');
const {isPlainObject, template} = require('lodash');
const FormData = require('form-data');
Expand Down Expand Up @@ -35,15 +35,15 @@ module.exports = async (pluginConfig, context) => {
debug('globbed assets: %o', globbedAssets);

await Promise.all(
globbedAssets.map(async asset => {
globbedAssets.map(async (asset) => {
const {path, type, filepath} = isPlainObject(asset) ? asset : {path: asset};
const file = resolve(cwd, path);
const file = pathlib.resolve(cwd, path);
const label = asset.label ? template(asset.label)(context) : undefined;
let fileStat;

try {
fileStat = await stat(file);
} catch (_) {
} catch {
logger.error('The asset %s cannot be read, and will be ignored.', path);
return;
}
Expand Down
6 changes: 3 additions & 3 deletions lib/resolve-config.js
Expand Up @@ -78,7 +78,7 @@ function shouldProxy(gitlabUrl, NO_PROXY) {
// Stripping ports in this way instead of using parsedUrl.hostname to make
// sure that the brackets around IPv6 addresses are kept.
hostname = hostname.replace(/:\d*$/, '');
port = parseInt(port, 10) || DEFAULT_PORTS[proto] || 0;
port = Number.parseInt(port, 10) || DEFAULT_PORTS[proto] || 0;

if (!NO_PROXY) {
return true; // Always proxy if NO_PROXY is not set.
Expand All @@ -88,14 +88,14 @@ function shouldProxy(gitlabUrl, NO_PROXY) {
return false; // Never proxy if wildcard is set.
}

return NO_PROXY.split(/[,\s]/).every(function(proxy) {
return NO_PROXY.split(/[,\s]/).every((proxy) => {
if (!proxy) {
return true; // Skip zero-length hosts.
}

const parsedProxy = proxy.match(/^(.+):(\d+)$/);
let parsedProxyHostname = parsedProxy ? parsedProxy[1] : proxy;
const parsedProxyPort = parsedProxy ? parseInt(parsedProxy[2], 10) : 0;
const parsedProxyPort = parsedProxy ? Number.parseInt(parsedProxy[2], 10) : 0;
if (parsedProxyPort && parsedProxyPort !== port) {
return true; // Skip if ports don't match.
}
Expand Down
25 changes: 14 additions & 11 deletions lib/success.js
Expand Up @@ -22,9 +22,9 @@ module.exports = async (pluginConfig, context) => {
if (successComment === false) {
logger.log('Skip commenting on issues and pull requests.');
} else {
const releaseInfos = releases.filter(release => Boolean(release.name));
const releaseInfos = releases.filter((release) => Boolean(release.name));
try {
const postCommentToIssue = issue => {
const postCommentToIssue = (issue) => {
const issueNotesEndpoint = urlJoin(gitlabApiUrl, `/projects/${issue.project_id}/issues/${issue.iid}/notes`);
debug('Posting issue note to %s', issueNotesEndpoint);
const body = successComment
Expand All @@ -37,7 +37,7 @@ module.exports = async (pluginConfig, context) => {
});
};

const postCommentToMergeRequest = mergeRequest => {
const postCommentToMergeRequest = (mergeRequest) => {
const mergeRequestNotesEndpoint = urlJoin(
gitlabApiUrl,
`/projects/${mergeRequest.project_id}/merge_requests/${mergeRequest.iid}/notes`
Expand All @@ -53,7 +53,7 @@ module.exports = async (pluginConfig, context) => {
});
};

const getRelatedMergeRequests = async commitHash => {
const getRelatedMergeRequests = async (commitHash) => {
const relatedMergeRequestsEndpoint = urlJoin(
gitlabApiUrl,
`/projects/${encodedRepoId}/repository/commits/${commitHash}/merge_requests`
Expand All @@ -66,10 +66,10 @@ module.exports = async (pluginConfig, context) => {
})
.json();

return relatedMergeRequests.filter(x => x.state === 'merged');
return relatedMergeRequests.filter((x) => x.state === 'merged');
};

const getRelatedIssues = async mergeRequest => {
const getRelatedIssues = async (mergeRequest) => {
const relatedIssuesEndpoint = urlJoin(
gitlabApiUrl,
`/projects/${mergeRequest.project_id}/merge_requests/${mergeRequest.iid}/closes_issues`
Expand All @@ -82,16 +82,19 @@ module.exports = async (pluginConfig, context) => {
})
.json();

return relatedIssues.filter(x => x.state === 'closed');
return relatedIssues.filter((x) => x.state === 'closed');
};

const relatedMergeRequests = uniqWith(
(await Promise.all(commits.map(x => x.hash).map(getRelatedMergeRequests))).flat(),
(await Promise.all(commits.map((commit) => getRelatedMergeRequests(commit.hash)))).flat(),
isEqual
);
const relatedIssues = uniqWith((await Promise.all(relatedMergeRequests.map(getRelatedIssues))).flat(), isEqual);
await Promise.all(relatedIssues.map(postCommentToIssue));
await Promise.all(relatedMergeRequests.map(postCommentToMergeRequest));
const relatedIssues = uniqWith(
(await Promise.all(relatedMergeRequests.map((mergeRequest) => getRelatedIssues(mergeRequest)))).flat(),
isEqual
);
await Promise.all(relatedIssues.map((issues) => postCommentToIssue(issues)));
await Promise.all(relatedMergeRequests.map((mergeRequest) => postCommentToMergeRequest(mergeRequest)));
} catch (error) {
logger.error('An error occurred while posting comments to related issues and merge requests:\n%O', error);
throw error;
Expand Down
19 changes: 9 additions & 10 deletions lib/verify.js
Expand Up @@ -7,14 +7,15 @@ const resolveConfig = require('./resolve-config');
const getRepoId = require('./get-repo-id');
const getError = require('./get-error');

const isNonEmptyString = value => isString(value) && value.trim();
const isStringOrStringArray = value => isNonEmptyString(value) || (isArray(value) && value.every(isNonEmptyString));
const isArrayOf = validator => array => isArray(array) && array.every(value => validator(value));
const canBeDisabled = validator => value => value === false || validator(value);
const isNonEmptyString = (value) => isString(value) && value.trim();
const isStringOrStringArray = (value) =>
isNonEmptyString(value) || (isArray(value) && value.every((item) => isNonEmptyString(item)));
const isArrayOf = (validator) => (array) => isArray(array) && array.every((value) => validator(value));
const canBeDisabled = (validator) => (value) => value === false || validator(value);

const VALIDATORS = {
assets: isArrayOf(
asset => isStringOrStringArray(asset) || (isPlainObject(asset) && isStringOrStringArray(asset.path))
(asset) => isStringOrStringArray(asset) || (isPlainObject(asset) && isStringOrStringArray(asset.path))
),
failTitle: canBeDisabled(isNonEmptyString),
failComment: canBeDisabled(isNonEmptyString),
Expand All @@ -37,11 +38,9 @@ module.exports = async (pluginConfig, context) => {
return isNil(value) || isNil(validator) || VALIDATORS[option](value);
};

const errors = Object.entries({...options}).reduce(
(errors, [option, value]) =>
isValid(option, value) ? errors : [...errors, getError(`EINVALID${option.toUpperCase()}`, {[option]: value})],
[]
);
const errors = Object.entries({...options})
.filter(([option, value]) => !isValid(option, value))
.map(([option, value]) => getError(`EINVALID${option.toUpperCase()}`, {[option]: value}));

if (!repoId) {
errors.push(getError('EINVALIDGITLABURL'));
Expand Down

0 comments on commit a8d1ce5

Please sign in to comment.