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

feat: allow conditional skip on success and fail comments #874

Merged
merged 79 commits into from
Sep 2, 2024
Merged
Show file tree
Hide file tree
Changes from 48 commits
Commits
Show all changes
79 commits
Select commit Hold shift + click to select a range
304d023
feat: add `failCommentCondition` to `fail` script
babblebey Jul 10, 2024
120d391
feat: add `successCommentCondition` and `failCommentCondition` to `re…
babblebey Jul 10, 2024
ec8f4d6
feat: add `successCommentCondition` and `failCommentCondition` to `su…
babblebey Jul 10, 2024
508e066
fix(build): lint
babblebey Jul 10, 2024
f319896
test: add `fail` case `Does not post comments if "failCommentConditio…
babblebey Jul 12, 2024
5983b75
test: add `fail` case for `Does not post comments on existing issues …
babblebey Jul 12, 2024
da630b1
Merge branch 'master' into feat/conditional-success-fail-comment-skip
babblebey Jul 12, 2024
a71ee8a
Merge branch 'master' into feat/conditional-success-fail-comment-skip
babblebey Jul 14, 2024
8231ec0
Merge branch 'master' into feat/conditional-success-fail-comment-skip
babblebey Jul 15, 2024
f516292
fix(build): lint
babblebey Jul 15, 2024
460d475
test(fail): add case for `Post new issue if none exists yet, but don'…
babblebey Jul 16, 2024
7d2b4de
test(success): add case `Does not comment on issues/PR if "successCom…
babblebey Jul 16, 2024
e55733b
Update test/fail.test.js
babblebey Jul 16, 2024
2156d92
test(success): add case for `Add comment and label to found issues/as…
babblebey Jul 18, 2024
6f46d09
nits
babblebey Jul 18, 2024
e32cc69
test(success): add case for `Does not comment/label found associatedP…
babblebey Jul 18, 2024
30b6f38
Merge branch 'feat/conditional-success-fail-comment-skip' of https://…
babblebey Jul 18, 2024
5d9e5d5
Merge branch 'master' into feat/conditional-success-fail-comment-skip
babblebey Jul 18, 2024
81c9ff0
test(success): improve case `Does not comment/label found associatedP…
babblebey Jul 18, 2024
a82c2b8
doc: add documentation for `successCommentCondition` and `failComment…
babblebey Jul 18, 2024
219386c
Update lib/success.js
babblebey Jul 22, 2024
34ae9a9
Merge branch 'master' into feat/conditional-success-fail-comment-skip
babblebey Jul 22, 2024
1cbf8c2
refactor: modify `failTitle`, `failComment` and `successComment` fals…
babblebey Jul 22, 2024
0d3014b
refator: implement early return in `fail` and `success` lifecyccle he…
babblebey Jul 22, 2024
ad0a03f
Update README.md
babblebey Jul 24, 2024
1faae48
remove `failCommentCondition` example wrong description
babblebey Jul 24, 2024
924ca55
build: fix lint
babblebey Jul 24, 2024
66c9f28
Merge branch 'master' into feat/conditional-success-fail-comment-skip
babblebey Jul 25, 2024
a556072
Merge branch 'master' into feat/conditional-success-fail-comment-skip
babblebey Jul 30, 2024
7328c8c
Merge branch 'master' into feat/conditional-success-fail-comment-skip
babblebey Aug 5, 2024
cfc61eb
feat: add validators for `successCommentCondition` and `failCommentCo…
babblebey Aug 5, 2024
9591bd0
feat: add `buildAssociatedPRs` to create pr object in form of issue o…
babblebey Aug 6, 2024
1cbb41a
doc: update README.md
babblebey Aug 6, 2024
8cfa350
build: fix lint
babblebey Aug 6, 2024
6ee6c24
build: fix failing test `Add custom comment and labels`
babblebey Aug 6, 2024
f250e71
feat: request more field for `associatedPRs` via graphql and improve …
babblebey Aug 7, 2024
60a73d6
test: modify integration tests
babblebey Aug 7, 2024
4b689fe
test: modify `success` unit tests
babblebey Aug 7, 2024
ee733fb
Merge branch 'master' into feat/conditional-success-fail-comment-skip
babblebey Aug 9, 2024
a798fc2
Merge branch 'master' into feat/conditional-success-fail-comment-skip
babblebey Aug 12, 2024
09cfdac
Merge branch 'master' into feat/conditional-success-fail-comment-skip
babblebey Aug 14, 2024
a9af537
Merge branch 'master' into feat/conditional-success-fail-comment-skip
babblebey Aug 15, 2024
627b0d8
build: fix lint
babblebey Aug 15, 2024
863b4a6
build: fix failing tests
babblebey Aug 15, 2024
2d826fa
feat: add `__typename` to `issue.user` object
babblebey Aug 15, 2024
990ed77
test: add new case `Does not comment/label associatedPR created by "B…
babblebey Aug 15, 2024
9e19862
test: modify `pull_request` mock value to `boolean`
babblebey Aug 15, 2024
a052c49
chore(test): clean debug comments
babblebey Aug 15, 2024
260bdd6
Merge branch 'master' into feat/conditional-success-fail-comment-skip
babblebey Aug 19, 2024
54dd036
feat: re-integrate `buildAssociatedPRs`
babblebey Aug 19, 2024
a6c8442
feat: re-introduced and modifed `loadSingleCommitAssociatedPRs`
babblebey Aug 19, 2024
e0e7ff1
refactor: introduce `parsedIssues` as returned value from `prs**.body…
babblebey Aug 19, 2024
c068bb3
feat: added `buildRelatedIssuesQuery` util graphql query builder
babblebey Aug 19, 2024
63a4bc1
feat: implement computation for `responseRelatedIssues`
babblebey Aug 19, 2024
229d4a8
fix: correct `number` arg type in `buildRelatedIssuesQuery`
babblebey Aug 19, 2024
43ca24f
refactor: extract common field accross graphql queries to `baseFields`
babblebey Aug 19, 2024
c4c561d
refactor: transform `buildAssociatedPRs` to `buildIssuesOrPRsFromResp…
babblebey Aug 19, 2024
88a7118
feat: integrate `buildIssuesOrPRsFromResponseNode`
babblebey Aug 19, 2024
1bc293c
feat: implement `issueOrPR` for correctly addressing issues and pr in…
babblebey Aug 19, 2024
e95a700
feat: implement improved chunk operation helper `inChunks` and integr…
babblebey Aug 19, 2024
2572def
build: fix lints
babblebey Aug 19, 2024
201a1bb
Merge branch 'master' into feat/conditional-success-fail-comment-skip
babblebey Aug 21, 2024
d41a1df
test: update `integrations` test
babblebey Aug 21, 2024
6473eb9
test: address PR and Issue naming in logs in `success`
babblebey Aug 21, 2024
94f3975
refactor: why the `Promise.all()`? Removed it haha
babblebey Aug 22, 2024
e29b312
feat: set default `type` param in `buildIssuesOrPRsFromResponseNode`
babblebey Aug 26, 2024
474a28a
feat: address edge cases
babblebey Aug 26, 2024
cbd0128
Merge branch 'master' into feat/conditional-success-fail-comment-skip
babblebey Aug 26, 2024
1ef47af
Merge branch 'feat/conditional-success-fail-comment-skip' of https://…
babblebey Aug 26, 2024
34795a5
Merge branch 'master' into feat/conditional-success-fail-comment-skip
babblebey Aug 30, 2024
8ee3679
test: fixed matchers in graphql request in `success` units
babblebey Aug 30, 2024
f617843
build: lint
babblebey Aug 30, 2024
e336619
Merge branch 'feat/conditional-success-fail-comment-skip' of https://…
babblebey Aug 30, 2024
15c3089
docs: add ignore bots pr/issues example
babblebey Aug 30, 2024
f91e8e9
Merge branch 'master' into feat/conditional-success-fail-comment-skip
babblebey Sep 2, 2024
ff17066
fix: user issue `number` over `id`
babblebey Sep 2, 2024
601303d
test: improve case `'Does not comment/label associatedPR and relatedI…
babblebey Sep 2, 2024
367047d
doc: modify `buildIssuesOrPRsFromResponseNode` documentation
babblebey Sep 2, 2024
0d3cd0f
Merge branch 'master' into feat/conditional-success-fail-comment-skip
babblebey Sep 2, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
81 changes: 63 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) {
babblebey marked this conversation as resolved.
Show resolved Hide resolved
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 {
babblebey marked this conversation as resolved.
Show resolved Hide resolved
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
153 changes: 132 additions & 21 deletions lib/success.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,10 @@ export default async function success(pluginConfig, context, { Octokit }) {
githubApiUrl,
proxy,
successComment,
failComment,
successCommentCondition,
failTitle,
failComment,
failCommentCondition,
releasedLabels,
addReleases,
} = resolveConfig(pluginConfig, context);
Expand Down Expand Up @@ -59,6 +61,12 @@ export default async function success(pluginConfig, context, { Octokit }) {
logger.log("No commits found in release");
}
logger.log("Skip commenting on issues and pull requests.");
// TODO: use logger.warn() instead of logger.log()
Copy link
Member

Choose a reason for hiding this comment

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

There is no logger.warn right now, it would need to be added in semantic-release core

Copy link
Member

Choose a reason for hiding this comment

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

Just a quick fyi to keep in mind: to use the newly added logger in core, we'll need to bump the minimum bound of the peer dependency, which is a breaking change

Copy link
Member Author

Choose a reason for hiding this comment

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

Will do that in a follow-up PR 😉

logger.log(
`DEPRECATION: 'false' for 'successComment' is deprecated and will be removed in a future major version. Use 'successCommentCondition' instead.`,
);
} else if (successCommentCondition === false) {
logger.log("Skip commenting on issues and pull requests.");
} else {
const parser = issueParser(
"github",
Expand Down Expand Up @@ -161,6 +169,15 @@ export default async function success(pluginConfig, context, { Octokit }) {

await Promise.all(
uniqBy([...prs, ...issues], "number").map(async (issue) => {
const canCommentOnIssue = successCommentCondition
? template(successCommentCondition)({ ...context, issue })
: true;

if (!canCommentOnIssue) {
babblebey marked this conversation as resolved.
Show resolved Hide resolved
logger.log("Skip commenting on issue #%d.", issue.id);
return;
}

const body = successComment
? template(successComment)({ ...context, issue })
: getSuccessComment(issue, releaseInfos, nextRelease);
Expand Down Expand Up @@ -298,9 +315,63 @@ function buildAssociatedPRsQuery(shas) {
hasNextPage
}
nodes {
id
title
body
url
number
body
createdAt
updatedAt
closedAt
mergedAt
isDraft
mergedBy {
login
avatarUrl
url
}
commits {
totalCount
}
comments {
totalCount
}
state
author {
login
url
avatarUrl
__typename
}
labels(first: 100) {
nodes {
id
url
name
color
}
}
milestone {
url
id
number
state
title
description
creator {
login
url
avatarUrl
}
createdAt
closedAt
updatedAt
}
locked
activeLockReason
mergeable
canBeRebased
changedFiles
}
}
}
Expand All @@ -313,26 +384,66 @@ function buildAssociatedPRsQuery(shas) {
}

/**
* GraphQL Query to fetch additional associatedPR for commits that has more than 100 associatedPRs
* Build associatedPRs (into issue-like object with `pull_request` property) from the GraphQL repository response
* @param {object} repository
* @returns {object[]}
*/
const loadSingleCommitAssociatedPRs = `#graphql
query getCommitAssociatedPRs($owner: String!, $repo: String!, $sha: String!, $cursor: String) {
repository(owner: $owner, name: $repo) {
commit: object(oid: $sha) {
...on Commit {
associatedPullRequests(after: $cursor, first: 100) {
pageInfo {
endCursor
hasNextPage
}
nodes {
url
number
body
function buildAssociatedPRs(repository) {
const associatedPRs = [];
for (const commit in repository) {
for (const node of repository[commit].associatedPullRequests.nodes) {
const pr = {
pull_request: true,
number: node.number,
title: node.title,
body: node.body,
labels: node.labels?.nodes.map((label) => label.name),
html_url: node.url,
created_at: node.createdAt,
updated_at: node.updatedAt,
closed_at: node.closedAt,
merged_at: node.mergedAt,
draft: node.isDraft,
user: {
login: node.author?.login,
html_url: node.author?.url,
avatar_url: node.author?.avatarUrl,
type: node.author?.__typename,
},
commits: node.commits?.totalCount,
comments: node.comments?.totalCount,
state: node.state,
merged_by: {
login: node.mergedBy?.login,
avatar_url: node.mergedBy?.avatarUrl,
html_url: node.mergedBy?.url,
},
milestone: node.milestone
? {
url: node.milestone.url,
id: node.milestone.id,
number: node.milestone.number,
state: node.milestone.state,
title: node.milestone.title,
description: node.milestone.description,
creator: {
login: node.milestone.creator.login,
html_url: node.milestone.creator.url,
avatar_url: node.milestone.creator.avatarUrl,
},
created_at: node.milestone.createdAt,
closed_at: node.milestone.closedAt,
updated_at: node.milestone.updatedAt,
}
}
}
}
: null,
locked: node.locked,
active_lock_reason: node.activeLockReason,
mergeable: node.mergeable,
rebaseable: node.canBeRebased,
changed_files: node.changedFiles,
};
associatedPRs.push(pr);
}
}
`;
return associatedPRs;
}
2 changes: 2 additions & 0 deletions lib/verify.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,10 @@ const VALIDATORS = {
(isPlainObject(asset) && isStringOrStringArray(asset.path)),
),
successComment: canBeDisabled(isNonEmptyString),
successCommentCondition: canBeDisabled(isNonEmptyString),
failTitle: canBeDisabled(isNonEmptyString),
failComment: canBeDisabled(isNonEmptyString),
failCommentCondition: canBeDisabled(isNonEmptyString),
labels: canBeDisabled(isArrayOf(isNonEmptyString)),
assignees: isArrayOf(isNonEmptyString),
releasedLabels: canBeDisabled(isArrayOf(isNonEmptyString)),
Expand Down
Loading