diff --git a/lib/platform/azure/index.ts b/lib/platform/azure/index.ts index 3b86b2f6ece9ce8897fb9b31dc2d69c723b6cc75..dcaf8021226f83c5e7ad1e4bdbbe6f9ff6b8d57a 100644 --- a/lib/platform/azure/index.ts +++ b/lib/platform/azure/index.ts @@ -221,29 +221,6 @@ async function abandonPr(prNo: number): Promise<void> { ); } -export async function getPr(pullRequestId: number): Promise<Pr | null> { - logger.debug(`getPr(${pullRequestId})`); - if (!pullRequestId) { - return null; - } - const azureApiGit = await azureApi.gitApi(); - const prs = await azureApiGit.getPullRequests(config.repoId, { status: 4 }); - const azurePr: any = prs.find(item => item.pullRequestId === pullRequestId); - if (!azurePr) { - return null; - } - const labels = await azureApiGit.getPullRequestLabels( - config.repoId, - pullRequestId - ); - azurePr.labels = labels - .filter(label => label.active) - .map(label => label.name); - logger.debug(`pr: (${azurePr})`); - const pr = azureHelper.getRenovatePRFormat(azurePr); - return pr; -} - export async function getPrList(): Promise<Pr[]> { logger.debug('getPrList()'); if (!config.prList) { @@ -269,6 +246,31 @@ export async function getPrList(): Promise<Pr[]> { return config.prList; } +export async function getPr(pullRequestId: number): Promise<Pr | null> { + logger.debug(`getPr(${pullRequestId})`); + if (!pullRequestId) { + return null; + } + const azurePr = (await getPrList()).find( + item => item.pullRequestId === pullRequestId + ); + + if (!azurePr) { + return null; + } + + const azureApiGit = await azureApi.gitApi(); + const labels = await azureApiGit.getPullRequestLabels( + config.repoId, + pullRequestId + ); + + azurePr.labels = labels + .filter(label => label.active) + .map(label => label.name); + return azurePr; +} + export async function findPr( branchName: string, prTitle: string | null, diff --git a/test/platform/azure/index.spec.ts b/test/platform/azure/index.spec.ts index 06c54a7d32ada17b0feaee4848e69e0b271c5b9d..ac3a0935aa9d8a230784a00db9a33c434e98fec3 100644 --- a/test/platform/azure/index.spec.ts +++ b/test/platform/azure/index.spec.ts @@ -443,7 +443,7 @@ describe('platform/azure', () => { }); it('should return a pr in the right format', async () => { await initRepo({ repository: 'some/repo' }); - azureApi.gitApi.mockImplementationOnce( + azureApi.gitApi.mockImplementation( () => ({ getPullRequests: jest @@ -454,9 +454,9 @@ describe('platform/azure', () => { pullRequestId: 1234, }, ]), - getPullRequestLabels: jest.fn(() => [ - { active: true, name: 'renovate' }, - ]), + getPullRequestLabels: jest + .fn() + .mockReturnValue([{ active: true, name: 'renovate' }]), } as any) ); azureHelper.getRenovatePRFormat.mockImplementation(