Skip to content

Commit

Permalink
feat: allow conditional skip on success and fail comments (#874)
Browse files Browse the repository at this point in the history
* 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]>
  • Loading branch information
3 people authored Sep 2, 2024
1 parent be071a2 commit e097d1c
Show file tree
Hide file tree
Showing 8 changed files with 1,873 additions and 202 deletions.
82 changes: 64 additions & 18 deletions README.md

Large diffs are not rendered by default.

18 changes: 17 additions & 1 deletion lib/fail.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,21 @@ export default async function fail(pluginConfig, context, { Octokit }) {
githubApiPathPrefix,
githubApiUrl,
proxy,
failComment,
failTitle,
failComment,
failCommentCondition,
labels,
assignees,
} = resolveConfig(pluginConfig, context);

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

const canCommentOnOrCreateIssue = failCommentCondition
? template(failCommentCondition)({ ...context, issue: srIssue })
: true;

if (!canCommentOnOrCreateIssue) {
logger.log("Skip commenting on or creating an issue.");
return;
}

if (srIssue) {
logger.log("Found existing semantic-release issue #%d.", srIssue.number);
const comment = { owner, repo, issue_number: srIssue.number, body };
Expand Down
4 changes: 4 additions & 0 deletions lib/resolve-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,10 @@ export default function resolveConfig(
proxy,
assets,
successComment,
successCommentCondition,
failTitle,
failComment,
failCommentCondition,
labels,
assignees,
releasedLabels,
Expand All @@ -30,10 +32,12 @@ export default function resolveConfig(
proxy: isNil(proxy) ? env.http_proxy || env.HTTP_PROXY || false : proxy,
assets: assets ? castArray(assets) : assets,
successComment,
successCommentCondition,
failTitle: isNil(failTitle)
? "The automated release is failing 🚨"
: failTitle,
failComment,
failCommentCondition,
labels: isNil(labels)
? ["semantic-release"]
: labels === false
Expand Down
Loading

0 comments on commit e097d1c

Please sign in to comment.