Skip to content

Commit

Permalink
feat(commenting): disable if set to false
Browse files Browse the repository at this point in the history
  • Loading branch information
JonasSchubert committed Jul 1, 2024
1 parent b53d424 commit 05d1a59
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 2 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ The success comment condition is generated with [Lodash template](https://lodash

##### successCommentCondition example

- do no create any comments at all: `"<% return false; %>"`
- do no create any comments at all: set to `false` or templating: `"<% return false; %>"`
- to only comment on issues: `"<% return issue %>"`
- to only comment on merge requests: `"<% return mergeRequest %>"`
- you can use labels to filter issues: `"<% return issue.labels?.includes('semantic-release-relevant') %>"`
Expand Down Expand Up @@ -204,7 +204,7 @@ The fail comment condition is generated with [Lodash template](https://lodash.co

##### failCommentCondition example

- do no create any comments at all: `"<% return false; %>"`
- do no create any comments at all: set to `false` or templating: `"<% return false; %>"`
- to only comment on main branch: `"<% return branch.name === 'main' %>"`
- you can use labels to filter issues, i.e. to not comment if the issue is labeled with `wip`: `"<% return !issue.labels?.includes('wip') %>"`

Expand Down
2 changes: 2 additions & 0 deletions lib/fail.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ export default async (pluginConfig, context) => {
logger.log("Skip issue creation.");
logger.error(`Failure reporting should be disabled via 'failCommentCondition'.
Using 'false' for 'failComment' or 'failTitle' is deprecated and will be removed in a future major version.`);
} else if (failCommentCondition === false) {
logger.log("Skip issue creation.");
} else {
const encodedFailTitle = encodeURIComponent(failTitle);
const description = failComment ? template(failComment)({ branch, errors }) : getFailComment(branch, errors);
Expand Down
2 changes: 2 additions & 0 deletions lib/success.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ export default async (pluginConfig, context) => {
logger.log("Skip commenting on issues and pull requests.");
logger.error(`Issue and pull request comments should be disabled via 'successCommentCondition'.
Using 'false' for 'successComment' is deprecated and will be removed in a future major version.`);
} else if (successCommentCondition === false) {
logger.log("Skip commenting on issues and pull requests.");
} else {
const releaseInfos = releases.filter((release) => Boolean(release.name));
try {
Expand Down
15 changes: 15 additions & 0 deletions test/fail.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -346,3 +346,18 @@ test.serial("Post new issue if none exists yet with disabled comment on existing
"https://gitlab.com/test_user/test_repo/-/issues/3",
]);
});

test.serial("Does not post comments when failCommentCondition is set to false", async (t) => {
const owner = "test_user";
const repo = "test_repo";
const env = { GITLAB_TOKEN: "gitlab_token" };
const pluginConfig = { failCommentCondition: false };
const branch = { name: "main" };
const options = { repositoryUrl: `https://gitlab.com/${owner}/${repo}.git` };
const errors = [{ message: "An error occured" }];
const gitlab = authenticate(env);

await fail(pluginConfig, { env, options, branch, errors, logger: t.context.logger });

t.true(gitlab.isDone());
});
16 changes: 16 additions & 0 deletions test/success.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -289,3 +289,19 @@ test.serial(
t.true(gitlab.isDone());
}
);

test.serial("Does not post comments when successCommentCondition is set to false", async (t) => {
const owner = "test_user";
const repo = "test_repo";
const env = { GITLAB_TOKEN: "gitlab_token" };
const pluginConfig = { successCommentCondition: false };
const nextRelease = { version: "1.0.0" };
const releases = [{ name: RELEASE_NAME, url: "https://gitlab.com/test_user/test_repo/-/releases/v1.0.0" }];
const options = { repositoryUrl: `https://gitlab.com/${owner}/${repo}.git` };
const commits = [{ hash: "abcdef" }, { hash: "fedcba" }];
const gitlab = authenticate(env);

await success(pluginConfig, { env, options, nextRelease, logger: t.context.logger, commits, releases });

t.true(gitlab.isDone());
});

0 comments on commit 05d1a59

Please sign in to comment.