Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: use makeTag from utils rather than lodash template #2814

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 3 additions & 2 deletions lib/branches/get-tags.js
@@ -1,8 +1,9 @@
import { escapeRegExp, template } from "lodash-es";
import { escapeRegExp } from "lodash-es";
import semver from "semver";
import pReduce from "p-reduce";
import debugTags from "debug";
import { getNote, getTags } from "../../lib/git.js";
import { makeTag } from "../../lib/utils.js";
Comment on lines 5 to +6
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I copied the line above, but this could also be:

Suggested change
import { getNote, getTags } from "../../lib/git.js";
import { makeTag } from "../../lib/utils.js";
import { getNote, getTags } from "../git.js";
import { makeTag } from "../utils.js";

though in that manner it would lose the mention of libs and might not be as explicit / obvious.


const debug = debugTags("semantic-release:get-tags");

Expand All @@ -11,7 +12,7 @@ export default async ({ cwd, env, options: { tagFormat } }, branches) => {
// by replacing the `version` variable in the template by `(.+)`.
// The `tagFormat` is compiled with space as the `version` as it's an invalid tag character,
// so it's guaranteed to no be present in the `tagFormat`.
const tagRegexp = `^${escapeRegExp(template(tagFormat)({ version: " " })).replace(" ", "(.+)")}`;
const tagRegexp = `^${escapeRegExp(makeTag(tagFormat, " ")).replace(" ", "(.+)")}`;

return pReduce(
branches,
Expand Down
2 changes: 1 addition & 1 deletion lib/utils.js
@@ -1,4 +1,4 @@
import { isFunction, template, union } from "lodash-es";
import { template, union } from "lodash-es";
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

isFunction was imported but not used.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Incase the unused function is desired

Suggested change
import { template, union } from "lodash-es";
import { isFunction, template, union } from "lodash-es";

import semver from "semver";
import hideSensitive from "./hide-sensitive.js";

Expand Down
11 changes: 6 additions & 5 deletions lib/verify.js
@@ -1,6 +1,7 @@
import { isPlainObject, isString, template } from "lodash-es";
import { isPlainObject, isString } from "lodash-es";
import AggregateError from "aggregate-error";
import { isGitRepo, verifyTagName } from "./git.js";
import { makeTag } from "./utils.js";
import getError from "./get-error.js";

export default async (context) => {
Expand All @@ -17,15 +18,15 @@ export default async (context) => {
errors.push(getError("ENOREPOURL"));
}

// Verify that compiling the `tagFormat` produce a valid Git tag
if (!(await verifyTagName(template(tagFormat)({ version: "0.0.0" })))) {
// Verify that compiling the `tagFormat` will produce a valid Git tag
if (!(await verifyTagName(makeTag(tagFormat, "0.0.0")))) {
errors.push(getError("EINVALIDTAGFORMAT", context));
}

// Verify the `tagFormat` contains the variable `version` by compiling the `tagFormat` template
// Verify that the `tagFormat` contains the variable `version` by compiling the `tagFormat` template
// with a space as the `version` value and verify the result contains the space.
// The space is used as it's an invalid tag character, so it's guaranteed to no be present in the `tagFormat`.
if ((template(tagFormat)({ version: " " }).match(/ /g) || []).length !== 1) {
if ((makeTag(tagFormat, " ").match(/ /g) || []).length !== 1) {
errors.push(getError("ETAGNOVERSION", context));
}

Expand Down