diff --git a/lib/platform/azure/index.spec.ts b/lib/platform/azure/index.spec.ts index 123879ffb61328d615fc57bd758bb7d3a022d6fc..6c652fdb52794e2bec288b325c787d15d3793d09 100644 --- a/lib/platform/azure/index.spec.ts +++ b/lib/platform/azure/index.spec.ts @@ -846,6 +846,56 @@ describe('platform/azure', () => { }); }); + describe('getPrFiles', () => { + it('single change', async () => { + azureApi.gitApi.mockImplementationOnce( + () => + ({ + getPullRequestIterations: jest.fn(() => [{ id: 1 }]), + getPullRequestIterationChanges: jest.fn(() => ({ + changeEntries: [{ item: { path: '/index.js' } }], + })), + } as any) + ); + const res = await azure.getPrFiles(46); + expect(res).toHaveLength(1); + expect(res).toEqual(['index.js']); + }); + it('multiple changes', async () => { + azureApi.gitApi.mockImplementationOnce( + () => + ({ + getPullRequestIterations: jest.fn(() => [{ id: 1 }, { id: 2 }]), + getPullRequestIterationChanges: jest + .fn() + .mockResolvedValueOnce({ + changeEntries: [{ item: { path: '/index.js' } }], + }) + .mockResolvedValueOnce({ + changeEntries: [{ item: { path: '/package.json' } }], + }), + } as any) + ); + const res = await azure.getPrFiles(46); + expect(res).toHaveLength(2); + expect(res).toEqual(['index.js', 'package.json']); + }); + it('deduplicate changes', async () => { + azureApi.gitApi.mockImplementationOnce( + () => + ({ + getPullRequestIterations: jest.fn(() => [{ id: 1 }, { id: 2 }]), + getPullRequestIterationChanges: jest.fn().mockResolvedValue({ + changeEntries: [{ item: { path: '/index.js' } }], + }), + } as any) + ); + const res = await azure.getPrFiles(46); + expect(res).toHaveLength(1); + expect(res).toEqual(['index.js']); + }); + }); + describe('Not supported by Azure DevOps (yet!)', () => { it('setBranchStatus', async () => { const res = await azure.setBranchStatus({ @@ -862,12 +912,6 @@ describe('platform/azure', () => { const res = await azure.mergePr(0, undefined); expect(res).toBe(false); }); - - // to become async? - it('getPrFiles', async () => { - const res = await azure.getPrFiles(46); - expect(res).toHaveLength(0); - }); }); describe('getVulnerabilityAlerts()', () => { diff --git a/lib/platform/azure/index.ts b/lib/platform/azure/index.ts index 2edd874c5e4376e96b963c2d7c38da45e79db3c3..dfc322b13344341dcdab31b30cc9f8b4e10f9b86 100644 --- a/lib/platform/azure/index.ts +++ b/lib/platform/azure/index.ts @@ -729,12 +729,32 @@ export /* istanbul ignore next */ async function deleteLabel( await azureApiGit.deletePullRequestLabels(config.repoId, prNumber, label); } -// to become async? -export function getPrFiles(prNo: number): Promise<string[]> { - logger.debug( - `getPrFiles(prNo)(${prNo}) - Not supported by Azure DevOps (yet!)` +export async function getPrFiles(prId: number): Promise<string[]> { + const azureApiGit = await azureApi.gitApi(); + const prIterations = await azureApiGit.getPullRequestIterations( + config.repoId, + prId ); - return Promise.resolve([]); + return [ + ...new Set( + ( + await Promise.all( + prIterations.map( + async iteration => + ( + await azureApiGit.getPullRequestIterationChanges( + config.repoId, + prId, + iteration.id + ) + ).changeEntries + ) + ) + ) + .reduce((acc, val) => acc.concat(val), []) + .map(change => change.item.path.slice(1)) + ), + ]; } export function getVulnerabilityAlerts(): Promise<VulnerabilityAlert[]> {