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

Split "successComment" into two parameters to enable conditional activation of this step #666

Open
Leo383 opened this issue Jul 6, 2023 · 1 comment

Comments

@Leo383
Copy link

Leo383 commented Jul 6, 2023

Hi everyone,
I want to disable successComments when the release is a prerelease and otherwise I want a custom message.

I have tried to do so via

"@semantic-release/github",
      {
        "successComment": "${prerelease ? false : `:tada: This issue has been resolved in version ${nextRelease.version} :tada:</br></br>The release is available on [GitHub release](<github_release_url>) and contains these changes: </br></br>${nextRelease.notes}`}"
      }

but the plugin seems to replace some of the brackets with parenthesis yet not all of them, thus creating this error:

SyntaxError: Missing } in template expression
        at Function (<anonymous>)
        at /opt/semantic-release/node_modules/�[4mlodash�[24m/lodash.js:14942:16
        at apply (/opt/semantic-release/node_modules/�[4mlodash�[24m/lodash.js:487:27)
        at /opt/semantic-release/node_modules/�[4mlodash�[24m/lodash.js:15326:16
        at apply (/opt/semantic-release/node_modules/�[4mlodash�[24m/lodash.js:489:27)
        at /opt/semantic-release/node_modules/�[4mlodash�[24m/lodash.js:6627:16
        at template (/opt/semantic-release/node_modules/�[4mlodash�[24m/lodash.js:14941:20)
        at /opt/semantic-release/node_modules/�[4m@semantic-release�[24m/github/lib/success.js:83:13
        at Array.map (<anonymous>)
        at module.exports (/opt/semantic-release/node_modules/�[4m@semantic-release�[24m/github/lib/success.js:81:45) {
      source: �[32m'function(obj) {\n'�[39m +
        �[32m'obj || (obj = {});\n'�[39m +
        �[32m"var __t, __p = '';\n"�[39m +
        �[32m'with (obj) {\n'�[39m +
        �[32m'__p +=\n'�[39m +
        �[32m"((__t = (prerelease ? false : `:tada: This issue has been resolved in version ${nextRelease.version)) == null ? '' : __t) +\n"�[39m +
        �[32m"' :tada:</br></br>The release is available on [GitHub release](<github_release_url>) and contains these changes: </br></br>' +\n"�[39m +
        �[32m"((__t = (nextRelease.notes)) == null ? '' : __t) +\n"�[39m +
        �[32m"'`}';\n"�[39m +
        �[32m'\n'�[39m +
        �[32m'}\n'�[39m +
        �[32m'return __p\n'�[39m +
        �[32m'}'�[39m,
      pluginName: �[32m'@semantic-release/github'�[39m
    }

Does anyone notice what I am doing wrong or if I am doing something wrong?

I am using semantic-release version 21.0.2

@Leo383
Copy link
Author

Leo383 commented Jul 6, 2023

I went through the code and noticed, that with the current configuration there is no way my request would work at all.
The check at

51   if (successComment === false) {
52      logger.log("Skip commenting on issues and pull requests.");
53    } else {

is done before processing the string into a template at

128   await Promise.all(
129        uniqBy([...prs, ...issues], "number").map(async (issue) => {
130          const body = successComment
131            ? template(successComment)({ ...context, issue })
132            : getSuccessComment(issue, releaseInfos, nextRelease);

So I there would be the need to have 2 parameters:

  1. successComment (parse wether or not to run this step )
  2. successCommentMessage (the string that gets processed through the lodash template)

@Leo383 Leo383 changed the title SuccessComment templating in ternary expression Split "successComment" into two parameters to enable conditional activation of this step Jul 6, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant