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 for releasedLabels with successComment set to false #861

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
51 changes: 28 additions & 23 deletions lib/success.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,16 +57,19 @@ export default async function success(pluginConfig, context, { Octokit }) {

const errors = [];

if (successComment === false || isEmpty(commits)) {
if (
(successComment === false && releasedLabels === false) ||
isEmpty(commits)
) {
if (isEmpty(commits)) {
logger.log("No commits found in release");
}
logger.log("Skip commenting on issues and pull requests.");
logger.log("Skip commenting / adding labels on issues and pull requests.");
logger.warn(
`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 if (successCommentCondition === false && releasedLabels === false) {
logger.log("Skip commenting / adding labels on issues and pull requests.");
} else {
const parser = issueParser(
"github",
Expand Down Expand Up @@ -202,23 +205,25 @@ export default async function success(pluginConfig, context, { Octokit }) {
return;
}

const body = successComment
? template(successComment)({ ...context, issue })
: getSuccessComment(issue, releaseInfos, nextRelease);
try {
const comment = { owner, repo, issue_number: issue.number, body };
debug("create comment: %O", comment);
const {
data: { html_url: url },
} = await octokit.request(
"POST /repos/{owner}/{repo}/issues/{issue_number}/comments",
comment,
);
logger.log(
`Added comment to ${issueOrPR} #%d: %s`,
issue.number,
url,
);
if (successComment !== false) {
const body = successComment
? template(successComment)({ ...context, issue })
: getSuccessComment(issue, releaseInfos, nextRelease);
const comment = { owner, repo, issue_number: issue.number, body };
debug("create comment: %O", comment);
const {
data: { html_url: url },
} = await octokit.request(
"POST /repos/{owner}/{repo}/issues/{issue_number}/comments",
comment,
);
logger.log(
`Added comment to ${issueOrPR} #%d: %s`,
issue.number,
url,
);
}

if (releasedLabels) {
const labels = releasedLabels.map((label) =>
Expand All @@ -242,18 +247,18 @@ export default async function success(pluginConfig, context, { Octokit }) {
} catch (error) {
if (error.status === 403) {
logger.error(
`Not allowed to add a comment to the issue/PR #%d.`,
`Not allowed to add a comment/label to the issue/PR #%d.`,
issue.number,
);
} else if (error.status === 404) {
logger.error(
`Failed to add a comment to the issue/PR #%d as it doesn't exist.`,
`Failed to add a comment/label to the issue/PR #%d as it doesn't exist.`,
issue.number,
);
} else {
errors.push(error);
logger.error(
`Failed to add a comment to the issue/PR #%d.`,
`Failed to add a comment/label to the issue/PR #%d.`,
issue.number,
);
// Don't throw right away and continue to update other issues
Expand Down
6 changes: 3 additions & 3 deletions test/integration.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -501,7 +501,7 @@ test("Comment and add labels on PR included in the releases", async (t) => {
`https://api.github.local/repos/${owner}/${repo}/issues/1/labels`,
{},
{
body: ["released"],
labels: ["released"],
},
)
.postOnce(
Expand Down Expand Up @@ -749,7 +749,7 @@ test("Verify, release and notify success", async (t) => {
.postOnce(
`https://api.github.local/repos/${owner}/${repo}/issues/1/labels`,
{},
{ body: ["released"] },
{ labels: ["released"] },
)
.getOnce(
`https://api.github.local/search/issues?q=${encodeURIComponent(
Expand Down Expand Up @@ -922,7 +922,7 @@ test("Verify, update release and notify success", async (t) => {
`https://api.github.local/repos/${owner}/${repo}/issues/1/labels`,
{},
{
body: ["released"],
labels: ["released"],
},
)
.postOnce(
Expand Down
Loading