Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(worker/branch): optimize artifact error handling (#11771)
- Loading branch information
Showing
3 changed files
with
88 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import { getConfig, platform } from '../../../test/util'; | ||
import { setGlobalConfig } from '../../config/global'; | ||
import { BranchStatus } from '../../types'; | ||
import { BranchConfig } from '../types'; | ||
import { setArtifactErrorStatus } from './artifacts'; | ||
|
||
describe('workers/branch/artifacts', () => { | ||
let config: BranchConfig; | ||
beforeEach(() => { | ||
setGlobalConfig({}); | ||
jest.resetAllMocks(); | ||
config = { | ||
...getConfig(), | ||
branchName: 'renovate/pin', | ||
upgrades: [], | ||
artifactErrors: [{ lockFile: 'some' }], | ||
}; | ||
}); | ||
|
||
describe('setArtifactsErrorStatus', () => { | ||
it('adds status', async () => { | ||
platform.getBranchStatusCheck.mockResolvedValueOnce(null); | ||
await setArtifactErrorStatus(config); | ||
expect(platform.setBranchStatus).toHaveBeenCalled(); | ||
}); | ||
|
||
it('skips status', async () => { | ||
platform.getBranchStatusCheck.mockResolvedValueOnce(BranchStatus.red); | ||
await setArtifactErrorStatus(config); | ||
expect(platform.setBranchStatus).not.toHaveBeenCalled(); | ||
}); | ||
|
||
it('skips status (dry-run)', async () => { | ||
setGlobalConfig({ dryRun: true }); | ||
platform.getBranchStatusCheck.mockResolvedValueOnce(null); | ||
await setArtifactErrorStatus(config); | ||
expect(platform.setBranchStatus).not.toHaveBeenCalled(); | ||
}); | ||
|
||
it('skips status (no errors)', async () => { | ||
platform.getBranchStatusCheck.mockResolvedValueOnce(null); | ||
config.artifactErrors.length = 0; | ||
await setArtifactErrorStatus(config); | ||
expect(platform.setBranchStatus).not.toHaveBeenCalled(); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import { getGlobalConfig } from '../../config/global'; | ||
import { logger } from '../../logger'; | ||
import { platform } from '../../platform'; | ||
import { BranchStatus } from '../../types'; | ||
import type { BranchConfig } from '../types'; | ||
|
||
export async function setArtifactErrorStatus( | ||
config: BranchConfig | ||
): Promise<void> { | ||
if (!config.artifactErrors?.length) { | ||
// no errors | ||
return; | ||
} | ||
|
||
const context = `renovate/artifacts`; | ||
const description = 'Artifact file update failure'; | ||
const state = BranchStatus.red; | ||
const existingState = await platform.getBranchStatusCheck( | ||
config.branchName, | ||
context | ||
); | ||
|
||
// Check if state needs setting | ||
if (existingState !== state) { | ||
logger.debug(`Updating status check state to failed`); | ||
if (getGlobalConfig().dryRun) { | ||
logger.info('DRY-RUN: Would set branch status in ' + config.branchName); | ||
} else { | ||
await platform.setBranchStatus({ | ||
branchName: config.branchName, | ||
context, | ||
description, | ||
state, | ||
}); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters