| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 5e040f4 commit ec38c66
2 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -64,12 +64,12 @@ export default async function success(pluginConfig, context, { Octokit }) { | |||
| 64 | 64 | if (isEmpty(commits)) { | |
| 65 | 65 | logger.log("No commits found in release"); | |
| 66 | 66 | } | |
| 67 | - logger.log("Skip commenting on issues and pull requests."); | ||
| 67 | + logger.log("Skip commenting / adding labels on issues and pull requests."); | ||
| 68 | 68 | logger.warn( | |
| 69 | 69 | `DEPRECATION: 'false' for 'successComment' is deprecated and will be removed in a future major version. Use 'successCommentCondition' instead.`, | |
| 70 | 70 | ); | |
| 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."); | ||
| 73 | 73 | } else { | |
| 74 | 74 | const parser = issueParser( | |
| 75 | 75 | "github", | |
@@ -205,23 +205,25 @@ export default async function success(pluginConfig, context, { Octokit }) { | |||
| 205 | 205 | return; | |
| 206 | 206 | } | |
| 207 | 207 | ||
| 208 | - const body = successComment | ||
| 209 | - ? template(successComment)({ ...context, issue }) | ||
| 210 | - : getSuccessComment(issue, releaseInfos, nextRelease); | ||
| 211 | 208 | 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 | + } | ||
| 225 | 227 | ||
| 226 | 228 | if (releasedLabels) { | |
| 227 | 229 | const labels = releasedLabels.map((label) => | |
@@ -245,18 +247,18 @@ export default async function success(pluginConfig, context, { Octokit }) { | |||
| 245 | 247 | } catch (error) { | |
| 246 | 248 | if (error.status === 403) { | |
| 247 | 249 | 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.`, | ||
| 249 | 251 | issue.number, | |
| 250 | 252 | ); | |
| 251 | 253 | } else if (error.status === 404) { | |
| 252 | 254 | 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.`, | ||
| 254 | 256 | issue.number, | |
| 255 | 257 | ); | |
| 256 | 258 | } else { | |
| 257 | 259 | errors.push(error); | |
| 258 | 260 | 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.`, | ||
| 260 | 262 | issue.number, | |
| 261 | 263 | ); | |
| 262 | 264 | // Don't throw right away and continue to update other issues | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1992,13 +1992,13 @@ test("Ignore missing and forbidden issues/PRs", async (t) => { | |||
| 1992 | 1992 | ); | |
| 1993 | 1993 | t.true( | |
| 1994 | 1994 | 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.", | ||
| 1996 | 1996 | 2, | |
| 1997 | 1997 | ), | |
| 1998 | 1998 | ); | |
| 1999 | 1999 | t.true( | |
| 2000 | 2000 | 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.", | ||
| 2002 | 2002 | 3, | |
| 2003 | 2003 | ), | |
| 2004 | 2004 | ); | |
@@ -3225,7 +3225,7 @@ test("Ignore errors when adding comments and closing issues", async (t) => { | |||
| 3225 | 3225 | t.is(error2.status, 500); | |
| 3226 | 3226 | t.true( | |
| 3227 | 3227 | 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.", | ||
| 3229 | 3229 | 1, | |
| 3230 | 3230 | ), | |
| 3231 | 3231 | ); | |
@@ -3396,6 +3396,10 @@ test('Skip comment on on issues/PR if "successComment" is "false"', async (t) => | |||
| 3396 | 3396 | repository: { | |
| 3397 | 3397 | commit123: { | |
| 3398 | 3398 | associatedPullRequests: { | |
| 3399 | + pageInfo: { | ||
| 3400 | + endCursor: "NI", | ||
| 3401 | + hasNextPage: false, | ||
| 3402 | + }, | ||
| 3399 | 3403 | nodes: [prs[0]], | |
| 3400 | 3404 | }, | |
| 3401 | 3405 | }, | |
@@ -3411,6 +3415,32 @@ test('Skip comment on on issues/PR if "successComment" is "false"', async (t) => | |||
| 3411 | 3415 | {}, | |
| 3412 | 3416 | { labels: ["released"] }, | |
| 3413 | 3417 | ) | |
| 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 | + ) | ||
| 3414 | 3444 | .getOnce( | |
| 3415 | 3445 | `https://api.github.local/search/issues?q=${encodeURIComponent( | |
| 3416 | 3446 | "in:title", | |
@@ -3522,7 +3552,9 @@ test('Skip comment on issues/PR and skip label if "successComment" is "false" / | |||
| 3522 | 3552 | ); | |
| 3523 | 3553 | ||
| 3524 | 3554 | 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 | + ), | ||
| 3526 | 3558 | ); | |
| 3527 | 3559 | t.true(fetch.done()); | |
| 3528 | 3560 | }); | |
@@ -3553,13 +3585,53 @@ test('Does not comment/label on issues/PR if "successCommentCondition" is "false | |||
| 3553 | 3585 | .getOnce(`https://api.github.local/repos/${owner}/${repo}`, { | |
| 3554 | 3586 | full_name: `${owner}/${repo}`, | |
| 3555 | 3587 | }) | |
| 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 | + }, | ||
| 3560 | 3606 | }, | |
| 3561 | 3607 | }, | |
| 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 | + ) | ||
| 3563 | 3635 | .getOnce( | |
| 3564 | 3636 | `https://api.github.local/search/issues?q=${encodeURIComponent( | |
| 3565 | 3637 | "in:title", | |
@@ -3592,7 +3664,7 @@ test('Does not comment/label on issues/PR if "successCommentCondition" is "false | |||
| 3592 | 3664 | t.true(fetch.done()); | |
| 3593 | 3665 | }); | |
| 3594 | 3666 | ||
| 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) => { | ||
| 3596 | 3668 | const owner = "test_user"; | |
| 3597 | 3669 | const repo = "test_repo"; | |
| 3598 | 3670 | const env = { GITHUB_TOKEN: "github_token" }; | |
| Back | FazBrowse Home | New Git URL |
0 commit comments