Skip to content

Commit

Permalink
refactor: merge confidence default undefined (#21059)
Browse files Browse the repository at this point in the history
  • Loading branch information
rarkins committed Mar 21, 2023
1 parent 25e0fa2 commit 3b60c93
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 25 deletions.
14 changes: 7 additions & 7 deletions lib/util/merge-confidence/index.spec.ts
Expand Up @@ -85,7 +85,7 @@ describe('util/merge-confidence/index', () => {
).toBe('high');
});

it('returns neutral if no token', async () => {
it('returns undefined if no token', async () => {
expect(
await getMergeConfidenceLevel(
'npm',
Expand All @@ -94,7 +94,7 @@ describe('util/merge-confidence/index', () => {
'25.0.0',
'major'
)
).toBe('neutral');
).toBeUndefined();
});

it('returns valid confidence level', async () => {
Expand All @@ -120,7 +120,7 @@ describe('util/merge-confidence/index', () => {
).toBe('high');
});

it('returns neutral if invalid confidence level', async () => {
it('returns undefined if invalid confidence level', async () => {
hostRules.add({ hostType: 'merge-confidence', token: '123test' });
const datasource = 'npm';
const depName = 'renovate';
Expand All @@ -140,10 +140,10 @@ describe('util/merge-confidence/index', () => {
newVersion,
'minor'
)
).toBe('neutral');
).toBeUndefined();
});

it('returns neutral if exception from API', async () => {
it('returns undefined if exception from API', async () => {
hostRules.add({ hostType: 'merge-confidence', token: '123test' });
const datasource = 'npm';
const depName = 'renovate';
Expand All @@ -163,7 +163,7 @@ describe('util/merge-confidence/index', () => {
newVersion,
'minor'
)
).toBe('neutral');
).toBeUndefined();

// FIXME: no cache hit
httpMock
Expand All @@ -181,7 +181,7 @@ describe('util/merge-confidence/index', () => {
newVersion,
'minor'
)
).toBe('neutral');
).toBeUndefined();
});

it('returns high if pinning digest', async () => {
Expand Down
8 changes: 4 additions & 4 deletions lib/util/merge-confidence/index.ts
Expand Up @@ -48,7 +48,7 @@ export async function getMergeConfidenceLevel(
currentVersion: string,
newVersion: string,
updateType: UpdateType
): Promise<MergeConfidence> {
): Promise<MergeConfidence | undefined> {
if (!(currentVersion && newVersion && updateType)) {
return 'neutral';
}
Expand All @@ -62,19 +62,19 @@ export async function getMergeConfidenceLevel(
});
if (!token) {
logger.warn('No Merge Confidence API token found');
return 'neutral';
return undefined;
}
// istanbul ignore if
if (memCache.get('merge-confidence-invalid-token')) {
return 'neutral';
return undefined;
}
const url = `https://badges.renovateapi.com/packages/${datasource}/${depName}/${newVersion}/confidence.api/${currentVersion}`;
const cachedResult = await packageCache.get('merge-confidence', token + url);
// istanbul ignore if
if (cachedResult) {
return cachedResult;
}
let confidence: MergeConfidence = 'neutral';
let confidence: MergeConfidence | undefined;
try {
const res = (await http.getJson<{ confidence: MergeConfidence }>(url)).body;
if (MERGE_CONFIDENCE.includes(res.confidence)) {
Expand Down
15 changes: 8 additions & 7 deletions lib/workers/repository/process/lookup/filter-checks.ts
Expand Up @@ -73,13 +73,14 @@ export async function filterInternalChecks(

// TODO #7154
if (isActiveConfidenceLevel(minimumConfidence!)) {
const confidenceLevel = await getMergeConfidenceLevel(
datasource!,
depName!,
currentVersion!,
newVersion,
updateType!
);
const confidenceLevel =
(await getMergeConfidenceLevel(
datasource!,
depName!,
currentVersion!,
newVersion,
updateType!
)) ?? 'neutral';
// TODO #7154
if (!satisfiesConfidenceLevel(confidenceLevel, minimumConfidence!)) {
logger.trace(
Expand Down
15 changes: 8 additions & 7 deletions lib/workers/repository/update/branch/index.ts
Expand Up @@ -311,13 +311,14 @@ export async function processBranch(
const currentVersion = upgrade.currentVersion!;
const newVersion = upgrade.newVersion!;
if (isActiveConfidenceLevel(minimumConfidence)) {
const confidence = await getMergeConfidenceLevel(
datasource,
depName,
currentVersion,
newVersion,
updateType
);
const confidence =
(await getMergeConfidenceLevel(
datasource,
depName,
currentVersion,
newVersion,
updateType
)) ?? 'neutral';
if (satisfiesConfidenceLevel(confidence, minimumConfidence)) {
config.confidenceStatus = 'green';
} else {
Expand Down

0 comments on commit 3b60c93

Please sign in to comment.