Skip to content

Commit f4ab529

Browse files
feat: allow for releasedLabels with successComment set to false
1 parent c258b0c commit f4ab529

File tree

3 files changed

+233
-67
lines changed

3 files changed

+233
-67
lines changed

lib/success.js

Lines changed: 28 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -57,16 +57,19 @@ export default async function success(pluginConfig, context, { Octokit }) {
5757

5858
const errors = [];
5959

60-
if (successComment === false || isEmpty(commits)) {
60+
if (
61+
(successComment === false && releasedLabels === false) ||
62+
isEmpty(commits)
63+
) {
6164
if (isEmpty(commits)) {
6265
logger.log("No commits found in release");
6366
}
64-
logger.log("Skip commenting on issues and pull requests.");
67+
logger.log("Skip commenting / adding labels on issues and pull requests.");
6568
logger.warn(
6669
`DEPRECATION: 'false' for 'successComment' is deprecated and will be removed in a future major version. Use 'successCommentCondition' instead.`,
6770
);
68-
} else if (successCommentCondition === false) {
69-
logger.log("Skip commenting on issues and pull requests.");
71+
} else if (successCommentCondition === false && releasedLabels === false) {
72+
logger.log("Skip commenting / adding labels on issues and pull requests.");
7073
} else {
7174
const parser = issueParser(
7275
"github",
@@ -202,23 +205,25 @@ export default async function success(pluginConfig, context, { Octokit }) {
202205
return;
203206
}
204207

205-
const body = successComment
206-
? template(successComment)({ ...context, issue })
207-
: getSuccessComment(issue, releaseInfos, nextRelease);
208208
try {
209-
const comment = { owner, repo, issue_number: issue.number, body };
210-
debug("create comment: %O", comment);
211-
const {
212-
data: { html_url: url },
213-
} = await octokit.request(
214-
"POST /repos/{owner}/{repo}/issues/{issue_number}/comments",
215-
comment,
216-
);
217-
logger.log(
218-
`Added comment to ${issueOrPR} #%d: %s`,
219-
issue.number,
220-
url,
221-
);
209+
if (successComment !== false) {
210+
const body = successComment
211+
? template(successComment)({ ...context, issue })
212+
: getSuccessComment(issue, releaseInfos, nextRelease);
213+
const comment = { owner, repo, issue_number: issue.number, body };
214+
debug("create comment: %O", comment);
215+
const {
216+
data: { html_url: url },
217+
} = await octokit.request(
218+
"POST /repos/{owner}/{repo}/issues/{issue_number}/comments",
219+
comment,
220+
);
221+
logger.log(
222+
`Added comment to ${issueOrPR} #%d: %s`,
223+
issue.number,
224+
url,
225+
);
226+
}
222227

223228
if (releasedLabels) {
224229
const labels = releasedLabels.map((label) =>
@@ -242,18 +247,18 @@ export default async function success(pluginConfig, context, { Octokit }) {
242247
} catch (error) {
243248
if (error.status === 403) {
244249
logger.error(
245-
`Not allowed to add a comment to the issue/PR #%d.`,
250+
`Not allowed to add a comment/label to the issue/PR #%d.`,
246251
issue.number,
247252
);
248253
} else if (error.status === 404) {
249254
logger.error(
250-
`Failed to add a comment to the issue/PR #%d as it doesn't exist.`,
255+
`Failed to add a comment/label to the issue/PR #%d as it doesn't exist.`,
251256
issue.number,
252257
);
253258
} else {
254259
errors.push(error);
255260
logger.error(
256-
`Failed to add a comment to the issue/PR #%d.`,
261+
`Failed to add a comment/label to the issue/PR #%d.`,
257262
issue.number,
258263
);
259264
// Don't throw right away and continue to update other issues

test/integration.test.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -501,7 +501,7 @@ test("Comment and add labels on PR included in the releases", async (t) => {
501501
`https://api.github.local/repos/${owner}/${repo}/issues/1/labels`,
502502
{},
503503
{
504-
body: ["released"],
504+
labels: ["released"],
505505
},
506506
)
507507
.postOnce(
@@ -749,7 +749,7 @@ test("Verify, release and notify success", async (t) => {
749749
.postOnce(
750750
`https://api.github.local/repos/${owner}/${repo}/issues/1/labels`,
751751
{},
752-
{ body: ["released"] },
752+
{ labels: ["released"] },
753753
)
754754
.getOnce(
755755
`https://api.github.local/search/issues?q=${encodeURIComponent(
@@ -922,7 +922,7 @@ test("Verify, update release and notify success", async (t) => {
922922
`https://api.github.local/repos/${owner}/${repo}/issues/1/labels`,
923923
{},
924924
{
925-
body: ["released"],
925+
labels: ["released"],
926926
},
927927
)
928928
.postOnce(

0 commit comments

Comments
 (0)