Skip to content

Commit e097d1c

Browse files
babblebeyJonasSchubertgr2m
authored
feat: allow conditional skip on success and fail comments (#874)
* feat: add `failCommentCondition` to `fail` script * feat: add `successCommentCondition` and `failCommentCondition` to `resolve-config` * feat: add `successCommentCondition` and `failCommentCondition` to `success` scipt * fix(build): lint * test: add `fail` case `Does not post comments if "failCommentCondition" is "false"` * test: add `fail` case for `Does not post comments on existing issues when "failCommentCondition" is "false"` * fix(build): lint * test(fail): add case for `Post new issue if none exists yet, but don't comment on existing issues when "failCommentCondition" is disallows it` * test(success): add case `Does not comment on issues/PR if "successCommentCondition" is "false"` * Update test/fail.test.js Co-authored-by: Jonas Schubert <[email protected]> * test(success): add case for `Add comment and label to found issues/associatedPR using the "successCommentCondition"` * nits * test(success): add case for `Does not comment/label found associatedPR when "successCommentCondition" disables it` * test(success): improve case `Does not comment/label found associatedPR when "successCommentCondition" disables it` * doc: add documentation for `successCommentCondition` and `failCommentCondition` * Update lib/success.js Co-authored-by: Gregor Martynus <[email protected]> * refactor: modify `failTitle`, `failComment` and `successComment` false deprecation message * refator: implement early return in `fail` and `success` lifecyccle helper function * Update README.md Co-authored-by: Jonas Schubert <[email protected]> * remove `failCommentCondition` example wrong description * build: fix lint * feat: add validators for `successCommentCondition` and `failCommentCondition` * feat: add `buildAssociatedPRs` to create pr object in form of issue object with pull_request property * doc: update README.md * build: fix lint * build: fix failing test `Add custom comment and labels` * feat: request more field for `associatedPRs` via graphql and improve `buildAssociatedPRs` response object with * test: modify integration tests * test: modify `success` unit tests * build: fix lint * build: fix failing tests * feat: add `__typename` to `issue.user` object * test: add new case `Does not comment/label associatedPR created by "Bots"` * test: modify `pull_request` mock value to `boolean` * chore(test): clean debug comments * feat: re-integrate `buildAssociatedPRs` * feat: re-introduced and modifed `loadSingleCommitAssociatedPRs` * refactor: introduce `parsedIssues` as returned value from `prs**.body` and `commits**.message` * feat: added `buildRelatedIssuesQuery` util graphql query builder * feat: implement computation for `responseRelatedIssues` * fix: correct `number` arg type in `buildRelatedIssuesQuery` * refactor: extract common field accross graphql queries to `baseFields` * refactor: transform `buildAssociatedPRs` to `buildIssuesOrPRsFromResponseNode` with ability to build both `PRs` and `Issues` object * feat: integrate `buildIssuesOrPRsFromResponseNode` * feat: implement `issueOrPR` for correctly addressing issues and pr in logs * feat: implement improved chunk operation helper `inChunks` and integrate in pr and issues fetch * build: fix lints * test: update `integrations` test * test: address PR and Issue naming in logs in `success` * refactor: why the `Promise.all()`? Removed it haha * feat: set default `type` param in `buildIssuesOrPRsFromResponseNode` * feat: address edge cases * test: fixed matchers in graphql request in `success` units * build: lint * docs: add ignore bots pr/issues example * fix: user issue `number` over `id` * test: improve case `'Does not comment/label associatedPR and relatedIssues created by "Bots"'` * doc: modify `buildIssuesOrPRsFromResponseNode` documentation --------- Co-authored-by: Jonas Schubert <[email protected]> Co-authored-by: Gregor Martynus <[email protected]>
1 parent be071a2 commit e097d1c

File tree

8 files changed

+1873
-202
lines changed

8 files changed

+1873
-202
lines changed

README.md

+64-18
Large diffs are not rendered by default.

lib/fail.js

+17-1
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,21 @@ export default async function fail(pluginConfig, context, { Octokit }) {
2323
githubApiPathPrefix,
2424
githubApiUrl,
2525
proxy,
26-
failComment,
2726
failTitle,
27+
failComment,
28+
failCommentCondition,
2829
labels,
2930
assignees,
3031
} = resolveConfig(pluginConfig, context);
3132

3233
if (failComment === false || failTitle === false) {
3334
logger.log("Skip issue creation.");
35+
// TODO: use logger.warn() instead of logger.log()
36+
logger.log(
37+
`DEPRECATION: 'false' for 'failComment' or 'failTitle' is deprecated and will be removed in a future major version. Use 'failCommentCondition' instead.`,
38+
);
39+
} else if (failCommentCondition === false) {
40+
logger.log("Skip issue creation.");
3441
} else {
3542
const octokit = new Octokit(
3643
toOctokitOptions({
@@ -52,6 +59,15 @@ export default async function fail(pluginConfig, context, { Octokit }) {
5259
: getFailComment(branch, errors);
5360
const [srIssue] = await findSRIssues(octokit, failTitle, owner, repo);
5461

62+
const canCommentOnOrCreateIssue = failCommentCondition
63+
? template(failCommentCondition)({ ...context, issue: srIssue })
64+
: true;
65+
66+
if (!canCommentOnOrCreateIssue) {
67+
logger.log("Skip commenting on or creating an issue.");
68+
return;
69+
}
70+
5571
if (srIssue) {
5672
logger.log("Found existing semantic-release issue #%d.", srIssue.number);
5773
const comment = { owner, repo, issue_number: srIssue.number, body };

lib/resolve-config.js

+4
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,10 @@ export default function resolveConfig(
88
proxy,
99
assets,
1010
successComment,
11+
successCommentCondition,
1112
failTitle,
1213
failComment,
14+
failCommentCondition,
1315
labels,
1416
assignees,
1517
releasedLabels,
@@ -30,10 +32,12 @@ export default function resolveConfig(
3032
proxy: isNil(proxy) ? env.http_proxy || env.HTTP_PROXY || false : proxy,
3133
assets: assets ? castArray(assets) : assets,
3234
successComment,
35+
successCommentCondition,
3336
failTitle: isNil(failTitle)
3437
? "The automated release is failing 🚨"
3538
: failTitle,
3639
failComment,
40+
failCommentCondition,
3741
labels: isNil(labels)
3842
? ["semantic-release"]
3943
: labels === false

0 commit comments

Comments
 (0)