diff --git a/lib/platform/azure/index.ts b/lib/platform/azure/index.ts index 95b3ead1a948041ac5e18d75c1c052b138b6caeb..44ffff1b2b2e6065169837920b26d1b7e15bb830 100644 --- a/lib/platform/azure/index.ts +++ b/lib/platform/azure/index.ts @@ -17,6 +17,7 @@ import { VulnerabilityAlert, CreatePRConfig, BranchStatusConfig, + EnsureCommentConfig, } from '../common'; import { sanitize } from '../../util/sanitize'; import { smartTruncate } from '../utils/pr-body'; @@ -476,12 +477,12 @@ export async function updatePr( await azureApiGit.updatePullRequest(objToUpdate, config.repoId, prNo); } -export async function ensureComment( - issueNo: number, - topic: string | null, - content: string -): Promise<void> { - logger.debug(`ensureComment(${issueNo}, ${topic}, content)`); +export async function ensureComment({ + number, + topic, + content, +}: EnsureCommentConfig): Promise<void> { + logger.debug(`ensureComment(${number}, ${topic}, content)`); const body = `### ${topic}\n\n${sanitize(content)}`; const azureApiGit = await azureApi.gitApi(); await azureApiGit.createThread( @@ -490,7 +491,7 @@ export async function ensureComment( status: 1, }, config.repoId, - issueNo + number ); } @@ -578,11 +579,11 @@ export async function addAssignees( assignees: string[] ): Promise<void> { logger.trace(`addAssignees(${issueNo}, ${assignees})`); - await ensureComment( - issueNo, - 'Add Assignees', - assignees.map(a => `@<${a}>`).join(', ') - ); + await ensureComment({ + number: issueNo, + topic: 'Add Assignees', + content: assignees.map(a => `@<${a}>`).join(', '), + }); } /** diff --git a/lib/platform/bitbucket-server/index.ts b/lib/platform/bitbucket-server/index.ts index c534bc2404d36b11c6824f196e201a42064ba08a..9a1f57c45206a4e801f15ab020ddf86d377f3990 100644 --- a/lib/platform/bitbucket-server/index.ts +++ b/lib/platform/bitbucket-server/index.ts @@ -16,6 +16,7 @@ import { GotResponse, CreatePRConfig, BranchStatusConfig, + EnsureCommentConfig, } from '../common'; import { sanitize } from '../../util/sanitize'; import { smartTruncate } from '../utils/pr-body'; @@ -790,20 +791,20 @@ async function deleteComment(prNo: number, commentId: number): Promise<void> { ); } -export async function ensureComment( - prNo: number, - topic: string | null, - rawContent: string -): Promise<boolean> { - const content = sanitize(rawContent); +export async function ensureComment({ + number, + topic, + content, +}: EnsureCommentConfig): Promise<boolean> { + const sanitizedContent = sanitize(content); try { - const comments = await getComments(prNo); + const comments = await getComments(number); let body: string; let commentId: number | undefined; let commentNeedsUpdating: boolean | undefined; if (topic) { - logger.debug(`Ensuring comment "${topic}" in #${prNo}`); - body = `### ${topic}\n\n${content}`; + logger.debug(`Ensuring comment "${topic}" in #${number}`); + body = `### ${topic}\n\n${sanitizedContent}`; comments.forEach(comment => { if (comment.text.startsWith(`### ${topic}\n\n`)) { commentId = comment.id; @@ -811,8 +812,8 @@ export async function ensureComment( } }); } else { - logger.debug(`Ensuring content-only comment in #${prNo}`); - body = `${content}`; + logger.debug(`Ensuring content-only comment in #${number}`); + body = `${sanitizedContent}`; comments.forEach(comment => { if (comment.text === body) { commentId = comment.id; @@ -821,14 +822,17 @@ export async function ensureComment( }); } if (!commentId) { - await addComment(prNo, body); + await addComment(number, body); logger.info( - { repository: config.repository, prNo, topic }, + { repository: config.repository, prNo: number, topic }, 'Comment added' ); } else if (commentNeedsUpdating) { - await editComment(prNo, commentId, body); - logger.info({ repository: config.repository, prNo }, 'Comment updated'); + await editComment(number, commentId, body); + logger.info( + { repository: config.repository, prNo: number }, + 'Comment updated' + ); } else { logger.debug('Comment is already update-to-date'); } diff --git a/lib/platform/bitbucket/comments.ts b/lib/platform/bitbucket/comments.ts index 51cfd78ce980faece3204e2eb13c92e213d7cd14..cda6427189b571ee742649a533df748a4851ebba 100644 --- a/lib/platform/bitbucket/comments.ts +++ b/lib/platform/bitbucket/comments.ts @@ -1,6 +1,7 @@ import { logger } from '../../logger'; import { Config, accumulateValues } from './utils'; import { api } from './bb-got-wrapper'; +import { EnsureCommentConfig } from '../common'; interface Comment { content: { raw: string }; @@ -9,6 +10,10 @@ interface Comment { export type CommentsConfig = Pick<Config, 'repository'>; +interface EnsureBitBucketCommentConfig extends EnsureCommentConfig { + config: CommentsConfig; +} + async function getComments( config: CommentsConfig, prNo: number @@ -58,12 +63,12 @@ async function deleteComment( ); } -export async function ensureComment( - config: CommentsConfig, - prNo: number, - topic: string | null, - content: string -): Promise<boolean> { +export async function ensureComment({ + config, + number: prNo, + topic, + content, +}: EnsureBitBucketCommentConfig): Promise<boolean> { try { const comments = await getComments(config, prNo); let body: string; diff --git a/lib/platform/bitbucket/index.ts b/lib/platform/bitbucket/index.ts index 2411c79fa956a1e999f01398436109b54b36b75f..79bd2ce4fa83986b4c2897bb4c3d74a1f2ad13a5 100644 --- a/lib/platform/bitbucket/index.ts +++ b/lib/platform/bitbucket/index.ts @@ -17,6 +17,7 @@ import { CreatePRConfig, EnsureIssueConfig, BranchStatusConfig, + EnsureCommentConfig, } from '../common'; import { sanitize } from '../../util/sanitize'; import { smartTruncate } from '../utils/pr-body'; @@ -657,13 +658,18 @@ export /* istanbul ignore next */ function deleteLabel(): never { throw new Error('deleteLabel not implemented'); } -export function ensureComment( - prNo: number, - topic: string | null, - content: string -): Promise<boolean> { +export function ensureComment({ + number, + topic, + content, +}: EnsureCommentConfig): Promise<boolean> { // https://developer.atlassian.com/bitbucket/api/2/reference/search?q=pullrequest+comment - return comments.ensureComment(config, prNo, topic, sanitize(content)); + return comments.ensureComment({ + config, + number, + topic, + content: sanitize(content), + }); } export function ensureCommentRemoval( diff --git a/lib/platform/common.ts b/lib/platform/common.ts index 34f105ed1d440622216e88f369a2b4463c221cd1..93e8cc07e77585f36719766366545788a08b7c37 100644 --- a/lib/platform/common.ts +++ b/lib/platform/common.ts @@ -129,6 +129,11 @@ export interface BranchStatusConfig { state: string | null; url?: string; } +export interface EnsureCommentConfig { + number: number; + topic: string; + content: string; +} /** * TODO: Proper typing */ @@ -165,11 +170,7 @@ export interface Platform { getBranchStatusCheck(branchName: string, context: string): Promise<string>; ensureCommentRemoval(number: number, subject: string): Promise<void>; deleteBranch(branchName: string, closePr?: boolean): Promise<void>; - ensureComment( - number: number, - subject: string, - content: string - ): Promise<boolean>; + ensureComment(ensureComment: EnsureCommentConfig): Promise<boolean>; branchExists(branchName: string): Promise<boolean>; setBaseBranch(baseBranch: string): Promise<void>; commitFilesToBranch(commitFile: CommitFilesConfig): Promise<void>; diff --git a/lib/platform/github/index.ts b/lib/platform/github/index.ts index 372b3d40582119b82791f8fce141b9bb7725b43c..1d4d9ece810f604bc26a354d7c7f088df9b2ec83 100644 --- a/lib/platform/github/index.ts +++ b/lib/platform/github/index.ts @@ -16,6 +16,7 @@ import { CreatePRConfig, EnsureIssueConfig, BranchStatusConfig, + EnsureCommentConfig, } from '../common'; import { configFileNames } from '../../config/app-strings'; @@ -1500,20 +1501,20 @@ async function getComments(issueNo: number): Promise<Comment[]> { } } -export async function ensureComment( - issueNo: number, - topic: string | null, - rawContent: string -): Promise<boolean> { - const content = sanitize(rawContent); +export async function ensureComment({ + number, + topic, + content, +}: EnsureCommentConfig): Promise<boolean> { + const sanitizedContent = sanitize(content); try { - const comments = await getComments(issueNo); + const comments = await getComments(number); let body: string; let commentId: number | null = null; let commentNeedsUpdating = false; if (topic) { - logger.debug(`Ensuring comment "${topic}" in #${issueNo}`); - body = `### ${topic}\n\n${content}`; + logger.debug(`Ensuring comment "${topic}" in #${number}`); + body = `### ${topic}\n\n${sanitizedContent}`; comments.forEach(comment => { if (comment.body.startsWith(`### ${topic}\n\n`)) { commentId = comment.id; @@ -1521,8 +1522,8 @@ export async function ensureComment( } }); } else { - logger.debug(`Ensuring content-only comment in #${issueNo}`); - body = `${content}`; + logger.debug(`Ensuring content-only comment in #${number}`); + body = `${sanitizedContent}`; comments.forEach(comment => { if (comment.body === body) { commentId = comment.id; @@ -1531,15 +1532,15 @@ export async function ensureComment( }); } if (!commentId) { - await addComment(issueNo, body); + await addComment(number, body); logger.info( - { repository: config.repository, issueNo, topic }, + { repository: config.repository, issueNo: number, topic }, 'Comment added' ); } else if (commentNeedsUpdating) { await editComment(commentId, body); logger.info( - { repository: config.repository, issueNo }, + { repository: config.repository, issueNo: number }, 'Comment updated' ); } else { diff --git a/lib/platform/gitlab/index.ts b/lib/platform/gitlab/index.ts index b10c7edf5d605f5908d51de565babc87f68ec2dc..b76614abb847f9227c8421c57ec585bda50760c7 100644 --- a/lib/platform/gitlab/index.ts +++ b/lib/platform/gitlab/index.ts @@ -15,6 +15,7 @@ import { CreatePRConfig, EnsureIssueConfig, BranchStatusConfig, + EnsureCommentConfig, } from '../common'; import { configFileNames } from '../../config/app-strings'; import { logger } from '../../logger'; @@ -842,22 +843,22 @@ async function deleteComment( ); } -export async function ensureComment( - issueNo: number, - topic: string | null | undefined, - rawContent: string -): Promise<void> { - const content = sanitize(rawContent); +export async function ensureComment({ + number, + topic, + content, +}: EnsureCommentConfig): Promise<void> { + const sanitizedContent = sanitize(content); const massagedTopic = topic ? topic.replace(/Pull Request/g, 'Merge Request').replace(/PR/g, 'MR') : topic; - const comments = await getComments(issueNo); + const comments = await getComments(number); let body: string; let commentId; let commentNeedsUpdating; if (topic) { - logger.debug(`Ensuring comment "${massagedTopic}" in #${issueNo}`); - body = `### ${topic}\n\n${content}`; + logger.debug(`Ensuring comment "${massagedTopic}" in #${number}`); + body = `### ${topic}\n\n${sanitizedContent}`; body = body.replace(/Pull Request/g, 'Merge Request').replace(/PR/g, 'MR'); comments.forEach((comment: { body: string; id: number }) => { if (comment.body.startsWith(`### ${massagedTopic}\n\n`)) { @@ -866,8 +867,8 @@ export async function ensureComment( } }); } else { - logger.debug(`Ensuring content-only comment in #${issueNo}`); - body = `${content}`; + logger.debug(`Ensuring content-only comment in #${number}`); + body = `${sanitizedContent}`; comments.forEach((comment: { body: string; id: number }) => { if (comment.body === body) { commentId = comment.id; @@ -876,11 +877,17 @@ export async function ensureComment( }); } if (!commentId) { - await addComment(issueNo, body); - logger.info({ repository: config.repository, issueNo }, 'Added comment'); + await addComment(number, body); + logger.info( + { repository: config.repository, issueNo: number }, + 'Added comment' + ); } else if (commentNeedsUpdating) { - await editComment(issueNo, commentId, body); - logger.info({ repository: config.repository, issueNo }, 'Updated comment'); + await editComment(number, commentId, body); + logger.info( + { repository: config.repository, issueNo: number }, + 'Updated comment' + ); } else { logger.debug('Comment is already update-to-date'); } diff --git a/lib/workers/branch/index.ts b/lib/workers/branch/index.ts index 4929c1771be5f85cc8b356e4e7d6c398347d4b13..893dd2b4011aa64e85a8e4104a750ddbb2d43333 100644 --- a/lib/workers/branch/index.ts +++ b/lib/workers/branch/index.ts @@ -94,7 +94,7 @@ export async function processBranch( 'Closed PR already exists. Skipping branch.' ); if (existingPr.state === 'closed') { - const subject = `Renovate Ignore Notification`; + const topic = `Renovate Ignore Notification`; let content; if (config.updateType === 'major') { content = `As this PR has been closed unmerged, Renovate will ignore this upgrade and you will not receive PRs for *any* future ${config.newMajor}.x releases. However, if you upgrade to ${config.newMajor}.x manually then Renovate will then reenable updates for minor and patch updates automatically.`; @@ -112,7 +112,11 @@ export async function processBranch( existingPr.number ); } else { - await platform.ensureComment(existingPr.number, subject, content); + await platform.ensureComment({ + number: existingPr.number, + topic, + content, + }); } } if (branchExists) { @@ -165,7 +169,7 @@ export async function processBranch( (branchPr.targetBranch && branchPr.targetBranch !== branchConfig.baseBranch) ) { - const subject = 'PR has been edited'; + const topic = 'PR has been edited'; if (masterIssueCheck || config.rebaseRequested) { if (config.dryRun) { logger.info( @@ -173,7 +177,7 @@ export async function processBranch( branchPr.number ); } else { - await platform.ensureCommentRemoval(branchPr.number, subject); + await platform.ensureCommentRemoval(branchPr.number, topic); } } else { let content = emojify( @@ -186,7 +190,11 @@ export async function processBranch( 'DRY-RUN: ensure comment in PR #' + branchPr.number ); } else { - await platform.ensureComment(branchPr.number, subject, content); + await platform.ensureComment({ + number: branchPr.number, + topic, + content, + }); } } return 'pr-edited'; @@ -496,7 +504,11 @@ export async function processBranch( pr.number ); } else { - await platform.ensureComment(pr.number, topic, content); + await platform.ensureComment({ + number: pr.number, + topic, + content, + }); // TODO: remoe this soon once they're all cleared out await platform.ensureCommentRemoval( pr.number, diff --git a/lib/workers/pr/index.ts b/lib/workers/pr/index.ts index d5fb7d56111b00d9b7976e87d18eb86a3bd8ee40..ca0be895dde68e8c0dd59542f57f6ee3e6d4916f 100644 --- a/lib/workers/pr/index.ts +++ b/lib/workers/pr/index.ts @@ -353,7 +353,7 @@ export async function ensurePr( config.branchAutomergeFailureMessage && !config.suppressNotifications.includes('branchAutomergeFailure') ) { - const subject = 'Branch automerge failure'; + const topic = 'Branch automerge failure'; let content = 'This PR was configured for branch automerge, however this is not possible so it has been raised as a PR instead.'; if (config.branchAutomergeFailureMessage === 'branch status error') { @@ -364,7 +364,11 @@ export async function ensurePr( if (config.dryRun) { logger.info('Would add comment to PR #' + pr.number); } else { - await platform.ensureComment(pr.number, subject, content); + await platform.ensureComment({ + number: pr.number, + topic, + content, + }); } } // Skip assign and review if automerging PR @@ -446,7 +450,11 @@ export async function checkAutoMerge(pr: Pr, config): Promise<boolean> { ); return false; } - return platform.ensureComment(pr.number, null, automergeComment); + return platform.ensureComment({ + number: pr.number, + topic: null, + content: automergeComment, + }); } // Let's merge this logger.debug(`Automerging #${pr.number}`); diff --git a/lib/workers/repository/finalise/prune.ts b/lib/workers/repository/finalise/prune.ts index 96994b89fcbc527468cd788756340a83a55b6cd8..d78e4022e8f2277ff36289d227b397fb11722dc5 100644 --- a/lib/workers/repository/finalise/prune.ts +++ b/lib/workers/repository/finalise/prune.ts @@ -35,11 +35,12 @@ async function cleanUpBranches( if (dryRun) { logger.info(`DRY-RUN: Would add Autoclosing Skipped comment to PR`); } else { - await platform.ensureComment( - pr.number, - 'Autoclosing Skipped', - 'This PR has been flagged for autoclosing, however it is being skipped due to the branch being already modified. Please close/delete it manually or report a bug if you think this is in error.' - ); + await platform.ensureComment({ + number: pr.number, + topic: 'Autoclosing Skipped', + content: + 'This PR has been flagged for autoclosing, however it is being skipped due to the branch being already modified. Please close/delete it manually or report a bug if you think this is in error.', + }); } } } else if (dryRun) { diff --git a/lib/workers/repository/finalise/validate.ts b/lib/workers/repository/finalise/validate.ts index 9d67512c26f8c4c1619d90a897753722a29ae517..21d42d49b9b0e51bf0f515510927e07d4bfbd9a0 100644 --- a/lib/workers/repository/finalise/validate.ts +++ b/lib/workers/repository/finalise/validate.ts @@ -87,18 +87,22 @@ export async function validatePrs(config: RenovateConfig): Promise<void> { // if the PR has renovate files then we set a status no matter what let status: 'failure' | 'success'; let description: string; - const subject = `Renovate Configuration Errors`; + const topic = `Renovate Configuration Errors`; if (validations.length) { const content = validations .map(v => `\`${v.file}\`: ${v.message}`) .join('\n\n'); - await platform.ensureComment(pr.number, subject, content); + await platform.ensureComment({ + number: pr.number, + topic, + content, + }); status = 'failure'; description = `Renovate config validation failed`; // GitHub limit } else { description = `Renovate config is valid`; status = 'success'; - await platform.ensureCommentRemoval(pr.number, subject); + await platform.ensureCommentRemoval(pr.number, topic); } // istanbul ignore else if (pr.sourceRepo === config.repository) { diff --git a/lib/workers/repository/onboarding/branch/check.ts b/lib/workers/repository/onboarding/branch/check.ts index 85b3cf9c4bfde8d2ad14dc0b92ceb0c35a5d6dac..8b047417d82158101c8aa63427f59693b821264d 100644 --- a/lib/workers/repository/onboarding/branch/check.ts +++ b/lib/workers/repository/onboarding/branch/check.ts @@ -77,11 +77,11 @@ export const isOnboarded = async (config: RenovateConfig): Promise<boolean> => { logger.info('Repo is not onboarded and no merged PRs exist'); if (!config.suppressNotifications.includes('onboardingClose')) { // ensure PR comment - await platform.ensureComment( - pr.number, - `Renovate is disabled`, - `Renovate is disabled due to lack of config. If you wish to reenable it, you can either (a) commit a config file to your base branch, or (b) rename this closed PR to trigger a replacement onboarding PR.` - ); + await platform.ensureComment({ + number: pr.number, + topic: `Renovate is disabled`, + content: `Renovate is disabled due to lack of config. If you wish to reenable it, you can either (a) commit a config file to your base branch, or (b) rename this closed PR to trigger a replacement onboarding PR.`, + }); } throw new Error(REPOSITORY_DISABLED); }; diff --git a/test/platform/azure/index.spec.ts b/test/platform/azure/index.spec.ts index cd5add0e2eea2ded54952c8fc968380d5f187c32..c75c41c0deb6d63b7654be592e980164ee8d86d9 100644 --- a/test/platform/azure/index.spec.ts +++ b/test/platform/azure/index.spec.ts @@ -609,7 +609,11 @@ describe('platform/azure', () => { createThread: jest.fn(() => [{ id: 123 }]), } as any) ); - await azure.ensureComment(42, 'some-subject', 'some\ncontent'); + await azure.ensureComment({ + number: 42, + topic: 'some-subject', + content: 'some\ncontent', + }); expect(azureApi.gitApi.mock.calls).toMatchSnapshot(); }); }); diff --git a/test/platform/bitbucket-server/index.spec.ts b/test/platform/bitbucket-server/index.spec.ts index 6b08d695f0d01a20027bc2be0b0853ce37516ca5..454f0092efb30feabc708878b66bc7ce29dc43c0 100644 --- a/test/platform/bitbucket-server/index.spec.ts +++ b/test/platform/bitbucket-server/index.spec.ts @@ -331,9 +331,13 @@ describe('platform/bitbucket-server', () => { describe('ensureComment()', () => { it('does not throw', async () => { expect.assertions(2); - expect(await bitbucket.ensureComment(3, 'topic', 'content')).toBe( - false - ); + expect( + await bitbucket.ensureComment({ + number: 3, + topic: 'topic', + content: 'content', + }) + ).toBe(false); expect(api.get.mock.calls).toMatchSnapshot(); }); @@ -342,16 +346,26 @@ describe('platform/bitbucket-server', () => { await initRepo(); api.get.mockClear(); - expect(await bitbucket.ensureComment(5, 'topic', 'content')).toBe( - true - ); + expect( + await bitbucket.ensureComment({ + number: 5, + topic: 'topic', + content: 'content', + }) + ).toBe(true); expect(api.get.mock.calls).toMatchSnapshot(); expect(api.post).toHaveBeenCalledTimes(1); api.get.mockClear(); api.post.mockClear(); - expect(await bitbucket.ensureComment(5, null, 'content')).toBe(true); + expect( + await bitbucket.ensureComment({ + number: 5, + topic: null, + content: 'content', + }) + ).toBe(true); expect(api.get.mock.calls).toMatchSnapshot(); expect(api.post).toHaveBeenCalledTimes(1); }); @@ -362,7 +376,11 @@ describe('platform/bitbucket-server', () => { api.get.mockClear(); expect( - await bitbucket.ensureComment(5, 'some-subject', 'some\ncontent') + await bitbucket.ensureComment({ + number: 5, + topic: 'some-subject', + content: 'some\ncontent', + }) ).toBe(true); expect(api.get.mock.calls).toMatchSnapshot(); expect(api.post).toHaveBeenCalledTimes(0); @@ -371,9 +389,13 @@ describe('platform/bitbucket-server', () => { api.get.mockClear(); api.put.mockClear(); - expect(await bitbucket.ensureComment(5, null, 'some\ncontent')).toBe( - true - ); + expect( + await bitbucket.ensureComment({ + number: 5, + topic: null, + content: 'some\ncontent', + }) + ).toBe(true); expect(api.get.mock.calls).toMatchSnapshot(); expect(api.post).toHaveBeenCalledTimes(1); expect(api.put).toHaveBeenCalledTimes(0); @@ -385,7 +407,11 @@ describe('platform/bitbucket-server', () => { api.get.mockClear(); expect( - await bitbucket.ensureComment(5, 'some-subject', 'blablabla') + await bitbucket.ensureComment({ + number: 5, + topic: 'some-subject', + content: 'blablabla', + }) ).toBe(true); expect(api.get.mock.calls).toMatchSnapshot(); expect(api.put).toHaveBeenCalledTimes(0); @@ -393,7 +419,13 @@ describe('platform/bitbucket-server', () => { api.get.mockClear(); api.put.mockClear(); - expect(await bitbucket.ensureComment(5, null, '!merge')).toBe(true); + expect( + await bitbucket.ensureComment({ + number: 5, + topic: null, + content: '!merge', + }) + ).toBe(true); expect(api.get.mock.calls).toMatchSnapshot(); expect(api.put).toHaveBeenCalledTimes(0); }); diff --git a/test/platform/bitbucket/comments.spec.ts b/test/platform/bitbucket/comments.spec.ts index 05c47a81940e29e233ea7081489789e6393dcce7..cf31b77e4c4c318e3d465a5817ab58dbf8cb3278 100644 --- a/test/platform/bitbucket/comments.spec.ts +++ b/test/platform/bitbucket/comments.spec.ts @@ -36,9 +36,14 @@ describe('platform/comments', () => { describe('ensureComment()', () => { it('does not throw', async () => { expect.assertions(2); - expect(await comments.ensureComment(config, 3, 'topic', 'content')).toBe( - false - ); + expect( + await comments.ensureComment({ + config, + number: 3, + topic: 'topic', + content: 'content', + }) + ).toBe(false); expect(api.get.mock.calls).toMatchSnapshot(); }); @@ -46,18 +51,28 @@ describe('platform/comments', () => { expect.assertions(6); api.get.mockClear(); - expect(await comments.ensureComment(config, 5, 'topic', 'content')).toBe( - true - ); + expect( + await comments.ensureComment({ + config, + number: 5, + topic: 'topic', + content: 'content', + }) + ).toBe(true); expect(api.get.mock.calls).toMatchSnapshot(); expect(api.post).toHaveBeenCalledTimes(1); api.get.mockClear(); api.post.mockClear(); - expect(await comments.ensureComment(config, 5, null, 'content')).toBe( - true - ); + expect( + await comments.ensureComment({ + config, + number: 5, + topic: null, + content: 'content', + }) + ).toBe(true); expect(api.get.mock.calls).toMatchSnapshot(); expect(api.post).toHaveBeenCalledTimes(1); }); @@ -67,7 +82,12 @@ describe('platform/comments', () => { api.get.mockClear(); expect( - await comments.ensureComment(config, 5, 'some-subject', 'some\ncontent') + await comments.ensureComment({ + config, + number: 5, + topic: 'some-subject', + content: 'some\ncontent', + }) ).toBe(true); expect(api.get.mock.calls).toMatchSnapshot(); expect(api.post).toHaveBeenCalledTimes(0); @@ -77,7 +97,12 @@ describe('platform/comments', () => { api.put.mockClear(); expect( - await comments.ensureComment(config, 5, null, 'some\ncontent') + await comments.ensureComment({ + config, + number: 5, + topic: null, + content: 'some\ncontent', + }) ).toBe(true); expect(api.get.mock.calls).toMatchSnapshot(); expect(api.post).toHaveBeenCalledTimes(1); @@ -89,7 +114,12 @@ describe('platform/comments', () => { api.get.mockClear(); expect( - await comments.ensureComment(config, 5, 'some-subject', 'blablabla') + await comments.ensureComment({ + config, + number: 5, + topic: 'some-subject', + content: 'blablabla', + }) ).toBe(true); expect(api.get.mock.calls).toMatchSnapshot(); expect(api.put).toHaveBeenCalledTimes(0); @@ -97,9 +127,14 @@ describe('platform/comments', () => { api.get.mockClear(); api.put.mockClear(); - expect(await comments.ensureComment(config, 5, null, '!merge')).toBe( - true - ); + expect( + await comments.ensureComment({ + config, + number: 5, + topic: null, + content: '!merge', + }) + ).toBe(true); expect(api.get.mock.calls).toMatchSnapshot(); expect(api.put).toHaveBeenCalledTimes(0); }); diff --git a/test/platform/bitbucket/index.spec.ts b/test/platform/bitbucket/index.spec.ts index 39f97af35be112f4614ba49224817d0b509cb7d7..029ff0f820fbafb635d0e811d8072a490a68100b 100644 --- a/test/platform/bitbucket/index.spec.ts +++ b/test/platform/bitbucket/index.spec.ts @@ -361,7 +361,11 @@ describe('platform/bitbucket', () => { describe('ensureComment()', () => { it('does not throw', async () => { - await bitbucket.ensureComment(3, 'topic', 'content'); + await bitbucket.ensureComment({ + number: 3, + topic: 'topic', + content: 'content', + }); }); }); diff --git a/test/platform/github/index.spec.ts b/test/platform/github/index.spec.ts index a56630f95476293ca654717a4b3eb632485ccf5d..0ccc9bf7fb3fd7b855e67175e34b422c794f98a9 100644 --- a/test/platform/github/index.spec.ts +++ b/test/platform/github/index.spec.ts @@ -1320,7 +1320,11 @@ describe('platform/github', () => { repository: 'some/repo', }); api.get.mockReturnValueOnce({ body: [] } as any); - await github.ensureComment(42, 'some-subject', 'some\ncontent'); + await github.ensureComment({ + number: 42, + topic: 'some-subject', + content: 'some\ncontent', + }); expect(api.post).toHaveBeenCalledTimes(2); expect(api.post.mock.calls[1]).toMatchSnapshot(); }); @@ -1334,7 +1338,11 @@ describe('platform/github', () => { body: graphqlClosedPullrequests, } as any) ); - await github.ensureComment(2499, 'some-subject', 'some\ncontent'); + await github.ensureComment({ + number: 2499, + topic: 'some-subject', + content: 'some\ncontent', + }); expect(api.post).toHaveBeenCalledTimes(2); expect(api.patch).toHaveBeenCalledTimes(0); }); @@ -1345,7 +1353,11 @@ describe('platform/github', () => { api.get.mockReturnValueOnce({ body: [{ id: 1234, body: '### some-subject\n\nblablabla' }], } as any); - await github.ensureComment(42, 'some-subject', 'some\ncontent'); + await github.ensureComment({ + number: 42, + topic: 'some-subject', + content: 'some\ncontent', + }); expect(api.post).toHaveBeenCalledTimes(1); expect(api.patch).toHaveBeenCalledTimes(1); expect(api.patch.mock.calls).toMatchSnapshot(); @@ -1357,7 +1369,11 @@ describe('platform/github', () => { api.get.mockReturnValueOnce({ body: [{ id: 1234, body: '### some-subject\n\nsome\ncontent' }], } as any); - await github.ensureComment(42, 'some-subject', 'some\ncontent'); + await github.ensureComment({ + number: 42, + topic: 'some-subject', + content: 'some\ncontent', + }); expect(api.post).toHaveBeenCalledTimes(1); expect(api.patch).toHaveBeenCalledTimes(0); }); @@ -1368,7 +1384,11 @@ describe('platform/github', () => { api.get.mockReturnValueOnce({ body: [{ id: 1234, body: '!merge' }], } as any); - await github.ensureComment(42, null, '!merge'); + await github.ensureComment({ + number: 42, + topic: null, + content: '!merge', + }); expect(api.post).toHaveBeenCalledTimes(1); expect(api.patch).toHaveBeenCalledTimes(0); }); diff --git a/test/platform/gitlab/index.spec.ts b/test/platform/gitlab/index.spec.ts index 254171e3db0c4dea221e360e73d65d035bdfff7e..d547309b4b97321f1c176067e643a9f7806a296b 100644 --- a/test/platform/gitlab/index.spec.ts +++ b/test/platform/gitlab/index.spec.ts @@ -707,7 +707,11 @@ describe('platform/gitlab', () => { it('add comment if not found', async () => { await initRepo({ repository: 'some/repo', token: 'token' }); api.get.mockReturnValueOnce({ body: [] } as any); - await gitlab.ensureComment(42, 'some-subject', 'some\ncontent'); + await gitlab.ensureComment({ + number: 42, + topic: 'some-subject', + content: 'some\ncontent', + }); expect(api.post).toHaveBeenCalledTimes(1); expect(api.post.mock.calls).toMatchSnapshot(); }); @@ -716,7 +720,11 @@ describe('platform/gitlab', () => { api.get.mockReturnValueOnce({ body: [{ id: 1234, body: '### some-subject\n\nblablabla' }], } as any); - await gitlab.ensureComment(42, 'some-subject', 'some\ncontent'); + await gitlab.ensureComment({ + number: 42, + topic: 'some-subject', + content: 'some\ncontent', + }); expect(api.post).toHaveBeenCalledTimes(0); expect(api.put).toHaveBeenCalledTimes(1); expect(api.put.mock.calls).toMatchSnapshot(); @@ -726,7 +734,11 @@ describe('platform/gitlab', () => { api.get.mockReturnValueOnce({ body: [{ id: 1234, body: '### some-subject\n\nsome\ncontent' }], } as any); - await gitlab.ensureComment(42, 'some-subject', 'some\ncontent'); + await gitlab.ensureComment({ + number: 42, + topic: 'some-subject', + content: 'some\ncontent', + }); expect(api.post).toHaveBeenCalledTimes(0); expect(api.put).toHaveBeenCalledTimes(0); }); @@ -735,7 +747,11 @@ describe('platform/gitlab', () => { api.get.mockReturnValueOnce({ body: [{ id: 1234, body: '!merge' }], } as any); - await gitlab.ensureComment(42, null, '!merge'); + await gitlab.ensureComment({ + number: 42, + topic: null, + content: '!merge', + }); expect(api.post).toHaveBeenCalledTimes(0); expect(api.put).toHaveBeenCalledTimes(0); });