diff --git a/lib/platform/azure/azure-helper.ts b/lib/platform/azure/azure-helper.ts index b1baa1714088bb8c42e13d515173763d9b999557..c539e9fcf067f5d3c7fb620d886c2311f53a0d80 100644 --- a/lib/platform/azure/azure-helper.ts +++ b/lib/platform/azure/azure-helper.ts @@ -191,6 +191,8 @@ export function getRenovatePRFormat(azurePr: GitPullRequest): Pr { pr.isConflicted = true; } + // value is updated later to be correct for + // specific pr's after filtering, for performance pr.isModified = false; return pr; diff --git a/lib/platform/azure/index.ts b/lib/platform/azure/index.ts index 0dfa208723f42a6c7b3c4084d2b1f22681480c3a..1e068eac6a1fc49818f885aced723df985b18a6c 100644 --- a/lib/platform/azure/index.ts +++ b/lib/platform/azure/index.ts @@ -251,6 +251,7 @@ export async function getPrList(): Promise<Pr[]> { prs = prs.concat(fetchedPrs); skip += 100; } while (fetchedPrs.length > 0); + config.prList = prs.map(azureHelper.getRenovatePRFormat); logger.info({ length: config.prList.length }, 'Retrieved Pull Requests'); } @@ -279,6 +280,15 @@ export async function getPr(pullRequestId: number): Promise<Pr | null> { azurePr.labels = labels .filter(label => label.active) .map(label => label.name); + + const commits = await azureApiGit.getPullRequestCommits( + config.repoId, + pullRequestId + ); + azurePr.isModified = + commits.length > 0 && + commits[0].author.name !== commits[commits.length - 1].author.name; + return azurePr; } diff --git a/test/platform/azure/__snapshots__/index.spec.ts.snap b/test/platform/azure/__snapshots__/index.spec.ts.snap index 16ce1928c6e10a323974016f9c0d465f9ab83564..ea8e65413bb2f3ecc71bbf05dabed2db7c0b389d 100644 --- a/test/platform/azure/__snapshots__/index.spec.ts.snap +++ b/test/platform/azure/__snapshots__/index.spec.ts.snap @@ -90,6 +90,7 @@ exports[`platform/azure getBranchPr(branchName) should return the pr 1`] = `null exports[`platform/azure getPr(prNo) should return a pr in the right format 1`] = ` Object { + "isModified": false, "labels": Array [ "renovate", ], @@ -97,6 +98,14 @@ Object { } `; +exports[`platform/azure getPr(prNo) should return a pr thats been modified 1`] = ` +Object { + "isModified": true, + "labels": Array [], + "pullRequestId": 1234, +} +`; + exports[`platform/azure getPrBody(input) returns updated pr body 1`] = `"https://github.com/foo/bar/issues/5 plus also [a link](https://github.com/foo/bar/issues/5)"`; exports[`platform/azure getRepos() should return an array of repos 1`] = ` diff --git a/test/platform/azure/index.spec.ts b/test/platform/azure/index.spec.ts index 5506df28c6475535786835cdfb7a6ec3fdc6107f..7a91f30dc3346980db8def7c5171a0304e11768d 100644 --- a/test/platform/azure/index.spec.ts +++ b/test/platform/azure/index.spec.ts @@ -215,6 +215,7 @@ describe('platform/azure', () => { state: 'open', }, ]), + getPullRequestCommits: jest.fn().mockReturnValue([]), } as any) ); azureHelper.getNewBranchName.mockImplementationOnce( @@ -251,6 +252,7 @@ describe('platform/azure', () => { state: 'closed', }, ]), + getPullRequestCommits: jest.fn().mockReturnValue([]), } as any) ); azureHelper.getNewBranchName.mockImplementationOnce( @@ -287,6 +289,7 @@ describe('platform/azure', () => { state: 'closed', }, ]), + getPullRequestCommits: jest.fn().mockReturnValue([]), } as any) ); azureHelper.getNewBranchName.mockImplementationOnce( @@ -323,6 +326,7 @@ describe('platform/azure', () => { state: 'closed', }, ]), + getPullRequestCommits: jest.fn().mockReturnValue([]), } as any) ); azureHelper.getNewBranchName.mockImplementationOnce( @@ -387,6 +391,7 @@ describe('platform/azure', () => { status: 2, }, ]), + getPullRequestCommits: jest.fn().mockReturnValue([]), } as any) ); azureHelper.getNewBranchName.mockImplementation( @@ -474,13 +479,57 @@ describe('platform/azure', () => { getPullRequestLabels: jest .fn() .mockReturnValue([{ active: true, name: 'renovate' }]), + getPullRequestCommits: jest.fn().mockReturnValue([ + { + author: { + name: 'renovate', + }, + }, + ]), + } as any) + ); + azureHelper.getRenovatePRFormat.mockImplementation( + () => + ({ + pullRequestId: 1234, + } as any) + ); + const pr = await azure.getPr(1234); + expect(pr).toMatchSnapshot(); + }); + it('should return a pr thats been modified', async () => { + await initRepo({ repository: 'some/repo' }); + azureApi.gitApi.mockImplementation( + () => + ({ + getPullRequests: jest + .fn() + .mockReturnValue([]) + .mockReturnValueOnce([ + { + pullRequestId: 1234, + }, + ]), + getPullRequestLabels: jest.fn().mockReturnValue([]), + getPullRequestCommits: jest.fn().mockReturnValue([ + { + author: { + name: 'renovate', + }, + }, + { + author: { + name: 'end user', + }, + }, + ]), } as any) ); azureHelper.getRenovatePRFormat.mockImplementation( () => ({ pullRequestId: 1234, - labels: ['renovate'], + isModified: false, } as any) ); const pr = await azure.getPr(1234);