Skip to content

Commit ec38c66

Browse files
fix: rebuild on top of master
1 parent 5e040f4 commit ec38c66

File tree

2 files changed

+106
-32
lines changed

2 files changed

+106
-32
lines changed

lib/success.js

+24-22
Original file line numberDiff line numberDiff line change
@@ -64,12 +64,12 @@ export default async function success(pluginConfig, context, { Octokit }) {
6464
if (isEmpty(commits)) {
6565
logger.log("No commits found in release");
6666
}
67-
logger.log("Skip commenting on issues and pull requests.");
67+
logger.log("Skip commenting / adding labels on issues and pull requests.");
6868
logger.warn(
6969
`DEPRECATION: 'false' for 'successComment' is deprecated and will be removed in a future major version. Use 'successCommentCondition' instead.`,
7070
);
71-
} else if (successCommentCondition === false) {
72-
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.");
7373
} else {
7474
const parser = issueParser(
7575
"github",
@@ -205,23 +205,25 @@ export default async function success(pluginConfig, context, { Octokit }) {
205205
return;
206206
}
207207

208-
const body = successComment
209-
? template(successComment)({ ...context, issue })
210-
: getSuccessComment(issue, releaseInfos, nextRelease);
211208
try {
212-
const comment = { owner, repo, issue_number: issue.number, body };
213-
debug("create comment: %O", comment);
214-
const {
215-
data: { html_url: url },
216-
} = await octokit.request(
217-
"POST /repos/{owner}/{repo}/issues/{issue_number}/comments",
218-
comment,
219-
);
220-
logger.log(
221-
`Added comment to ${issueOrPR} #%d: %s`,
222-
issue.number,
223-
url,
224-
);
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+
}
225227

226228
if (releasedLabels) {
227229
const labels = releasedLabels.map((label) =>
@@ -245,18 +247,18 @@ export default async function success(pluginConfig, context, { Octokit }) {
245247
} catch (error) {
246248
if (error.status === 403) {
247249
logger.error(
248-
`Not allowed to add a comment to the issue/PR #%d.`,
250+
`Not allowed to add a comment/label to the issue/PR #%d.`,
249251
issue.number,
250252
);
251253
} else if (error.status === 404) {
252254
logger.error(
253-
`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.`,
254256
issue.number,
255257
);
256258
} else {
257259
errors.push(error);
258260
logger.error(
259-
`Failed to add a comment to the issue/PR #%d.`,
261+
`Failed to add a comment/label to the issue/PR #%d.`,
260262
issue.number,
261263
);
262264
// Don't throw right away and continue to update other issues

test/success.test.js

+82-10
Original file line numberDiff line numberDiff line change
@@ -1992,13 +1992,13 @@ test("Ignore missing and forbidden issues/PRs", async (t) => {
19921992
);
19931993
t.true(
19941994
t.context.error.calledWith(
1995-
"Failed to add a comment to the issue/PR #%d as it doesn't exist.",
1995+
"Failed to add a comment/label to the issue/PR #%d as it doesn't exist.",
19961996
2,
19971997
),
19981998
);
19991999
t.true(
20002000
t.context.error.calledWith(
2001-
"Not allowed to add a comment to the issue/PR #%d.",
2001+
"Not allowed to add a comment/label to the issue/PR #%d.",
20022002
3,
20032003
),
20042004
);
@@ -3225,7 +3225,7 @@ test("Ignore errors when adding comments and closing issues", async (t) => {
32253225
t.is(error2.status, 500);
32263226
t.true(
32273227
t.context.error.calledWith(
3228-
"Failed to add a comment to the issue/PR #%d.",
3228+
"Failed to add a comment/label to the issue/PR #%d.",
32293229
1,
32303230
),
32313231
);
@@ -3396,6 +3396,10 @@ test('Skip comment on on issues/PR if "successComment" is "false"', async (t) =>
33963396
repository: {
33973397
commit123: {
33983398
associatedPullRequests: {
3399+
pageInfo: {
3400+
endCursor: "NI",
3401+
hasNextPage: false,
3402+
},
33993403
nodes: [prs[0]],
34003404
},
34013405
},
@@ -3411,6 +3415,32 @@ test('Skip comment on on issues/PR if "successComment" is "false"', async (t) =>
34113415
{},
34123416
{ labels: ["released"] },
34133417
)
3418+
.postOnce(
3419+
(url, { body }) => {
3420+
t.is(url, "https://api.github.local/graphql");
3421+
t.regex(JSON.parse(body).query, /query getRelatedIssues\(/);
3422+
return true;
3423+
},
3424+
{
3425+
data: {
3426+
repository: {},
3427+
},
3428+
},
3429+
)
3430+
.postOnce(
3431+
(url, { body }) => {
3432+
t.is(url, "https://api.github.local/graphql");
3433+
t.regex(JSON.parse(body).query, /query getSRIssues\(/);
3434+
return true;
3435+
},
3436+
{
3437+
data: {
3438+
repository: {
3439+
issues: { nodes: [] },
3440+
},
3441+
},
3442+
},
3443+
)
34143444
.getOnce(
34153445
`https://api.github.local/search/issues?q=${encodeURIComponent(
34163446
"in:title",
@@ -3522,7 +3552,9 @@ test('Skip comment on issues/PR and skip label if "successComment" is "false" /
35223552
);
35233553

35243554
t.true(
3525-
t.context.log.calledWith("Skip commenting on issues and pull requests."),
3555+
t.context.log.calledWith(
3556+
"Skip commenting / adding labels on issues and pull requests.",
3557+
),
35263558
);
35273559
t.true(fetch.done());
35283560
});
@@ -3553,13 +3585,53 @@ test('Does not comment/label on issues/PR if "successCommentCondition" is "false
35533585
.getOnce(`https://api.github.local/repos/${owner}/${repo}`, {
35543586
full_name: `${owner}/${repo}`,
35553587
})
3556-
.postOnce("https://api.github.local/graphql", {
3557-
data: {
3558-
repository: {
3559-
issues: { nodes: [] },
3588+
.postOnce(
3589+
(url, { body }) =>
3590+
url === "https://api.github.local/graphql" &&
3591+
JSON.parse(body).query.includes("query getAssociatedPRs("),
3592+
{
3593+
data: {
3594+
repository: {
3595+
commit123: {
3596+
oid: "123",
3597+
associatedPullRequests: {
3598+
pageInfo: {
3599+
endCursor: "NI",
3600+
hasNextPage: false,
3601+
},
3602+
nodes: [],
3603+
},
3604+
},
3605+
},
35603606
},
35613607
},
3562-
})
3608+
)
3609+
.postOnce(
3610+
(url, { body }) => {
3611+
t.is(url, "https://api.github.local/graphql");
3612+
t.regex(JSON.parse(body).query, /query getRelatedIssues\(/);
3613+
return true;
3614+
},
3615+
{
3616+
data: {
3617+
repository: {},
3618+
},
3619+
},
3620+
)
3621+
.postOnce(
3622+
(url, { body }) => {
3623+
t.is(url, "https://api.github.local/graphql");
3624+
t.regex(JSON.parse(body).query, /query getSRIssues\(/);
3625+
return true;
3626+
},
3627+
{
3628+
data: {
3629+
repository: {
3630+
issues: { nodes: [] },
3631+
},
3632+
},
3633+
},
3634+
)
35633635
.getOnce(
35643636
`https://api.github.local/search/issues?q=${encodeURIComponent(
35653637
"in:title",
@@ -3592,7 +3664,7 @@ test('Does not comment/label on issues/PR if "successCommentCondition" is "false
35923664
t.true(fetch.done());
35933665
});
35943666

3595-
test('Add comment and label to found issues/associatedPR using the "successCommentCondition": if specific label is found', async (t) => {
3667+
test('Add comment and label to found issues/associated PR using the "successCommentCondition": if specific label is found', async (t) => {
35963668
const owner = "test_user";
35973669
const repo = "test_repo";
35983670
const env = { GITHUB_TOKEN: "github_token" };

0 commit comments

Comments
 (0)