From 14c5227ce3959989bad0a68cf907b6e9b331a54f Mon Sep 17 00:00:00 2001 From: Rhys Arkins <rhys@arkins.net> Date: Thu, 15 Apr 2021 19:06:55 +0200 Subject: [PATCH] refactor: ProcessBranchResult -> BranchResult --- lib/workers/branch/index.spec.ts | 54 +++++++++---------- lib/workers/branch/index.ts | 48 ++++++++--------- .../repository/dependency-dashboard.spec.ts | 50 ++++++++--------- .../repository/dependency-dashboard.ts | 48 ++++++++--------- lib/workers/repository/process/write.spec.ts | 20 +++---- lib/workers/repository/process/write.ts | 6 +-- lib/workers/types.ts | 4 +- 7 files changed, 109 insertions(+), 121 deletions(-) diff --git a/lib/workers/branch/index.spec.ts b/lib/workers/branch/index.spec.ts index d24742e00e..7fa841bb71 100644 --- a/lib/workers/branch/index.spec.ts +++ b/lib/workers/branch/index.spec.ts @@ -23,7 +23,7 @@ import type { EnsurePrResult } from '../pr'; import * as _prAutomerge from '../pr/automerge'; import type { Pr } from '../repository/onboarding/branch/check'; import type { BranchConfig, BranchUpgradeConfig } from '../types'; -import { PrResult, ProcessBranchResult } from '../types'; +import { BranchResult, PrResult } from '../types'; import * as _automerge from './automerge'; import * as _checkExisting from './check-existing'; import * as _commit from './commit'; @@ -106,14 +106,14 @@ describe(getName(__filename), () => { it('skips branch if not scheduled and branch does not exist', async () => { schedule.isScheduledNow.mockReturnValueOnce(false); const res = await branchWorker.processBranch(config); - expect(res).toEqual(ProcessBranchResult.NotScheduled); + expect(res).toEqual(BranchResult.NotScheduled); }); it('skips branch if not scheduled and not updating out of schedule', async () => { schedule.isScheduledNow.mockReturnValueOnce(false); config.updateNotScheduled = false; git.branchExists.mockReturnValueOnce(true); const res = await branchWorker.processBranch(config); - expect(res).toEqual(ProcessBranchResult.NotScheduled); + expect(res).toEqual(BranchResult.NotScheduled); }); it('skips branch for fresh release with stabilityDays', async () => { schedule.isScheduledNow.mockReturnValueOnce(true); @@ -136,7 +136,7 @@ describe(getName(__filename), () => { git.branchExists.mockReturnValueOnce(false); const res = await branchWorker.processBranch(config); - expect(res).toEqual(ProcessBranchResult.Pending); + expect(res).toEqual(BranchResult.Pending); }); it('skips branch if not stabilityDays not met', async () => { schedule.isScheduledNow.mockReturnValueOnce(true); @@ -148,7 +148,7 @@ describe(getName(__filename), () => { }, ]; const res = await branchWorker.processBranch(config); - expect(res).toEqual(ProcessBranchResult.Pending); + expect(res).toEqual(BranchResult.Pending); }); it('processes branch if not scheduled but updating out of schedule', async () => { schedule.isScheduledNow.mockReturnValueOnce(false); @@ -223,7 +223,7 @@ describe(getName(__filename), () => { } as Pr); git.isBranchModified.mockResolvedValueOnce(true); const res = await branchWorker.processBranch(config); - expect(res).not.toEqual(ProcessBranchResult.PrEdited); + expect(res).not.toEqual(BranchResult.PrEdited); }); it('skips branch if edited PR found', async () => { schedule.isScheduledNow.mockReturnValueOnce(false); @@ -234,7 +234,7 @@ describe(getName(__filename), () => { } as Pr); git.isBranchModified.mockResolvedValueOnce(true); const res = await branchWorker.processBranch(config); - expect(res).toEqual(ProcessBranchResult.PrEdited); + expect(res).toEqual(BranchResult.PrEdited); }); it('skips branch if target branch changed', async () => { schedule.isScheduledNow.mockReturnValueOnce(false); @@ -246,13 +246,13 @@ describe(getName(__filename), () => { git.isBranchModified.mockResolvedValueOnce(false); config.baseBranch = 'master'; const res = await branchWorker.processBranch(config); - expect(res).toEqual(ProcessBranchResult.PrEdited); + expect(res).toEqual(BranchResult.PrEdited); }); it('skips branch if branch edited and no PR found', async () => { git.branchExists.mockReturnValueOnce(true); git.isBranchModified.mockResolvedValueOnce(true); const res = await branchWorker.processBranch(config); - expect(res).toEqual(ProcessBranchResult.PrEdited); + expect(res).toEqual(BranchResult.PrEdited); }); it('continues branch if branch edited and but PR found', async () => { git.branchExists.mockReturnValueOnce(true); @@ -260,7 +260,7 @@ describe(getName(__filename), () => { git.getBranchCommit.mockReturnValueOnce('abc123'); platform.findPr.mockResolvedValueOnce({ sha: 'abc123' } as any); const res = await branchWorker.processBranch(config); - expect(res).toEqual(ProcessBranchResult.Error); + expect(res).toEqual(BranchResult.Error); }); it('skips branch if branch edited and and PR found with sha mismatch', async () => { git.branchExists.mockReturnValueOnce(true); @@ -268,7 +268,7 @@ describe(getName(__filename), () => { git.getBranchCommit.mockReturnValueOnce('abc123'); platform.findPr.mockResolvedValueOnce({ sha: 'def456' } as any); const res = await branchWorker.processBranch(config); - expect(res).toEqual(ProcessBranchResult.PrEdited); + expect(res).toEqual(BranchResult.PrEdited); }); it('returns if branch creation limit exceeded', async () => { getUpdated.getUpdatedPackageFiles.mockResolvedValueOnce({ @@ -281,7 +281,7 @@ describe(getName(__filename), () => { limits.isLimitReached.mockReturnValueOnce(true); limits.isLimitReached.mockReturnValueOnce(false); expect(await branchWorker.processBranch(config)).toEqual( - ProcessBranchResult.BranchLimitReached + BranchResult.BranchLimitReached ); }); it('returns if pr creation limit exceeded and branch exists', async () => { @@ -298,7 +298,7 @@ describe(getName(__filename), () => { }); limits.isLimitReached.mockReturnValue(false); expect(await branchWorker.processBranch(config)).toEqual( - ProcessBranchResult.PrLimitReached + BranchResult.PrLimitReached ); }); it('returns if commit limit exceeded', async () => { @@ -313,7 +313,7 @@ describe(getName(__filename), () => { limits.isLimitReached.mockReturnValueOnce(false); limits.isLimitReached.mockReturnValueOnce(true); expect(await branchWorker.processBranch(config)).toEqual( - ProcessBranchResult.CommitLimitReached + BranchResult.CommitLimitReached ); }); it('returns if no work', async () => { @@ -327,7 +327,7 @@ describe(getName(__filename), () => { git.branchExists.mockReturnValueOnce(false); commit.commitFilesToBranch.mockResolvedValueOnce(null); expect(await branchWorker.processBranch(config)).toEqual( - ProcessBranchResult.NoWork + BranchResult.NoWork ); }); it('returns if branch automerged', async () => { @@ -395,7 +395,7 @@ describe(getName(__filename), () => { prResult: PrResult.AwaitingApproval, }); expect(await branchWorker.processBranch(config)).toEqual( - ProcessBranchResult.NeedsPrApproval + BranchResult.NeedsPrApproval ); }); it('returns if branch exists but pending', async () => { @@ -414,7 +414,7 @@ describe(getName(__filename), () => { prResult: PrResult.AwaitingNotPending, }); expect(await branchWorker.processBranch(config)).toEqual( - ProcessBranchResult.Pending + BranchResult.Pending ); }); it('returns if branch exists but updated', async () => { @@ -432,7 +432,7 @@ describe(getName(__filename), () => { requiredStatusChecks: null, prCreation: 'not-pending', }) - ).toEqual(ProcessBranchResult.Pending); + ).toEqual(BranchResult.Pending); expect(automerge.tryBranchAutomerge).toHaveBeenCalledTimes(0); expect(prWorker.ensurePr).toHaveBeenCalledTimes(0); @@ -607,7 +607,7 @@ describe(getName(__filename), () => { } as Pr); setAdminConfig({ dryRun: true }); expect(await branchWorker.processBranch(config)).toEqual( - ProcessBranchResult.AlreadyExisted + BranchResult.AlreadyExisted ); }); @@ -619,7 +619,7 @@ describe(getName(__filename), () => { git.isBranchModified.mockResolvedValueOnce(true); setAdminConfig({ dryRun: true }); expect(await branchWorker.processBranch(config)).toEqual( - ProcessBranchResult.PrEdited + BranchResult.PrEdited ); }); @@ -649,7 +649,7 @@ describe(getName(__filename), () => { reuseExistingBranch: false, updatedArtifacts: [{ name: '|delete|', contents: 'dummy' }], }) - ).toEqual(ProcessBranchResult.Done); + ).toEqual(BranchResult.Done); }); it('branch pr no schedule (dry run)', async () => { @@ -680,7 +680,7 @@ describe(getName(__filename), () => { ...config, artifactErrors: [{}], }) - ).toEqual(ProcessBranchResult.Done); + ).toEqual(BranchResult.Done); }); it('branch pr no schedule', async () => { @@ -708,7 +708,7 @@ describe(getName(__filename), () => { reuseExistingBranch: false, updatedArtifacts: [{ name: '|delete|', contents: 'dummy' }], }) - ).toEqual(ProcessBranchResult.Done); + ).toEqual(BranchResult.Done); }); it('executes post-upgrade tasks if trust is high', async () => { @@ -776,7 +776,7 @@ describe(getName(__filename), () => { ], }); - expect(result).toEqual(ProcessBranchResult.Done); + expect(result).toEqual(BranchResult.Done); expect(exec.exec).toHaveBeenCalledWith('echo semver', { cwd: '/localDir', }); @@ -924,7 +924,7 @@ describe(getName(__filename), () => { ], }); - expect(result).toEqual(ProcessBranchResult.Done); + expect(result).toEqual(BranchResult.Done); expect(exec.exec).toHaveBeenCalledWith('echo {{{versioning}}}', { cwd: '/localDir', }); @@ -1031,7 +1031,7 @@ describe(getName(__filename), () => { const result = await branchWorker.processBranch(inconfig); - expect(result).toEqual(ProcessBranchResult.Done); + expect(result).toEqual(BranchResult.Done); expect(exec.exec).toHaveBeenNthCalledWith(1, 'echo some-dep-name-1', { cwd: '/localDir', }); @@ -1160,7 +1160,7 @@ describe(getName(__filename), () => { }; const result = await branchWorker.processBranch(inconfig); - expect(result).toEqual(ProcessBranchResult.Done); + expect(result).toEqual(BranchResult.Done); expect(exec.exec).toHaveBeenNthCalledWith(1, 'echo hardcoded-string', { cwd: '/localDir', }); diff --git a/lib/workers/branch/index.ts b/lib/workers/branch/index.ts index d2b2576b36..aeb36e100a 100644 --- a/lib/workers/branch/index.ts +++ b/lib/workers/branch/index.ts @@ -29,7 +29,7 @@ import { import { Limit, isLimitReached } from '../global/limits'; import { ensurePr, getPlatformPrOptions } from '../pr'; import { checkAutoMerge } from '../pr/automerge'; -import { BranchConfig, PrResult, ProcessBranchResult } from '../types'; +import { BranchConfig, BranchResult, PrResult } from '../types'; import { tryBranchAutomerge } from './automerge'; import { prAlreadyExisted } from './check-existing'; import { commitFilesToBranch } from './commit'; @@ -61,7 +61,7 @@ async function deleteBranchSilently(branchName: string): Promise<void> { export async function processBranch( branchConfig: BranchConfig -): Promise<ProcessBranchResult> { +): Promise<BranchResult> { let config: BranchConfig = { ...branchConfig }; const dependencies = config.upgrades .map((upgrade) => upgrade.depName) @@ -139,7 +139,7 @@ export async function processBranch( 'Merged PR is blocking this branch' ); } - return ProcessBranchResult.AlreadyExisted; + return BranchResult.AlreadyExisted; } // istanbul ignore if if (!branchExists && config.dependencyDashboardApproval) { @@ -147,7 +147,7 @@ export async function processBranch( logger.debug(`Branch ${config.branchName} is approved for creation`); } else { logger.debug(`Branch ${config.branchName} needs approval`); - return ProcessBranchResult.NeedsApproval; + return BranchResult.NeedsApproval; } } if ( @@ -157,7 +157,7 @@ export async function processBranch( !config.isVulnerabilityAlert ) { logger.debug('Reached branch limit - skipping branch creation'); - return ProcessBranchResult.BranchLimitReached; + return BranchResult.BranchLimitReached; } if ( isLimitReached(Limit.Commits) && @@ -165,7 +165,7 @@ export async function processBranch( !config.isVulnerabilityAlert ) { logger.debug('Reached commits limit - skipping branch'); - return ProcessBranchResult.CommitLimitReached; + return BranchResult.CommitLimitReached; } if (branchExists) { logger.debug('Checking if PR has been edited'); @@ -202,7 +202,7 @@ export async function processBranch( platformOptions: getPlatformPrOptions(config), }); } - return ProcessBranchResult.PrEdited; + return BranchResult.PrEdited; } } } else if (branchIsModified) { @@ -212,7 +212,7 @@ export async function processBranch( }); if (!oldPr) { logger.debug('Branch has been edited but found no PR - skipping'); - return ProcessBranchResult.PrEdited; + return BranchResult.PrEdited; } const branchSha = getBranchCommit(config.branchName); const oldPrSha = oldPr?.sha; @@ -226,7 +226,7 @@ export async function processBranch( { oldPrNumber: oldPr.number, oldPrSha, branchSha }, 'Found old PR but the SHA is different' ); - return ProcessBranchResult.PrEdited; + return BranchResult.PrEdited; } } } @@ -236,16 +236,16 @@ export async function processBranch( if (!config.isScheduledNow && !dependencyDashboardCheck) { if (!branchExists) { logger.debug('Skipping branch creation as not within schedule'); - return ProcessBranchResult.NotScheduled; + return BranchResult.NotScheduled; } if (config.updateNotScheduled === false && !config.rebaseRequested) { logger.debug('Skipping branch update as not within schedule'); - return ProcessBranchResult.NotScheduled; + return BranchResult.NotScheduled; } // istanbul ignore if if (!branchPr) { logger.debug('Skipping PR creation out of schedule'); - return ProcessBranchResult.NotScheduled; + return BranchResult.NotScheduled; } logger.debug( 'Branch + PR exists but is not scheduled -- will update if necessary' @@ -293,7 +293,7 @@ export async function processBranch( ['not-pending', 'status-success'].includes(config.prCreation) ) { logger.debug('Skipping branch creation due to stability days not met'); - return ProcessBranchResult.Pending; + return BranchResult.Pending; } } @@ -399,7 +399,7 @@ export async function processBranch( await platform.refreshPr(branchPr.number); } if (!commitSha && !branchExists) { - return ProcessBranchResult.NoWork; + return BranchResult.NoWork; } if (commitSha) { const action = branchExists ? 'updated' : 'created'; @@ -416,7 +416,7 @@ export async function processBranch( (config.requiredStatusChecks?.length || config.prCreation !== 'immediate') ) { logger.debug({ commitSha }, `Branch status pending`); - return ProcessBranchResult.Pending; + return BranchResult.Pending; } // Try to automerge branch and finish if successful, but only if branch already existed before this run @@ -426,7 +426,7 @@ export async function processBranch( if (mergeStatus === 'automerged') { await deleteBranchSilently(config.branchName); logger.debug('Branch is automerged - returning'); - return ProcessBranchResult.Automerged; + return BranchResult.Automerged; } if ( mergeStatus === 'automerge aborted - PR exists' || @@ -490,7 +490,7 @@ export async function processBranch( logger.warn('Error updating branch: update failure'); } else if (err.message.startsWith('bundler-')) { // we have already warned inside the bundler artifacts error handling, so just return - return ProcessBranchResult.Error; + return BranchResult.Error; } else if ( err.messagee && err.message.includes('fatal: Authentication failed') @@ -509,7 +509,7 @@ export async function processBranch( logger.warn({ err }, `Error updating branch`); } // Don't throw here - we don't want to stop the other renovations - return ProcessBranchResult.Error; + return BranchResult.Error; } try { logger.debug('Ensuring PR'); @@ -519,17 +519,17 @@ export async function processBranch( const { prResult: result, pr } = await ensurePr(config); if (result === PrResult.LimitReached && !config.isVulnerabilityAlert) { logger.debug('Reached PR limit - skipping PR creation'); - return ProcessBranchResult.PrLimitReached; + return BranchResult.PrLimitReached; } // TODO: ensurePr should check for automerge itself if (result === PrResult.AwaitingApproval) { - return ProcessBranchResult.NeedsPrApproval; + return BranchResult.NeedsPrApproval; } if ( result === PrResult.AwaitingGreenBranch || result === PrResult.AwaitingNotPending ) { - return ProcessBranchResult.Pending; + return BranchResult.Pending; } if (pr) { if (config.artifactErrors?.length) { @@ -603,7 +603,7 @@ export async function processBranch( logger.debug('PR is configured for automerge'); const prAutomergeResult = await checkAutoMerge(pr, config); if (prAutomergeResult?.automerged) { - return ProcessBranchResult.Automerged; + return BranchResult.Automerged; } } else { logger.debug('PR is not configured for automerge'); @@ -621,7 +621,7 @@ export async function processBranch( logger.error({ err }, `Error ensuring PR: ${String(err.message)}`); } if (!branchExists) { - return ProcessBranchResult.PrCreated; + return BranchResult.PrCreated; } - return ProcessBranchResult.Done; + return BranchResult.Done; } diff --git a/lib/workers/repository/dependency-dashboard.spec.ts b/lib/workers/repository/dependency-dashboard.spec.ts index caaa22e988..67bf63f17c 100644 --- a/lib/workers/repository/dependency-dashboard.spec.ts +++ b/lib/workers/repository/dependency-dashboard.spec.ts @@ -12,11 +12,7 @@ import { setAdminConfig } from '../../config/admin'; import { PLATFORM_TYPE_GITHUB } from '../../constants/platforms'; import { Platform, Pr } from '../../platform'; import { PrState } from '../../types'; -import { - BranchConfig, - BranchUpgradeConfig, - ProcessBranchResult, -} from '../types'; +import { BranchConfig, BranchResult, BranchUpgradeConfig } from '../types'; import * as dependencyDashboard from './dependency-dashboard'; type PrUpgrade = BranchUpgradeConfig; @@ -111,12 +107,12 @@ describe(getName(__filename), () => { { ...mock<BranchConfig>(), prTitle: 'pr1', - res: ProcessBranchResult.Automerged, + result: BranchResult.Automerged, }, { ...mock<BranchConfig>(), prTitle: 'pr2', - res: ProcessBranchResult.Automerged, + result: BranchResult.Automerged, dependencyDashboardApproval: false, }, ]; @@ -182,56 +178,56 @@ describe(getName(__filename), () => { ...mock<BranchConfig>(), prTitle: 'pr1', upgrades: [{ ...mock<BranchUpgradeConfig>(), depName: 'dep1' }], - res: ProcessBranchResult.NeedsApproval, + result: BranchResult.NeedsApproval, branchName: 'branchName1', }, { ...mock<BranchConfig>(), prTitle: 'pr2', upgrades: [{ ...mock<PrUpgrade>(), depName: 'dep2' }], - res: ProcessBranchResult.NeedsApproval, + result: BranchResult.NeedsApproval, branchName: 'branchName2', }, { ...mock<BranchConfig>(), prTitle: 'pr3', upgrades: [{ ...mock<PrUpgrade>(), depName: 'dep3' }], - res: ProcessBranchResult.NotScheduled, + result: BranchResult.NotScheduled, branchName: 'branchName3', }, { ...mock<BranchConfig>(), prTitle: 'pr4', upgrades: [{ ...mock<PrUpgrade>(), depName: 'dep4' }], - res: ProcessBranchResult.NotScheduled, + result: BranchResult.NotScheduled, branchName: 'branchName4', }, { ...mock<BranchConfig>(), prTitle: 'pr5', upgrades: [{ ...mock<PrUpgrade>(), depName: 'dep5' }], - res: ProcessBranchResult.PrLimitReached, + result: BranchResult.PrLimitReached, branchName: 'branchName5', }, { ...mock<BranchConfig>(), prTitle: 'pr6', upgrades: [{ ...mock<PrUpgrade>(), depName: 'dep6' }], - res: ProcessBranchResult.PrLimitReached, + result: BranchResult.PrLimitReached, branchName: 'branchName6', }, { ...mock<BranchConfig>(), prTitle: 'pr7', upgrades: [{ ...mock<PrUpgrade>(), depName: 'dep7' }], - res: ProcessBranchResult.Error, + result: BranchResult.Error, branchName: 'branchName7', }, { ...mock<BranchConfig>(), prTitle: 'pr8', upgrades: [{ ...mock<PrUpgrade>(), depName: 'dep8' }], - res: ProcessBranchResult.Error, + result: BranchResult.Error, branchName: 'branchName8', }, ]; @@ -261,7 +257,7 @@ describe(getName(__filename), () => { ...mock<BranchConfig>(), prTitle: 'pr1', upgrades: [{ ...mock<PrUpgrade>(), depName: 'dep1' }], - res: ProcessBranchResult.PrEdited, + result: BranchResult.PrEdited, branchName: 'branchName1', }, { @@ -271,7 +267,7 @@ describe(getName(__filename), () => { { ...mock<PrUpgrade>(), depName: 'dep2' }, { ...mock<PrUpgrade>(), depName: 'dep3' }, ], - res: ProcessBranchResult.PrEdited, + result: BranchResult.PrEdited, branchName: 'branchName2', }, ]; @@ -306,7 +302,7 @@ describe(getName(__filename), () => { ...mock<BranchConfig>(), prTitle: 'pr1', upgrades: [{ ...mock<PrUpgrade>(), depName: 'dep1' }], - res: ProcessBranchResult.Rebase, + result: BranchResult.Rebase, branchName: 'branchName1', }, { @@ -316,14 +312,14 @@ describe(getName(__filename), () => { { ...mock<PrUpgrade>(), depName: 'dep2' }, { ...mock<PrUpgrade>(), depName: 'dep3' }, ], - res: ProcessBranchResult.Rebase, + result: BranchResult.Rebase, branchName: 'branchName2', }, { ...mock<BranchConfig>(), prTitle: 'pr3', upgrades: [{ ...mock<PrUpgrade>(), depName: 'dep3' }], - res: ProcessBranchResult.Rebase, + result: BranchResult.Rebase, branchName: 'branchName3', }, ]; @@ -360,7 +356,7 @@ describe(getName(__filename), () => { ...mock<BranchConfig>(), prTitle: 'pr1', upgrades: [{ ...mock<PrUpgrade>(), depName: 'dep1' }], - res: ProcessBranchResult.AlreadyExisted, + result: BranchResult.AlreadyExisted, branchName: 'branchName1', }, { @@ -370,7 +366,7 @@ describe(getName(__filename), () => { { ...mock<PrUpgrade>(), depName: 'dep2' }, { ...mock<PrUpgrade>(), depName: 'dep3' }, ], - res: ProcessBranchResult.AlreadyExisted, + result: BranchResult.AlreadyExisted, branchName: 'branchName2', }, ]; @@ -410,7 +406,7 @@ describe(getName(__filename), () => { ...mock<BranchConfig>(), prTitle: 'pr1', upgrades: [{ ...mock<PrUpgrade>(), depName: 'dep1' }], - res: ProcessBranchResult.NeedsPrApproval, + result: BranchResult.NeedsPrApproval, branchName: 'branchName1', }, { @@ -420,21 +416,21 @@ describe(getName(__filename), () => { { ...mock<PrUpgrade>(), depName: 'dep2' }, { ...mock<PrUpgrade>(), depName: 'dep3' }, ], - res: ProcessBranchResult.NeedsPrApproval, + result: BranchResult.NeedsPrApproval, branchName: 'branchName2', }, { ...mock<BranchConfig>(), prTitle: 'pr3', upgrades: [{ ...mock<PrUpgrade>(), depName: 'dep3' }], - res: ProcessBranchResult.NeedsPrApproval, + result: BranchResult.NeedsPrApproval, branchName: 'branchName3', }, { ...mock<BranchConfig>(), prTitle: 'pr4', upgrades: [{ ...mock<PrUpgrade>(), depName: 'dep4' }], - res: ProcessBranchResult.Pending, + result: BranchResult.Pending, branchName: 'branchName4', }, ]; @@ -466,7 +462,7 @@ describe(getName(__filename), () => { upgrades: [ { ...mock<PrUpgrade>(), depName: 'dep1', repository: 'repo1' }, ], - res: ProcessBranchResult.Pending, + result: BranchResult.Pending, branchName: 'branchName1', }, ]; diff --git a/lib/workers/repository/dependency-dashboard.ts b/lib/workers/repository/dependency-dashboard.ts index 0bfc51b8e2..2d57520cdc 100644 --- a/lib/workers/repository/dependency-dashboard.ts +++ b/lib/workers/repository/dependency-dashboard.ts @@ -5,7 +5,7 @@ import { getAdminConfig } from '../../config/admin'; import { getProblems, logger } from '../../logger'; import { Pr, platform } from '../../platform'; import { PrState } from '../../types'; -import { BranchConfig, ProcessBranchResult } from '../types'; +import { BranchConfig, BranchResult } from '../types'; function getListItem(branch: BranchConfig, type: string, pr?: Pr): string { let item = ' - [ ] '; @@ -77,7 +77,7 @@ export async function ensureMasterIssue( logger.debug('Ensuring Dependency Dashboard'); const hasBranches = is.nonEmptyArray(branches) && - branches.some((branch) => branch.res !== ProcessBranchResult.Automerged); + branches.some((branch) => branch.result !== BranchResult.Automerged); if (config.dependencyDashboardAutoclose && !hasBranches) { if (getAdminConfig().dryRun) { logger.info( @@ -98,7 +98,7 @@ export async function ensureMasterIssue( issueBody = appendRepoProblems(config, issueBody); const pendingApprovals = branches.filter( - (branch) => branch.res === ProcessBranchResult.NeedsApproval + (branch) => branch.result === BranchResult.NeedsApproval ); if (pendingApprovals.length) { issueBody += '## Pending Approval\n\n'; @@ -109,7 +109,7 @@ export async function ensureMasterIssue( issueBody += '\n'; } const awaitingSchedule = branches.filter( - (branch) => branch.res === ProcessBranchResult.NotScheduled + (branch) => branch.result === BranchResult.NotScheduled ); if (awaitingSchedule.length) { issueBody += '## Awaiting Schedule\n\n'; @@ -122,9 +122,9 @@ export async function ensureMasterIssue( } const rateLimited = branches.filter( (branch) => - branch.res === ProcessBranchResult.BranchLimitReached || - branch.res === ProcessBranchResult.PrLimitReached || - branch.res === ProcessBranchResult.CommitLimitReached + branch.result === BranchResult.BranchLimitReached || + branch.result === BranchResult.PrLimitReached || + branch.result === BranchResult.CommitLimitReached ); if (rateLimited.length) { issueBody += '## Rate Limited\n\n'; @@ -136,7 +136,7 @@ export async function ensureMasterIssue( issueBody += '\n'; } const errorList = branches.filter( - (branch) => branch.res === ProcessBranchResult.Error + (branch) => branch.result === BranchResult.Error ); if (errorList.length) { issueBody += '## Errored\n\n'; @@ -148,7 +148,7 @@ export async function ensureMasterIssue( issueBody += '\n'; } const awaitingPr = branches.filter( - (branch) => branch.res === ProcessBranchResult.NeedsPrApproval + (branch) => branch.result === BranchResult.NeedsPrApproval ); if (awaitingPr.length) { issueBody += '## PR Creation Approval Required\n\n'; @@ -160,7 +160,7 @@ export async function ensureMasterIssue( issueBody += '\n'; } const prEdited = branches.filter( - (branch) => branch.res === ProcessBranchResult.PrEdited + (branch) => branch.result === BranchResult.PrEdited ); if (prEdited.length) { issueBody += '## Edited/Blocked\n\n'; @@ -172,7 +172,7 @@ export async function ensureMasterIssue( issueBody += '\n'; } const prPending = branches.filter( - (branch) => branch.res === ProcessBranchResult.Pending + (branch) => branch.result === BranchResult.Pending ); if (prPending.length) { issueBody += '## Pending Status Checks\n\n'; @@ -183,20 +183,20 @@ export async function ensureMasterIssue( issueBody += '\n'; } const otherRes = [ - ProcessBranchResult.Pending, - ProcessBranchResult.NeedsApproval, - ProcessBranchResult.NeedsPrApproval, - ProcessBranchResult.NotScheduled, - ProcessBranchResult.PrLimitReached, - ProcessBranchResult.CommitLimitReached, - ProcessBranchResult.BranchLimitReached, - ProcessBranchResult.AlreadyExisted, - ProcessBranchResult.Error, - ProcessBranchResult.Automerged, - ProcessBranchResult.PrEdited, + BranchResult.Pending, + BranchResult.NeedsApproval, + BranchResult.NeedsPrApproval, + BranchResult.NotScheduled, + BranchResult.PrLimitReached, + BranchResult.CommitLimitReached, + BranchResult.BranchLimitReached, + BranchResult.AlreadyExisted, + BranchResult.Error, + BranchResult.Automerged, + BranchResult.PrEdited, ]; const inProgress = branches.filter( - (branch) => !otherRes.includes(branch.res) + (branch) => !otherRes.includes(branch.result) ); if (inProgress.length) { issueBody += '## Open\n\n'; @@ -216,7 +216,7 @@ export async function ensureMasterIssue( issueBody += '\n'; } const alreadyExisted = branches.filter( - (branch) => branch.res === ProcessBranchResult.AlreadyExisted + (branch) => branch.result === BranchResult.AlreadyExisted ); if (alreadyExisted.length) { issueBody += '## Ignored or Blocked\n\n'; diff --git a/lib/workers/repository/process/write.spec.ts b/lib/workers/repository/process/write.spec.ts index 5a2c4ee636..22a5b1caa1 100644 --- a/lib/workers/repository/process/write.spec.ts +++ b/lib/workers/repository/process/write.spec.ts @@ -7,7 +7,7 @@ import { } from '../../../../test/util'; import * as _branchWorker from '../../branch'; import { Limit, isLimitReached } from '../../global/limits'; -import { BranchConfig, ProcessBranchResult } from '../../types'; +import { BranchConfig, BranchResult } from '../../types'; import * as _limits from './limits'; import { writeUpdates } from './write'; @@ -49,27 +49,19 @@ describe(getName(__filename), () => { {}, ] as never; git.branchExists.mockReturnValue(true); + branchWorker.processBranch.mockResolvedValueOnce(BranchResult.PrCreated); branchWorker.processBranch.mockResolvedValueOnce( - ProcessBranchResult.PrCreated - ); - branchWorker.processBranch.mockResolvedValueOnce( - ProcessBranchResult.AlreadyExisted - ); - branchWorker.processBranch.mockResolvedValueOnce( - ProcessBranchResult.Automerged - ); - branchWorker.processBranch.mockResolvedValueOnce( - ProcessBranchResult.Automerged + BranchResult.AlreadyExisted ); + branchWorker.processBranch.mockResolvedValueOnce(BranchResult.Automerged); + branchWorker.processBranch.mockResolvedValueOnce(BranchResult.Automerged); const res = await writeUpdates(config, branches); expect(res).toEqual('automerged'); expect(branchWorker.processBranch).toHaveBeenCalledTimes(4); }); it('increments branch counter', async () => { const branches: BranchConfig[] = [{}] as never; - branchWorker.processBranch.mockResolvedValueOnce( - ProcessBranchResult.PrCreated - ); + branchWorker.processBranch.mockResolvedValueOnce(BranchResult.PrCreated); git.branchExists.mockReturnValueOnce(false); git.branchExists.mockReturnValueOnce(true); limits.getBranchesRemaining.mockReturnValueOnce(1); diff --git a/lib/workers/repository/process/write.ts b/lib/workers/repository/process/write.ts index b6ebcdf108..de95d94e5b 100644 --- a/lib/workers/repository/process/write.ts +++ b/lib/workers/repository/process/write.ts @@ -3,7 +3,7 @@ import { addMeta, logger, removeMeta } from '../../../logger'; import { branchExists } from '../../../util/git'; import { processBranch } from '../../branch'; import { Limit, incLimitedValue, setMaxLimit } from '../../global/limits'; -import { BranchConfig, ProcessBranchResult } from '../../types'; +import { BranchConfig, BranchResult } from '../../types'; import { getBranchesRemaining, getPrsRemaining } from './limits'; export type WriteUpdateResult = 'done' | 'automerged'; @@ -44,9 +44,9 @@ export async function writeUpdates( addMeta({ branch: branch.branchName }); const branchExisted = branchExists(branch.branchName); const res = await processBranch(branch); - branch.res = res; + branch.result = res; if ( - res === ProcessBranchResult.Automerged && + res === BranchResult.Automerged && branch.automergeType !== 'pr-comment' ) { // Stop processing other branches because base branch has been changed diff --git a/lib/workers/types.ts b/lib/workers/types.ts index 27141cc31c..5e9fca00d4 100644 --- a/lib/workers/types.ts +++ b/lib/workers/types.ts @@ -79,7 +79,7 @@ export enum PrResult { LimitReached = 'LimitReached', } -export enum ProcessBranchResult { +export enum BranchResult { AlreadyExisted = 'already-existed', Automerged = 'automerged', Done = 'done', @@ -110,7 +110,7 @@ export interface BranchConfig releaseTimestamp?: string; forceCommit?: boolean; rebaseRequested?: boolean; - res?: ProcessBranchResult; + result?: BranchResult; upgrades: BranchUpgradeConfig[]; packageFiles?: Record<string, PackageFile[]>; } -- GitLab