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
21 changes: 13 additions & 8 deletions lib/success.js
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -57,16 +57,19 @@ export default async function success(pluginConfig, context, { Octokit }) {


const errors = []; const errors = [];


if (successComment === false || isEmpty(commits)) { if (
(successComment === false && releasedLabels === false) ||
isEmpty(commits)
) {
if (isEmpty(commits)) { if (isEmpty(commits)) {
logger.log("No commits found in release"); 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( logger.warn(
`DEPRECATION: 'false' for 'successComment' is deprecated and will be removed in a future major version. Use 'successCommentCondition' instead.`, `DEPRECATION: 'false' for 'successComment' is deprecated and will be removed in a future major version. Use 'successCommentCondition' instead.`,
); );
} else if (successCommentCondition === false) { } else if (successCommentCondition === false && releasedLabels === false) {
logger.log("Skip commenting on issues and pull requests."); logger.log("Skip commenting / adding labels on issues and pull requests.");
} else { } else {
const parser = issueParser( const parser = issueParser(
"github", "github",
Expand Down Expand Up @@ -202,10 +205,11 @@ export default async function success(pluginConfig, context, { Octokit }) {
return; return;
} }


try {
if (successComment !== false) {
const body = successComment const body = successComment
? template(successComment)({ ...context, issue }) ? template(successComment)({ ...context, issue })
: getSuccessComment(issue, releaseInfos, nextRelease); : getSuccessComment(issue, releaseInfos, nextRelease);
try {
const comment = { owner, repo, issue_number: issue.number, body }; const comment = { owner, repo, issue_number: issue.number, body };
debug("create comment: %O", comment); debug("create comment: %O", comment);
const { const {
Expand All @@ -219,6 +223,7 @@ export default async function success(pluginConfig, context, { Octokit }) {
issue.number, issue.number,
url, url,
); );
}


if (releasedLabels) { if (releasedLabels) {
const labels = releasedLabels.map((label) => const labels = releasedLabels.map((label) =>
Expand All @@ -242,18 +247,18 @@ export default async function success(pluginConfig, context, { Octokit }) {
} catch (error) { } catch (error) {
if (error.status === 403) { if (error.status === 403) {
logger.error( 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, issue.number,
); );
} else if (error.status === 404) { } else if (error.status === 404) {
logger.error( 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, issue.number,
); );
} else { } else {
errors.push(error); errors.push(error);
logger.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, issue.number,
); );
// Don't throw right away and continue to update other issues // 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 Original file line 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`, `https://api.github.local/repos/${owner}/${repo}/issues/1/labels`,
{}, {},
{ {
body: ["released"], labels: ["released"],
}, },
) )
.postOnce( .postOnce(
Expand Down Expand Up @@ -749,7 +749,7 @@ test("Verify, release and notify success", async (t) => {
.postOnce( .postOnce(
`https://api.github.local/repos/${owner}/${repo}/issues/1/labels`, `https://api.github.local/repos/${owner}/${repo}/issues/1/labels`,
{}, {},
{ body: ["released"] }, { labels: ["released"] },
) )
.getOnce( .getOnce(
`https://api.github.local/search/issues?q=${encodeURIComponent( `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`, `https://api.github.local/repos/${owner}/${repo}/issues/1/labels`,
{}, {},
{ {
body: ["released"], labels: ["released"],
}, },
) )
.postOnce( .postOnce(
Expand Down
Loading
Loading