diff --git a/lib/platform/azure/index.ts b/lib/platform/azure/index.ts index dcaf8021226f83c5e7ad1e4bdbbe6f9ff6b8d57a..a7c1d7fea48a699ed75c29bee7fff5df954e3780 100644 --- a/lib/platform/azure/index.ts +++ b/lib/platform/azure/index.ts @@ -15,6 +15,7 @@ import { Pr, Issue, VulnerabilityAlert, + BranchStatusConfig, } from '../common'; import { sanitize } from '../../util/sanitize'; import { smartTruncate } from '../utils/pr-body'; @@ -520,13 +521,13 @@ export async function ensureCommentRemoval( } } -export function setBranchStatus( - branchName: string, - context: string, - description: string, - state: string, - targetUrl: string -): void { +export function setBranchStatus({ + branchName, + context, + description, + state, + url: targetUrl, +}: BranchStatusConfig): void { logger.debug( `setBranchStatus(${branchName}, ${context}, ${description}, ${state}, ${targetUrl}) - Not supported by Azure DevOps (yet!)` ); diff --git a/lib/platform/bitbucket-server/index.ts b/lib/platform/bitbucket-server/index.ts index baf6b0566c488016e856250ff246c7edbcf430bf..51eeeffe95df2a0da65bfae5292aaae60751d1c4 100644 --- a/lib/platform/bitbucket-server/index.ts +++ b/lib/platform/bitbucket-server/index.ts @@ -14,6 +14,7 @@ import { Issue, VulnerabilityAlert, GotResponse, + BranchStatusConfig, } from '../common'; import { sanitize } from '../../util/sanitize'; import { smartTruncate } from '../utils/pr-body'; @@ -571,13 +572,13 @@ export async function getBranchStatusCheck( return null; } -export async function setBranchStatus( - branchName: string, - context: string, - description: string, - state: string | null, - targetUrl?: string -): Promise<void> { +export async function setBranchStatus({ + branchName, + context, + description, + state, + url: targetUrl, +}: BranchStatusConfig): Promise<void> { logger.debug(`setBranchStatus(${branchName})`); const existingStatus = await getBranchStatusCheck(branchName, context); diff --git a/lib/platform/bitbucket/index.ts b/lib/platform/bitbucket/index.ts index 3437f88601140e02ddb1373a2e4b2fdcfc1d8b5f..260dc4946c7d599385bc83181e8402fad8451448 100644 --- a/lib/platform/bitbucket/index.ts +++ b/lib/platform/bitbucket/index.ts @@ -14,6 +14,7 @@ import { Pr, Issue, VulnerabilityAlert, + BranchStatusConfig, } from '../common'; import { sanitize } from '../../util/sanitize'; import { smartTruncate } from '../utils/pr-body'; @@ -433,13 +434,13 @@ export async function getBranchStatusCheck( ); } -export async function setBranchStatus( - branchName: string, - context: string, - description: string, - state: string, - targetUrl?: string -): Promise<void> { +export async function setBranchStatus({ + branchName, + context, + description, + state, + url: targetUrl, +}: BranchStatusConfig): Promise<void> { const sha = await getBranchCommit(branchName); // TargetUrl can not be empty so default to bitbucket diff --git a/lib/platform/common.ts b/lib/platform/common.ts index e0dbf2255edd06a8c0b52c3d44af6534d2b055fb..632c23d2fb6f3d2dd244ccb8345cab355c3c3e3e 100644 --- a/lib/platform/common.ts +++ b/lib/platform/common.ts @@ -108,7 +108,13 @@ export type PlatformPrOptions = { statusCheckVerify: boolean; gitLabAutomerge: boolean; }; - +export interface BranchStatusConfig { + branchName: string; + context: string; + description: string; + state: string | null; + url?: string; +} /** * TODO: Proper typing */ @@ -151,13 +157,7 @@ export interface Platform { isBranchStale(branchName: string): Promise<boolean>; getRepoForceRebase(): Promise<boolean>; deleteLabel(number: number, label: string): Promise<void>; - setBranchStatus( - branchName: string, - context: string, - description: string, - state: string | null, - url?: string - ): Promise<void>; + setBranchStatus(branchStatusConfig: BranchStatusConfig): Promise<void>; getBranchStatusCheck(branchName: string, context: string): Promise<string>; ensureCommentRemoval(number: number, subject: string): Promise<void>; deleteBranch(branchName: string, closePr?: boolean): Promise<void>; diff --git a/lib/platform/github/index.ts b/lib/platform/github/index.ts index c1d9f0e54d97356d0591fe2569736c5a1d94c931..8212ed8f7c481b479545883215a38d9e36e5a10d 100644 --- a/lib/platform/github/index.ts +++ b/lib/platform/github/index.ts @@ -13,6 +13,7 @@ import { RepoConfig, Issue, VulnerabilityAlert, + BranchStatusConfig, } from '../common'; import { configFileNames } from '../../config/app-strings'; @@ -1134,13 +1135,13 @@ export async function getBranchStatusCheck( } } -export async function setBranchStatus( - branchName: string, - context: string, - description: string, - state: string, - targetUrl?: string -): Promise<void> { +export async function setBranchStatus({ + branchName, + context, + description, + state, + url: targetUrl, +}: BranchStatusConfig): Promise<void> { // istanbul ignore if if (config.parentRepo) { logger.info('Cannot set branch status when in forking mode'); @@ -1608,13 +1609,13 @@ export async function createPr( await addLabels(pr.number, labels); if (platformOptions.statusCheckVerify) { logger.debug('Setting statusCheckVerify'); - await setBranchStatus( + await setBranchStatus({ branchName, - `renovate/verify`, - `Renovate verified pull request`, - 'success', - 'https://github.com/renovatebot/renovate' - ); + context: `renovate/verify`, + description: `Renovate verified pull request`, + state: 'success', + url: 'https://github.com/renovatebot/renovate', + }); } pr.isModified = false; return pr; diff --git a/lib/platform/gitlab/index.ts b/lib/platform/gitlab/index.ts index 11105775f38b2b7cc100cb7a7cbabc4a880d5bad..b5326a5d5bc0a3f116d948c1d12ce900e63fe2b5 100644 --- a/lib/platform/gitlab/index.ts +++ b/lib/platform/gitlab/index.ts @@ -13,6 +13,7 @@ import { Pr, Issue, VulnerabilityAlert, + BranchStatusConfig, } from '../common'; import { configFileNames } from '../../config/app-strings'; import { logger } from '../../logger'; @@ -599,13 +600,13 @@ export async function getBranchStatusCheck( return null; } -export async function setBranchStatus( - branchName: string, - context: string, - description: string, - state: string, - targetUrl?: string -): Promise<void> { +export async function setBranchStatus({ + branchName, + context, + description, + state, + url: targetUrl, +}: BranchStatusConfig): Promise<void> { // First, get the branch commit SHA const branchSha = await config.storage.getBranchCommit(branchName); // Now, check the statuses for that commit diff --git a/lib/workers/branch/index.ts b/lib/workers/branch/index.ts index 03998fe8a2c9f68a3fd2211e7924394363893924..5c6767d5c3604bbcc1b124dda32ea9be88dbd52f 100644 --- a/lib/workers/branch/index.ts +++ b/lib/workers/branch/index.ts @@ -512,12 +512,12 @@ export async function processBranch( 'DRY-RUN: Would set branch status in ' + config.branchName ); } else { - await platform.setBranchStatus( - config.branchName, + await platform.setBranchStatus({ + branchName: config.branchName, context, description, - state - ); + state, + }); } } } else { diff --git a/lib/workers/branch/status-checks.ts b/lib/workers/branch/status-checks.ts index bfd0b3bc8775aa3e9900b4a617d74a2d277311ca..61c6d7b7c6548c7224bbf9a7f14b25ae812a0797 100644 --- a/lib/workers/branch/status-checks.ts +++ b/lib/workers/branch/status-checks.ts @@ -18,13 +18,13 @@ async function setStatusCheck( logger.debug(`Status check ${context} is already up-to-date`); } else { logger.debug(`Updating ${context} status check state to ${state}`); - await platform.setBranchStatus( + await platform.setBranchStatus({ branchName, context, description, state, - url - ); + url, + }); } } diff --git a/lib/workers/repository/finalise/validate.ts b/lib/workers/repository/finalise/validate.ts index b651d49916b2f8a162a5b496c1f929006ffb730c..455285a3fe693d9d9f1856a1c4b25ccca8277714 100644 --- a/lib/workers/repository/finalise/validate.ts +++ b/lib/workers/repository/finalise/validate.ts @@ -105,12 +105,12 @@ export async function validatePrs(config: RenovateConfig): Promise<void> { if (pr.sourceRepo === config.repository) { logger.info({ status, description }, 'Setting PR validation status'); const context = `renovate/validate`; - await platform.setBranchStatus( - pr.branchName, + await platform.setBranchStatus({ + branchName: pr.branchName, context, description, - status - ); + state: status, + }); } else { logger.debug('Skipping branch status for forked PR'); } diff --git a/test/platform/azure/index.spec.ts b/test/platform/azure/index.spec.ts index ac3a0935aa9d8a230784a00db9a33c434e98fec3..f099c734ea647213d12f6c5672d551afe30ca6ba 100644 --- a/test/platform/azure/index.spec.ts +++ b/test/platform/azure/index.spec.ts @@ -702,7 +702,13 @@ describe('platform/azure', () => { describe('Not supported by Azure DevOps (yet!)', () => { it('setBranchStatus', () => { - const res = azure.setBranchStatus('test', 'test', 'test', 'test', 'test'); + const res = azure.setBranchStatus({ + branchName: 'test', + context: 'test', + description: 'test', + state: 'test', + url: 'test', + }); expect(res).toBeUndefined(); }); diff --git a/test/platform/bitbucket-server/index.spec.ts b/test/platform/bitbucket-server/index.spec.ts index c4ee1e6a4ff15c686f5bf5866a1b057d7e65057f..becf461850b51e99f3de5de6d8910fb9d3754d19 100644 --- a/test/platform/bitbucket-server/index.spec.ts +++ b/test/platform/bitbucket-server/index.spec.ts @@ -919,51 +919,51 @@ Followed by some information. await initRepo(); api.get.mockClear(); - await bitbucket.setBranchStatus( - 'somebranch', - 'context-2', - null as any, - 'success' - ); + await bitbucket.setBranchStatus({ + branchName: 'somebranch', + context: 'context-2', + description: null as any, + state: 'success', + }); - await bitbucket.setBranchStatus( - 'somebranch', - 'context-2', - null as any, - 'failed' - ); + await bitbucket.setBranchStatus({ + branchName: 'somebranch', + context: 'context-2', + description: null as any, + state: 'failed', + }); - await bitbucket.setBranchStatus( - 'somebranch', - 'context-2', - null as any, - 'failure' - ); + await bitbucket.setBranchStatus({ + branchName: 'somebranch', + context: 'context-2', + description: null as any, + state: 'failure', + }); - await bitbucket.setBranchStatus( - 'somebranch', - 'context-2', - null as any, - 'pending' - ); + await bitbucket.setBranchStatus({ + branchName: 'somebranch', + context: 'context-2', + description: null as any, + state: 'pending', + }); api.post.mockImplementationOnce(() => { throw new Error('requst-failed'); }); - await bitbucket.setBranchStatus( - 'somebranch', - 'context-2', - null as any, - 'success' - ); + await bitbucket.setBranchStatus({ + branchName: 'somebranch', + context: 'context-2', + description: null as any, + state: 'success', + }); - await bitbucket.setBranchStatus( - 'somebranch', - 'context-1', - null as any, - 'success' - ); + await bitbucket.setBranchStatus({ + branchName: 'somebranch', + context: 'context-1', + description: null as any, + state: 'success', + }); expect(api.get.mock.calls).toMatchSnapshot(); expect(api.post.mock.calls).toMatchSnapshot(); diff --git a/test/platform/bitbucket/index.spec.ts b/test/platform/bitbucket/index.spec.ts index 8224c9402de3dbcfd70110dacf1ce739f94895ff..204dec5272411929ee0308facbcc2553781450c4 100644 --- a/test/platform/bitbucket/index.spec.ts +++ b/test/platform/bitbucket/index.spec.ts @@ -219,13 +219,13 @@ describe('platform/bitbucket', () => { it('posts status', async () => { await initRepo(); await mocked(async () => { - await bitbucket.setBranchStatus( - 'branch', - 'context', - 'description', - 'failed', - 'targetUrl' - ); + await bitbucket.setBranchStatus({ + branchName: 'branch', + context: 'context', + description: 'description', + state: 'failed', + url: 'targetUrl', + }); expect(api.post.mock.calls).toMatchSnapshot(); }); }); diff --git a/test/platform/github/index.spec.ts b/test/platform/github/index.spec.ts index 429ae70bfa2be8c0fcb034fb9c262c92b81b03ec..3a76f91873db7b0c0157332775cd64b67a6bace5 100644 --- a/test/platform/github/index.spec.ts +++ b/test/platform/github/index.spec.ts @@ -803,13 +803,13 @@ describe('platform/github', () => { ], } as any) ); - await github.setBranchStatus( - 'some-branch', - 'some-context', - 'some-description', - 'some-state', - 'some-url' - ); + await github.setBranchStatus({ + branchName: 'some-branch', + context: 'some-context', + description: 'some-description', + state: 'some-state', + url: 'some-url', + }); expect(api.post).toHaveBeenCalledTimes(0); }); it('sets branch status', async () => { @@ -852,13 +852,13 @@ describe('platform/github', () => { api.get.mockResolvedValueOnce({ body: {}, } as any); - await github.setBranchStatus( - 'some-branch', - 'some-context', - 'some-description', - 'some-state', - 'some-url' - ); + await github.setBranchStatus({ + branchName: 'some-branch', + context: 'some-context', + description: 'some-description', + state: 'some-state', + url: 'some-url', + }); expect(api.post).toHaveBeenCalledTimes(1); }); }); diff --git a/test/platform/gitlab/index.spec.ts b/test/platform/gitlab/index.spec.ts index 28cb51a85807e181cf109581b44161363034eb0a..13bdb93bb77e3ea736942aff0085d2c422b2a46e 100644 --- a/test/platform/gitlab/index.spec.ts +++ b/test/platform/gitlab/index.spec.ts @@ -498,13 +498,13 @@ describe('platform/gitlab', () => { describe('setBranchStatus', () => { it('sets branch status', async () => { await initRepo(); - await gitlab.setBranchStatus( - 'some-branch', - 'some-context', - 'some-description', - 'some-state', - 'some-url' - ); + await gitlab.setBranchStatus({ + branchName: 'some-branch', + context: 'some-context', + description: 'some-description', + state: 'some-state', + url: 'some-url', + }); expect(api.post).toHaveBeenCalledTimes(1); }); }); diff --git a/test/workers/repository/finalise/validate.spec.ts b/test/workers/repository/finalise/validate.spec.ts index 3676ee7f49c5f495731a44dfbcb7d3bc473211cc..c5733793744c25f4d3a25c6a745a550073cd6319 100644 --- a/test/workers/repository/finalise/validate.spec.ts +++ b/test/workers/repository/finalise/validate.spec.ts @@ -49,7 +49,9 @@ describe('workers/repository/validate', () => { platform.getFile.mockResolvedValue('not JSON'); await validate.validatePrs({}); expect(platform.setBranchStatus).toHaveBeenCalledTimes(1); - expect(platform.setBranchStatus.mock.calls[0][3]).toEqual('failure'); + expect(platform.setBranchStatus.mock.calls[0][0].state).toEqual( + 'failure' + ); expect(platform.ensureComment).toHaveBeenCalledTimes(1); expect(platform.ensureCommentRemoval).toHaveBeenCalledTimes(0); }); @@ -65,7 +67,9 @@ describe('workers/repository/validate', () => { platform.getFile.mockResolvedValue('{"foo":1}'); await validate.validatePrs({}); expect(platform.setBranchStatus).toHaveBeenCalledTimes(1); - expect(platform.setBranchStatus.mock.calls[0][3]).toEqual('failure'); + expect(platform.setBranchStatus.mock.calls[0][0].state).toEqual( + 'failure' + ); expect(platform.ensureComment).toHaveBeenCalledTimes(1); expect(platform.ensureCommentRemoval).toHaveBeenCalledTimes(0); }); @@ -81,7 +85,9 @@ describe('workers/repository/validate', () => { platform.getFile.mockResolvedValue('{}'); await validate.validatePrs({}); expect(platform.setBranchStatus).toHaveBeenCalledTimes(1); - expect(platform.setBranchStatus.mock.calls[0][3]).toEqual('success'); + expect(platform.setBranchStatus.mock.calls[0][0].state).toEqual( + 'success' + ); expect(platform.ensureComment).toHaveBeenCalledTimes(0); expect(platform.ensureCommentRemoval).toHaveBeenCalledTimes(1); });