Skip to content

Commit

Permalink
fix(azure): Support exact branch merge policies. (#27918)
Browse files Browse the repository at this point in the history
Co-authored-by: Rhys Arkins <rhys@arkins.net>
  • Loading branch information
scabana and rarkins committed Mar 15, 2024
1 parent c1517aa commit 1554cc6
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 2 deletions.
34 changes: 33 additions & 1 deletion 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');

Expand Down Expand Up @@ -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(
() =>
Expand Down
2 changes: 1 addition & 1 deletion lib/modules/platform/azure/azure-helper.ts
Expand Up @@ -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) {
Expand Down

0 comments on commit 1554cc6

Please sign in to comment.