diff --git a/lib/modules/platform/azure/azure-helper.spec.ts b/lib/modules/platform/azure/azure-helper.spec.ts index 1e7a722ab38f6b1eaf5d521c0c6df0b90a48c576..2d4430dd37861b00c94b9cf09bd093cfcfa1fd12 100644 --- a/lib/modules/platform/azure/azure-helper.spec.ts +++ b/lib/modules/platform/azure/azure-helper.spec.ts @@ -1,5 +1,8 @@ import { Readable } from 'node:stream'; -import { GitPullRequestMergeStrategy } from 'azure-devops-node-api/interfaces/GitInterfaces.js'; +import type { IPolicyApi } from 'azure-devops-node-api/PolicyApi'; +import { GitPullRequestMergeStrategy } from 'azure-devops-node-api/interfaces/GitInterfaces'; +import type { PolicyConfiguration } from 'azure-devops-node-api/interfaces/PolicyInterfaces'; +import { partial } from '../../../../test/util'; jest.mock('./azure-got-wrapper'); @@ -238,6 +241,35 @@ describe('modules/platform/azure/azure-helper', () => { ); }); + it('should return Squash when Project wide exact branch policy exists', async () => { + const refMock = 'refs/heads/ding'; + + azureApi.policyApi.mockResolvedValueOnce( + partial<IPolicyApi>({ + getPolicyConfigurations: jest.fn(() => + Promise.resolve([ + partial<PolicyConfiguration>({ + settings: { + allowSquash: true, + scope: [ + { + // null here means project wide + repositoryId: null, + matchKind: 'Exact', + refName: refMock, + }, + ], + }, + }), + ]), + ), + }), + ); + expect(await azureHelper.getMergeMethod('', '', refMock)).toEqual( + GitPullRequestMergeStrategy.Squash, + ); + }); + it('should return default branch policy', async () => { azureApi.policyApi.mockImplementationOnce( () => diff --git a/lib/modules/platform/azure/azure-helper.ts b/lib/modules/platform/azure/azure-helper.ts index e215c7a7c8f7392e20d50b2d6ee949f225f0be16..ff63ce284306e6836fde7503f0f31cfbd4ba99b3 100644 --- a/lib/modules/platform/azure/azure-helper.ts +++ b/lib/modules/platform/azure/azure-helper.ts @@ -135,7 +135,7 @@ export async function getMergeMethod( ) { return true; } - if (scope.repositoryId !== repoId) { + if (scope.repositoryId !== repoId && scope.repositoryId !== null) { return false; } if (!branchRef) {