Skip to content

Commit 0a8a0fc

Browse files
feat: allow for releasedLabels with successComment set to false
1 parent 39ecf6b commit 0a8a0fc

File tree

3 files changed

+233
-53
lines changed

3 files changed

+233
-53
lines changed

lib/success.js

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,8 @@ export default async function success(pluginConfig, context, { Octokit }) {
5555

5656
const errors = [];
5757

58-
if (successComment === false) {
59-
logger.log("Skip commenting on issues and pull requests.");
58+
if (successComment === false && releasedLabels === false) {
59+
logger.log("Skip commenting / adding labels on issues and pull requests.");
6060
} else {
6161
const parser = issueParser(
6262
"github",
@@ -134,20 +134,21 @@ export default async function success(pluginConfig, context, { Octokit }) {
134134

135135
await Promise.all(
136136
uniqBy([...prs, ...issues], "number").map(async (issue) => {
137-
const body = successComment
138-
? template(successComment)({ ...context, issue })
139-
: getSuccessComment(issue, releaseInfos, nextRelease);
140137
try {
141-
const comment = { owner, repo, issue_number: issue.number, body };
142-
debug("create comment: %O", comment);
143-
const {
144-
data: { html_url: url },
145-
} = await octokit.request(
146-
"POST /repos/{owner}/{repo}/issues/{issue_number}/comments",
147-
comment,
148-
);
149-
logger.log("Added comment to issue #%d: %s", issue.number, url);
150-
138+
if (successComment !== false) {
139+
const body = successComment
140+
? template(successComment)({ ...context, issue })
141+
: getSuccessComment(issue, releaseInfos, nextRelease);
142+
const comment = { owner, repo, issue_number: issue.number, body };
143+
debug("create comment: %O", comment);
144+
const {
145+
data: { html_url: url },
146+
} = await octokit.request(
147+
"POST /repos/{owner}/{repo}/issues/{issue_number}/comments",
148+
comment,
149+
);
150+
logger.log("Added comment to issue #%d: %s", issue.number, url);
151+
}
151152
if (releasedLabels) {
152153
const labels = releasedLabels.map((label) =>
153154
template(label)(context),
@@ -166,18 +167,18 @@ export default async function success(pluginConfig, context, { Octokit }) {
166167
} catch (error) {
167168
if (error.status === 403) {
168169
logger.error(
169-
"Not allowed to add a comment to the issue #%d.",
170+
"Not allowed to add comment/label to the issue #%d.",
170171
issue.number,
171172
);
172173
} else if (error.status === 404) {
173174
logger.error(
174-
"Failed to add a comment to the issue #%d as it doesn't exist.",
175+
"Failed to add comment/label to the issue #%d as it doesn't exist.",
175176
issue.number,
176177
);
177178
} else {
178179
errors.push(error);
179180
logger.error(
180-
"Failed to add a comment to the issue #%d.",
181+
"Failed to add comment/label to the issue #%d.",
181182
issue.number,
182183
);
183184
// 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
@@ -462,7 +462,7 @@ test("Comment and add labels on PR included in the releases", async (t) => {
462462
`https://api.github.local/repos/${owner}/${repo}/issues/1/labels`,
463463
{},
464464
{
465-
body: ["released"],
465+
labels: ["released"],
466466
},
467467
)
468468
.getOnce(
@@ -664,7 +664,7 @@ test("Verify, release and notify success", async (t) => {
664664
.postOnce(
665665
`https://api.github.local/repos/${owner}/${repo}/issues/1/labels`,
666666
{},
667-
{ body: ["released"] },
667+
{ labels: ["released"] },
668668
)
669669
.getOnce(
670670
`https://api.github.local/search/issues?q=${encodeURIComponent(
@@ -822,7 +822,7 @@ test("Verify, update release and notify success", async (t) => {
822822
`https://api.github.local/repos/${owner}/${repo}/issues/1/labels`,
823823
{},
824824
{
825-
body: ["released"],
825+
labels: ["released"],
826826
},
827827
)
828828
.getOnce(

0 commit comments

Comments
 (0)