From 5fd8c2bd8b78a658fee80a74ec5e70014173ebf2 Mon Sep 17 00:00:00 2001 From: Philip <42116482+PhilipAbed@users.noreply.github.com> Date: Mon, 19 Sep 2022 14:37:14 +0300 Subject: [PATCH] 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> --- docs/usage/self-hosted-configuration.md | 5 +---- lib/modules/platform/azure/azure-helper.ts | 2 +- lib/modules/platform/azure/index.ts | 3 +-- lib/modules/platform/azure/util.spec.ts | 13 ------------- lib/modules/platform/azure/util.ts | 7 ------- lib/modules/platform/util.spec.ts | 14 +++++++++++++- lib/modules/platform/util.ts | 7 +++++++ 7 files changed, 23 insertions(+), 28 deletions(-) diff --git a/docs/usage/self-hosted-configuration.md b/docs/usage/self-hosted-configuration.md index 637623d077..61fbb6e6d2 100644 --- a/docs/usage/self-hosted-configuration.md +++ b/docs/usage/self-hosted-configuration.md @@ -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']; } ``` diff --git a/lib/modules/platform/azure/azure-helper.ts b/lib/modules/platform/azure/azure-helper.ts index 6accda1c73..8369779fad 100644 --- a/lib/modules/platform/azure/azure-helper.ts +++ b/lib/modules/platform/azure/azure-helper.ts @@ -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 diff --git a/lib/modules/platform/azure/index.ts b/lib/modules/platform/azure/index.ts index 342dfcd599..5119106235 100644 --- a/lib/modules/platform/azure/index.ts +++ b/lib/modules/platform/azure/index.ts @@ -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, diff --git a/lib/modules/platform/azure/util.spec.ts b/lib/modules/platform/azure/util.spec.ts index ffa15a2d2f..567bc057e8 100644 --- a/lib/modules/platform/azure/util.spec.ts +++ b/lib/modules/platform/azure/util.spec.ts @@ -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); diff --git a/lib/modules/platform/azure/util.ts b/lib/modules/platform/azure/util.ts index 660086b22a..8984ca01a1 100644 --- a/lib/modules/platform/azure/util.ts +++ b/lib/modules/platform/azure/util.ts @@ -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 { diff --git a/lib/modules/platform/util.spec.ts b/lib/modules/platform/util.spec.ts index 6cd8ae05ad..2299cf047a 100644 --- a/lib/modules/platform/util.spec.ts +++ b/lib/modules/platform/util.spec.ts @@ -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`); + }); + }); }); diff --git a/lib/modules/platform/util.ts b/lib/modules/platform/util.ts index fb7a10b766..d074982889 100644 --- a/lib/modules/platform/util.ts +++ b/lib/modules/platform/util.ts @@ -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; +} -- GitLab