refactor: Refactor azure (#17858)

Co-authored-by: whitesource-for-github-com[bot] <50673670+whitesource-for-github-com[bot]@users.noreply.github.com>
Co-authored-by: whitesource-for-github-com[bot] <whitesource-for-github-com[bot]@users.noreply.github.com>
This commit is contained in:
Philip 2022-09-19 14:37:14 +03:00 committed by GitHub
parent 6ee1a8d931
commit 5fd8c2bd8b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 23 additions and 28 deletions

View file

@ -623,10 +623,7 @@ Elements in the `repositories` array can be an object if you wish to define addi
```js
{
repositories: [
{ repository: 'g/r1', bumpVersion: true },
'g/r2'
],
repositories: [{ repository: 'g/r1', bumpVersion: true }, 'g/r2'];
}
```

View file

@ -5,11 +5,11 @@ import {
} from 'azure-devops-node-api/interfaces/GitInterfaces.js';
import { logger } from '../../../logger';
import { streamToString } from '../../../util/streams';
import { getNewBranchName } from '../util';
import * as azureApi from './azure-got-wrapper';
import {
getBranchNameWithoutRefsPrefix,
getBranchNameWithoutRefsheadsPrefix,
getNewBranchName,
} from './util';
const mergePolicyGuid = 'fa4e907d-c16b-4a4c-9dfa-4916e5d171ab'; // Magic GUID for merge strategy policy configurations

View file

@ -40,7 +40,7 @@ import type {
RepoResult,
UpdatePrConfig,
} from '../types';
import { repoFingerprint } from '../util';
import { getNewBranchName, repoFingerprint } from '../util';
import { smartTruncate } from '../utils/pr-body';
import * as azureApi from './azure-got-wrapper';
import * as azureHelper from './azure-helper';
@ -49,7 +49,6 @@ import {
getBranchNameWithoutRefsheadsPrefix,
getGitStatusContextCombinedName,
getGitStatusContextFromCombinedName,
getNewBranchName,
getProjectAndRepo,
getRenovatePRFormat,
getRepoByName,

View file

@ -4,7 +4,6 @@ import {
getBranchNameWithoutRefsheadsPrefix,
getGitStatusContextCombinedName,
getGitStatusContextFromCombinedName,
getNewBranchName,
getProjectAndRepo,
getRenovatePRFormat,
getRepoByName,
@ -13,18 +12,6 @@ import {
} from './util';
describe('modules/platform/azure/util', () => {
describe('getNewBranchName', () => {
it('should add refs/heads', () => {
const res = getNewBranchName('testBB');
expect(res).toBe(`refs/heads/testBB`);
});
it('should be the same', () => {
const res = getNewBranchName('refs/heads/testBB');
expect(res).toBe(`refs/heads/testBB`);
});
});
describe('getGitStatusContextCombinedName', () => {
it('should return undefined if null context passed', () => {
const contextName = getGitStatusContextCombinedName(null);

View file

@ -12,13 +12,6 @@ import { toBase64 } from '../../../util/string';
import { getPrBodyStruct } from '../pr-body';
import type { AzurePr } from './types';
export function getNewBranchName(branchName?: string): string | undefined {
if (branchName && !branchName.startsWith('refs/heads/')) {
return `refs/heads/${branchName}`;
}
return branchName;
}
export function getGitStatusContextCombinedName(
context: GitStatusContext | null | undefined
): string | undefined {

View file

@ -1,5 +1,5 @@
import * as hostRules from '../../util/host-rules';
import { repoFingerprint } from './util';
import { getNewBranchName, repoFingerprint } from './util';
describe('modules/platform/util', () => {
beforeEach(() => hostRules.clear());
@ -16,4 +16,16 @@ describe('modules/platform/util', () => {
}
);
});
describe('getNewBranchName', () => {
it('should add refs/heads', () => {
const res = getNewBranchName('testBB');
expect(res).toBe(`refs/heads/testBB`);
});
it('should be the same', () => {
const res = getNewBranchName('refs/heads/testBB');
expect(res).toBe(`refs/heads/testBB`);
});
});
});

View file

@ -8,3 +8,10 @@ export function repoFingerprint(
const fingerprint = hasha(input);
return fingerprint;
}
export function getNewBranchName(branchName?: string): string | undefined {
if (branchName && !branchName.startsWith('refs/heads/')) {
return `refs/heads/${branchName}`;
}
return branchName;
}