-
Notifications
You must be signed in to change notification settings - Fork 142
feat: allow conditional skip on success and fail comments #874
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
Changes from 41 commits
304d023
120d391
ec8f4d6
508e066
f319896
5983b75
da630b1
a71ee8a
8231ec0
f516292
460d475
7d2b4de
e55733b
2156d92
6f46d09
e32cc69
30b6f38
5d9e5d5
81c9ff0
a82c2b8
219386c
34ae9a9
1cbf8c2
0d3014b
ad0a03f
1faae48
924ca55
66c9f28
a556072
7328c8c
cfc61eb
9591bd0
1cbb41a
8cfa350
6ee6c24
f250e71
60a73d6
4b689fe
ee733fb
a798fc2
09cfdac
a9af537
627b0d8
863b4a6
2d826fa
990ed77
9e19862
a052c49
260bdd6
54dd036
a6c8442
e0e7ff1
c068bb3
63a4bc1
229d4a8
43ca24f
c4c561d
88a7118
1bc293c
e95a700
2572def
201a1bb
d41a1df
6473eb9
94f3975
e29b312
474a28a
cbd0128
1ef47af
34795a5
8ee3679
f617843
e336619
15c3089
f91e8e9
ff17066
601303d
367047d
0d3cd0f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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); | ||
|
@@ -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() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
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", | ||
|
@@ -71,9 +79,7 @@ export default async function success(pluginConfig, context, { Octokit }) { | |
buildAssociatedPRsQuery(shas), | ||
{ owner, repo }, | ||
); | ||
const associatedPRs = Object.values(repository).map( | ||
(item) => item.associatedPullRequests.nodes, | ||
); | ||
const associatedPRs = buildAssociatedPRs(repository); | ||
|
||
const uniqueAssociatedPRs = uniqBy(flatten(associatedPRs), "number"); | ||
|
||
|
@@ -130,6 +136,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); | ||
|
@@ -262,9 +277,62 @@ export function buildAssociatedPRsQuery(shas) { | |
...on Commit { | ||
associatedPullRequests(first: 100) { | ||
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 | ||
} | ||
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 | ||
} | ||
} | ||
} | ||
|
@@ -275,3 +343,67 @@ export function buildAssociatedPRsQuery(shas) { | |
} | ||
`; | ||
} | ||
|
||
/** | ||
* Build associatedPRs (into issue-like object with `pull_request` property) from the GraphQL repository response | ||
* @param {object} repository | ||
* @returns {object[]} | ||
*/ | ||
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, | ||
}, | ||
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; | ||
} |
Uh oh!
There was an error while loading. Please reload this page.