diff --git a/lib/platform/azure/index.ts b/lib/platform/azure/index.ts index 12cc87254dd6f585dd439f8a234c27b56143a043..33e8458b53fc0ce01101e91e9ae7734feced19b4 100644 --- a/lib/platform/azure/index.ts +++ b/lib/platform/azure/index.ts @@ -168,13 +168,6 @@ export function getRepoForceRebase(): Promise<boolean> { return Promise.resolve(config.repoForceRebase === true); } -// istanbul ignore next -export async function setBaseBranch(branchName: string): Promise<string> { - logger.debug(`Setting base branch to ${branchName}`); - const baseBranchSha = await git.setBranch(branchName); - return baseBranchSha; -} - export async function getPrList(): Promise<AzurePr[]> { logger.debug('getPrList()'); if (!config.prList) { diff --git a/lib/platform/bitbucket-server/__snapshots__/index.spec.ts.snap b/lib/platform/bitbucket-server/__snapshots__/index.spec.ts.snap index 014356de7c1d199e924f6bf99e062b54b0f56287..48e378bd545a5b482a847d2e11e315d2b674eb54 100644 --- a/lib/platform/bitbucket-server/__snapshots__/index.spec.ts.snap +++ b/lib/platform/bitbucket-server/__snapshots__/index.spec.ts.snap @@ -2826,35 +2826,6 @@ Array [ ] `; -exports[`platform/bitbucket-server/index endpoint with no path setBaseBranch() updates file list 1`] = ` -Array [ - Object { - "headers": Object { - "accept": "application/json", - "accept-encoding": "gzip, deflate", - "authorization": "Basic YWJjOjEyMw==", - "host": "stash.renovatebot.com", - "user-agent": "https://github.com/renovatebot/renovate", - "x-atlassian-token": "no-check", - }, - "method": "GET", - "url": "https://stash.renovatebot.com/rest/api/1.0/projects/SOME/repos/repo", - }, - Object { - "headers": Object { - "accept": "application/json", - "accept-encoding": "gzip, deflate", - "authorization": "Basic YWJjOjEyMw==", - "host": "stash.renovatebot.com", - "user-agent": "https://github.com/renovatebot/renovate", - "x-atlassian-token": "no-check", - }, - "method": "GET", - "url": "https://stash.renovatebot.com/rest/api/1.0/projects/SOME/repos/repo/branches/default", - }, -] -`; - exports[`platform/bitbucket-server/index endpoint with no path setBranchStatus() should be success 1 1`] = ` Array [ Object { @@ -6602,35 +6573,6 @@ Array [ ] `; -exports[`platform/bitbucket-server/index endpoint with path setBaseBranch() updates file list 1`] = ` -Array [ - Object { - "headers": Object { - "accept": "application/json", - "accept-encoding": "gzip, deflate", - "authorization": "Basic YWJjOjEyMw==", - "host": "stash.renovatebot.com", - "user-agent": "https://github.com/renovatebot/renovate", - "x-atlassian-token": "no-check", - }, - "method": "GET", - "url": "https://stash.renovatebot.com/vcs/rest/api/1.0/projects/SOME/repos/repo", - }, - Object { - "headers": Object { - "accept": "application/json", - "accept-encoding": "gzip, deflate", - "authorization": "Basic YWJjOjEyMw==", - "host": "stash.renovatebot.com", - "user-agent": "https://github.com/renovatebot/renovate", - "x-atlassian-token": "no-check", - }, - "method": "GET", - "url": "https://stash.renovatebot.com/vcs/rest/api/1.0/projects/SOME/repos/repo/branches/default", - }, -] -`; - exports[`platform/bitbucket-server/index endpoint with path setBranchStatus() should be success 1 1`] = ` Array [ Object { diff --git a/lib/platform/bitbucket-server/index.spec.ts b/lib/platform/bitbucket-server/index.spec.ts index 77c8871a2d1962000e46749af1100632c82f1e04..b7354b58943de1cc5ae4e4851d4951ed6f0deb48 100644 --- a/lib/platform/bitbucket-server/index.spec.ts +++ b/lib/platform/bitbucket-server/index.spec.ts @@ -421,15 +421,6 @@ describe(getName(__filename), () => { ); }); - describe('setBaseBranch()', () => { - it('updates file list', async () => { - expect.assertions(1); - await initRepo(); - await bitbucket.setBaseBranch('branch'); - expect(httpMock.getTrace()).toMatchSnapshot(); - }); - }); - describe('addAssignees()', () => { it('does not throw', async () => { expect(await bitbucket.addAssignees(3, ['some'])).toMatchSnapshot(); diff --git a/lib/platform/bitbucket-server/index.ts b/lib/platform/bitbucket-server/index.ts index a093eb696deaabb55d582503610aa5e1db84b683..487c56c50fd1262fa8e7fa3ce66a5748f2fa7733 100644 --- a/lib/platform/bitbucket-server/index.ts +++ b/lib/platform/bitbucket-server/index.ts @@ -241,12 +241,6 @@ export async function getRepoForceRebase(): Promise<boolean> { res.body?.mergeConfig?.defaultStrategy?.id.includes('ff-only') ); } - -export async function setBaseBranch(branchName: string): Promise<string> { - const baseBranchSha = await git.setBranch(branchName); - return baseBranchSha; -} - // Gets details for a PR export async function getPr( prNo: number, diff --git a/lib/platform/bitbucket/__snapshots__/index.spec.ts.snap b/lib/platform/bitbucket/__snapshots__/index.spec.ts.snap index 278556530fc47aea9934fe21a852eecf2c18b5c9..210688c88709c06ffca63bcd8b3edca52774a95e 100644 --- a/lib/platform/bitbucket/__snapshots__/index.spec.ts.snap +++ b/lib/platform/bitbucket/__snapshots__/index.spec.ts.snap @@ -1090,22 +1090,6 @@ Array [ ] `; -exports[`platform/bitbucket setBaseBranch() updates file list 1`] = ` -Array [ - Object { - "headers": Object { - "accept": "application/json", - "accept-encoding": "gzip, deflate", - "authorization": "Basic YWJjOjEyMw==", - "host": "api.bitbucket.org", - "user-agent": "https://github.com/renovatebot/renovate", - }, - "method": "GET", - "url": "https://api.bitbucket.org/2.0/repositories/some/repo", - }, -] -`; - exports[`platform/bitbucket setBranchStatus() posts status 1`] = ` Array [ Object { diff --git a/lib/platform/bitbucket/index.spec.ts b/lib/platform/bitbucket/index.spec.ts index 5d529efdfd89fcfed6a55bb1a5f24cc3eb8aaa3d..b5400c74b7a9d1e9f2f9e251a4cf4df81dcd60a0 100644 --- a/lib/platform/bitbucket/index.spec.ts +++ b/lib/platform/bitbucket/index.spec.ts @@ -175,14 +175,6 @@ describe('platform/bitbucket', () => { }); }); - describe('setBaseBranch()', () => { - it('updates file list', async () => { - await initRepoMock(); - await bitbucket.setBaseBranch('branch'); - expect(httpMock.getTrace()).toMatchSnapshot(); - }); - }); - describe('getBranchPr()', () => { it('bitbucket finds PR for branch', async () => { const scope = await initRepoMock(); diff --git a/lib/platform/bitbucket/index.ts b/lib/platform/bitbucket/index.ts index b5c6603f8ed45f0eb47c388a606e5fcf8894ac8b..86e1134f18bca74b8368653870bf3392eddfbc59 100644 --- a/lib/platform/bitbucket/index.ts +++ b/lib/platform/bitbucket/index.ts @@ -177,11 +177,6 @@ export function getRepoForceRebase(): Promise<boolean> { return Promise.resolve(false); } -export async function setBaseBranch(branchName: string): Promise<string> { - const baseBranchSha = await git.setBranch(branchName); - return baseBranchSha; -} - // istanbul ignore next function matchesState(state: string, desiredState: string): boolean { if (desiredState === PrState.All) { diff --git a/lib/platform/common.ts b/lib/platform/common.ts index 549fe2b1bf0d4f69824f0036f028ac2851dd49d7..a84f1256660490fe8c44da3d3566c014fe7498fc 100644 --- a/lib/platform/common.ts +++ b/lib/platform/common.ts @@ -169,7 +169,6 @@ export interface Platform { | EnsureCommentRemovalConfigByContent ): Promise<void>; ensureComment(ensureComment: EnsureCommentConfig): Promise<boolean>; - setBaseBranch(branchName: string): Promise<string>; getPr(number: number): Promise<Pr>; findPr(findPRConfig: FindPRConfig): Promise<Pr>; refreshPr?(number: number): Promise<void>; diff --git a/lib/platform/gitea/index.spec.ts b/lib/platform/gitea/index.spec.ts index 562b86d14ad55b3b6ef6275a784db377f255214a..8e786a34f38270628b553cc419793f6c6cf694dc 100644 --- a/lib/platform/gitea/index.spec.ts +++ b/lib/platform/gitea/index.spec.ts @@ -385,22 +385,6 @@ describe('platform/gitea', () => { expect(logger.warn).toHaveBeenCalledTimes(1); }); - - it('should set base branch', async () => { - await initFakeRepo(); - await gitea.setBaseBranch('master'); - - expect(gitvcs.setBranch).toHaveBeenCalledTimes(1); - expect(gitvcs.setBranch).toHaveBeenCalledWith(mockRepo.default_branch); - }); - - it('should set custom base branch', async () => { - await initFakeRepo(); - await gitea.setBaseBranch('devel'); - - expect(gitvcs.setBranch).toHaveBeenCalledTimes(1); - expect(gitvcs.setBranch).toHaveBeenCalledWith('devel'); - }); }); describe('getBranchStatus', () => { @@ -688,7 +672,6 @@ describe('platform/gitea', () => { }); await initFakeRepo(); - await gitea.setBaseBranch('devel'); const res = await gitea.createPr({ branchName: mockNewPR.head.label, targetBranch: 'devel', @@ -713,7 +696,6 @@ describe('platform/gitea', () => { helper.createPR.mockResolvedValueOnce(mockNewPR); await initFakeRepo(); - await gitea.setBaseBranch('devel'); const res = await gitea.createPr({ branchName: mockNewPR.head.label, targetBranch: 'master', diff --git a/lib/platform/gitea/index.ts b/lib/platform/gitea/index.ts index 8ee46283700f148fc162b276d6f95290a4707c5f..56e8eb350d04308924273fb3a3220dcfffd5f0ef 100644 --- a/lib/platform/gitea/index.ts +++ b/lib/platform/gitea/index.ts @@ -414,11 +414,6 @@ const platform: Platform = { return BranchStatus.yellow; }, - async setBaseBranch(branchName: string): Promise<string> { - const baseBranchSha = await git.setBranch(branchName); - return baseBranchSha; - }, - getPrList(): Promise<Pr[]> { if (config.prList === null) { config.prList = helper @@ -848,7 +843,6 @@ export const { initPlatform, initRepo, mergePr, - setBaseBranch, setBranchStatus, updatePr, } = platform; diff --git a/lib/platform/github/index.ts b/lib/platform/github/index.ts index 95ebcdbe07554889760d6f359ca6ae17cf3204d2..fc4e7e8af4393479ce3f8c587d851cd5aa0a8e1b 100644 --- a/lib/platform/github/index.ts +++ b/lib/platform/github/index.ts @@ -460,12 +460,6 @@ export async function getRepoForceRebase(): Promise<boolean> { return config.repoForceRebase; } -// istanbul ignore next -export async function setBaseBranch(branchName: string): Promise<string> { - const baseBranchSha = await git.setBranch(branchName); - return baseBranchSha; -} - async function getClosedPrs(): Promise<PrList> { if (!config.closedPrList) { config.closedPrList = {}; diff --git a/lib/platform/gitlab/__snapshots__/index.spec.ts.snap b/lib/platform/gitlab/__snapshots__/index.spec.ts.snap index d496f99df0c944446cf1ed1b8836667f015591d4..52da16cfd55d296f36fd487b2e4ca3c90e78eee3 100644 --- a/lib/platform/gitlab/__snapshots__/index.spec.ts.snap +++ b/lib/platform/gitlab/__snapshots__/index.spec.ts.snap @@ -1560,22 +1560,6 @@ Array [ ] `; -exports[`platform/gitlab setBaseBranch(branchName) sets the base branch 1`] = ` -Array [ - Object { - "headers": Object { - "accept": "application/json", - "accept-encoding": "gzip, deflate", - "host": "gitlab.com", - "private-token": "abc123", - "user-agent": "https://github.com/renovatebot/renovate", - }, - "method": "GET", - "url": "https://gitlab.com/api/v4/projects/some%2Frepo", - }, -] -`; - exports[`platform/gitlab setBranchStatus sets branch status green 1`] = ` Array [ Object { diff --git a/lib/platform/gitlab/index.spec.ts b/lib/platform/gitlab/index.spec.ts index 742dd0b92a01e4e47bdc23a4dd0119475c95e67b..804934013ae71ec4de9fc7928557e9820d0c9d84 100644 --- a/lib/platform/gitlab/index.spec.ts +++ b/lib/platform/gitlab/index.spec.ts @@ -329,24 +329,6 @@ describe('platform/gitlab', () => { expect(httpMock.getTrace()).toMatchSnapshot(); }); }); - describe('setBaseBranch(branchName)', () => { - it('sets the base branch', async () => { - httpMock - .scope(gitlabApiHost) - .get(`/api/v4/projects/some%2Frepo`) - .reply(200, { - default_branch: 'master', - http_url_to_repo: `https://gitlab.com/some/repo.git`, - }); - await gitlab.initRepo({ - repository: 'some/repo', - localDir: '', - optimizeForDisabled: false, - }); - await gitlab.setBaseBranch('master'); - expect(httpMock.getTrace()).toMatchSnapshot(); - }); - }); describe('getBranchPr(branchName)', () => { it('should return null if no PR exists', async () => { diff --git a/lib/platform/gitlab/index.ts b/lib/platform/gitlab/index.ts index 3d9dddbd0b92e5035856b6f0d4c87195be937eaa..16fac4a0a3e041fd66b35956cc6e5aa3a67420c1 100644 --- a/lib/platform/gitlab/index.ts +++ b/lib/platform/gitlab/index.ts @@ -248,11 +248,6 @@ export function getRepoForceRebase(): Promise<boolean> { return Promise.resolve(config?.mergeMethod !== 'merge'); } -export async function setBaseBranch(branchName: string): Promise<string> { - const baseBranchSha = await git.setBranch(branchName); - return baseBranchSha; -} - type BranchState = 'pending' | 'running' | 'success' | 'failed' | 'canceled'; interface GitlabBranchStatus { diff --git a/lib/util/git/__snapshots__/index.spec.ts.snap b/lib/util/git/__snapshots__/index.spec.ts.snap index e6464d6277979fb5cf98993d43ff7263d99b5989..fe56ac8e3e050e471b25d85023f35cb4fbb914f9 100644 --- a/lib/util/git/__snapshots__/index.spec.ts.snap +++ b/lib/util/git/__snapshots__/index.spec.ts.snap @@ -1,5 +1,7 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP +exports[`platform/git checkoutBranch(branchName) should throw if branch does not exist 1`] = `[Error: config-validation]`; + exports[`platform/git getBranchCommit(branchName) should throw if branch does not exist 1`] = `[Error: Cannot fetch commit for branch that does not exist: not_found]`; exports[`platform/git getBranchFiles(branchName) detects changed files compared to current base branch 1`] = ` @@ -51,5 +53,3 @@ Array [ exports[`platform/git isBranchModified() should throw if branch does not exist 1`] = `[Error: Cannot check modification for branch that does not exist: not_found]`; exports[`platform/git isBranchStale() should throw if branch does not exist 1`] = `[Error: Cannot check staleness for branch that does not exist: not_found]`; - -exports[`platform/git setBaseBranch(branchName) should throw if branch does not exist 1`] = `[Error: config-validation]`; diff --git a/lib/util/git/index.spec.ts b/lib/util/git/index.spec.ts index cea07dcd81b9631c603ece2e587db82486853ced..971ec39d8ff555e2e6bc82cb4bf3a0ccfbfc4d42 100644 --- a/lib/util/git/index.spec.ts +++ b/lib/util/git/index.spec.ts @@ -84,17 +84,18 @@ describe('platform/git', () => { await base.cleanup(); }); - describe('setBaseBranch(branchName)', () => { + describe('checkoutBranch(branchName)', () => { it('sets the base branch as master', async () => { - await expect(git.setBranch('master')).resolves.not.toThrow(); + await expect(git.checkoutBranch('master')).resolves.not.toThrow(); }); it('sets non-master base branch', async () => { - await expect(git.setBranch('develop')).resolves.not.toThrow(); + await expect(git.checkoutBranch('develop')).resolves.not.toThrow(); }); it('should throw if branch does not exist', async () => { - await expect(git.setBranch('not_found')).rejects.toMatchSnapshot(); + await expect(git.checkoutBranch('not_found')).rejects.toMatchSnapshot(); }); }); + describe('getFileList()', () => { it('should return the correct files', async () => { expect(await git.getFileList()).toMatchSnapshot(); @@ -355,7 +356,7 @@ describe('platform/git', () => { expect(await git.getCommitMessages()).toMatchSnapshot(); - await git.setBranch('develop'); + await git.checkoutBranch('develop'); git.initRepo({ localDir: tmpDir.path, @@ -364,7 +365,7 @@ describe('platform/git', () => { expect(await git.branchExists('test')).toBeTruthy(); - await git.setBranch('test'); + await git.checkoutBranch('test'); const msg = await git.getCommitMessages(); expect(msg).toMatchSnapshot(); diff --git a/lib/util/git/index.ts b/lib/util/git/index.ts index e04811ef2c1b04d0129cb2ce949d8aca5c000a86..a442df648f48283bfccfc79a1c69856165fc28d7 100644 --- a/lib/util/git/index.ts +++ b/lib/util/git/index.ts @@ -336,7 +336,7 @@ export async function getCommitMessages(): Promise<string[]> { return res.all.map((commit) => commit.message); } -export async function setBranch(branchName: string): Promise<CommitSha> { +export async function checkoutBranch(branchName: string): Promise<CommitSha> { await syncGit(); if (!(await branchExists(branchName))) { throwBranchValidationError(branchName); diff --git a/lib/workers/branch/index.ts b/lib/workers/branch/index.ts index 12ed5663d89c4e3badeb96bc94c1c21f6a548ba1..10e7f3bed882eb92491550b060b01bc6dd5d8171 100644 --- a/lib/workers/branch/index.ts +++ b/lib/workers/branch/index.ts @@ -21,6 +21,7 @@ import { emojify } from '../../util/emoji'; import { exec } from '../../util/exec'; import { readLocalFile, writeLocalFile } from '../../util/fs'; import { + checkoutBranch, deleteBranch, getRepoStatus, branchExists as gitBranchExists, @@ -65,7 +66,7 @@ export async function processBranch( `processBranch with ${branchConfig.upgrades.length} upgrades` ); logger.trace({ config }, 'branch config'); - await platform.setBaseBranch(config.baseBranch); + await checkoutBranch(config.baseBranch); const branchExists = await gitBranchExists(config.branchName); const branchPr = await platform.getBranchPr(config.branchName); logger.debug(`branchExists=${branchExists}`); diff --git a/lib/workers/repository/init/index.ts b/lib/workers/repository/init/index.ts index b8004f92c369492c8e7270aebff1efbf0ede540e..6559682e68255b9344dad300871b25ed85c4e7c4 100644 --- a/lib/workers/repository/init/index.ts +++ b/lib/workers/repository/init/index.ts @@ -1,8 +1,7 @@ import { RenovateConfig } from '../../../config'; import { logger } from '../../../logger'; -import { platform } from '../../../platform'; import { clone } from '../../../util/clone'; -import { setBranchPrefix } from '../../../util/git'; +import { checkoutBranch, setBranchPrefix } from '../../../util/git'; import { checkIfConfigured } from '../configured'; import { checkOnboardingBranch } from '../onboarding/branch'; import { initApis } from './apis'; @@ -22,7 +21,7 @@ function initializeConfig(config: RenovateConfig): RenovateConfig { async function getRepoConfig(config_: RenovateConfig): Promise<RenovateConfig> { let config = { ...config_ }; config.baseBranch = config.defaultBranch; - config.baseBranchSha = await platform.setBaseBranch(config.baseBranch); + config.baseBranchSha = await checkoutBranch(config.baseBranch); config.semanticCommits = await detectSemanticCommits(config); config = await checkOnboardingBranch(config); config = await mergeRenovateConfig(config); diff --git a/lib/workers/repository/onboarding/branch/index.spec.ts b/lib/workers/repository/onboarding/branch/index.spec.ts index 19e5994e538cff03c7d52158e4d0335aed456556..f4be1d9bfc1c452fac7a462c312081cfdf8dc1a9 100644 --- a/lib/workers/repository/onboarding/branch/index.spec.ts +++ b/lib/workers/repository/onboarding/branch/index.spec.ts @@ -98,7 +98,7 @@ describe('workers/repository/onboarding/branch', () => { const res = await checkOnboardingBranch(config); expect(res.repoIsOnboarded).toBe(false); expect(res.branchList).toEqual(['renovate/configure']); - expect(platform.setBaseBranch).toHaveBeenCalledTimes(1); + expect(git.checkoutBranch).toHaveBeenCalledTimes(1); expect(git.commitFiles).toHaveBeenCalledTimes(0); }); }); diff --git a/lib/workers/repository/onboarding/branch/index.ts b/lib/workers/repository/onboarding/branch/index.ts index 4e51dbd61b54384e15bb0c0fa6fa6046fd94a77e..2da046e8d9b4c1dcd7f7ccd9df1e38ccd00885f8 100644 --- a/lib/workers/repository/onboarding/branch/index.ts +++ b/lib/workers/repository/onboarding/branch/index.ts @@ -5,6 +5,7 @@ import { } from '../../../../constants/error-messages'; import { logger } from '../../../../logger'; import { platform } from '../../../../platform'; +import { checkoutBranch } from '../../../../util/git'; import { extractAllDependencies } from '../../extract'; import { isOnboarded, onboardingPrExists } from './check'; import { createOnboardingBranch } from './create'; @@ -54,7 +55,7 @@ export async function checkOnboardingBranch( } } if (!config.dryRun) { - await platform.setBaseBranch(config.onboardingBranch); + await checkoutBranch(config.onboardingBranch); } const branchList = [config.onboardingBranch]; return { ...config, repoIsOnboarded, branchList }; diff --git a/lib/workers/repository/process/index.ts b/lib/workers/repository/process/index.ts index 42f86a80f6c17fae8db970ccbb989d9995c9eec2..02e8307c5ec56400d7a31e2366e510325a5ecfe5 100644 --- a/lib/workers/repository/process/index.ts +++ b/lib/workers/repository/process/index.ts @@ -2,13 +2,13 @@ import { RenovateConfig, mergeChildConfig } from '../../../config'; import { logger } from '../../../logger'; import { PackageFile } from '../../../manager/common'; import { platform } from '../../../platform'; -import { branchExists } from '../../../util/git'; +import { branchExists, checkoutBranch } from '../../../util/git'; import { addSplit } from '../../../util/split'; import { BranchConfig } from '../../common'; import { ExtractResult, extract, lookup, update } from './extract-update'; import { WriteUpdateResult } from './write'; -async function setBaseBranch( +async function getBaseBranchConfig( baseBranch: string, config: RenovateConfig ): Promise<RenovateConfig> { @@ -18,7 +18,7 @@ async function setBaseBranch( baseBranchConfig.branchPrefix += `${baseBranch}-`; baseBranchConfig.hasBaseBranches = true; } - baseBranchConfig.baseBranchSha = await platform.setBaseBranch(baseBranch); + baseBranchConfig.baseBranchSha = await checkoutBranch(baseBranch); return baseBranchConfig; } @@ -67,7 +67,7 @@ export async function extractDependencies( const extracted: Record<string, Record<string, PackageFile[]>> = {}; for (const baseBranch of config.baseBranches) { if (await branchExists(baseBranch)) { - const baseBranchConfig = await setBaseBranch(baseBranch, config); + const baseBranchConfig = await getBaseBranchConfig(baseBranch, config); extracted[baseBranch] = await extract(baseBranchConfig); } else { logger.warn({ baseBranch }, 'Base branch does not exist - skipping'); @@ -76,7 +76,7 @@ export async function extractDependencies( addSplit('extract'); for (const baseBranch of config.baseBranches) { if (await branchExists(baseBranch)) { - const baseBranchConfig = await setBaseBranch(baseBranch, config); + const baseBranchConfig = await getBaseBranchConfig(baseBranch, config); const packageFiles = extracted[baseBranch]; const baseBranchRes = await lookup(baseBranchConfig, packageFiles); res.branches = res.branches.concat(baseBranchRes?.branches);