Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: MergeConfidence types #21058

Merged
merged 1 commit into from
Mar 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 6 additions & 0 deletions lib/util/merge-confidence/common.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
export const MERGE_CONFIDENCE = [
'low',
'neutral',
'high',
'very high',
] as const;
5 changes: 4 additions & 1 deletion lib/util/merge-confidence/index.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import * as httpMock from '../../../test/http-mock';
import * as memCache from '../cache/memory';
import * as hostRules from '../host-rules';
import type { MergeConfidence } from './types';
import {
getMergeConfidenceLevel,
isActiveConfidenceLevel,
Expand All @@ -18,7 +19,9 @@ describe('util/merge-confidence/index', () => {
});

it('returns false if nonsense', () => {
expect(isActiveConfidenceLevel('nonsense')).toBeFalse();
expect(
isActiveConfidenceLevel('nonsense' as MergeConfidence)
).toBeFalse();
});

it('returns true if valid value (high)', () => {
Expand Down
10 changes: 4 additions & 6 deletions lib/util/merge-confidence/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,19 @@ import * as memCache from '../cache/memory';
import * as packageCache from '../cache/package';
import * as hostRules from '../host-rules';
import { Http } from '../http';
import { MERGE_CONFIDENCE } from './common';
import type { MergeConfidence } from './types';

const http = new Http('merge-confidence');

const MERGE_CONFIDENCE = ['low', 'neutral', 'high', 'very high'];
type MergeConfidenceTuple = typeof MERGE_CONFIDENCE;
export type MergeConfidence = MergeConfidenceTuple[number];

export const confidenceLevels: Record<MergeConfidence, number> = {
low: -1,
neutral: 0,
high: 1,
'very high': 2,
};

export function isActiveConfidenceLevel(confidence: string): boolean {
export function isActiveConfidenceLevel(confidence: MergeConfidence): boolean {
return confidence !== 'low' && MERGE_CONFIDENCE.includes(confidence);
}

Expand Down Expand Up @@ -76,7 +74,7 @@ export async function getMergeConfidenceLevel(
if (cachedResult) {
return cachedResult;
}
let confidence = 'neutral';
let confidence: MergeConfidence = 'neutral';
try {
const res = (await http.getJson<{ confidence: MergeConfidence }>(url)).body;
if (MERGE_CONFIDENCE.includes(res.confidence)) {
Expand Down
3 changes: 3 additions & 0 deletions lib/util/merge-confidence/types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import type { MERGE_CONFIDENCE } from './common';

export type MergeConfidence = (typeof MERGE_CONFIDENCE)[number];
3 changes: 2 additions & 1 deletion lib/workers/repository/process/lookup/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import type {
RangeConfig,
} from '../../../../modules/manager/types';
import type { SkipReason } from '../../../../types';
import type { MergeConfidence } from '../../../../util/merge-confidence/types';

export interface FilterConfig {
allowedVersions?: string;
Expand Down Expand Up @@ -43,7 +44,7 @@ export interface LookupUpdateConfig
separateMultipleMajor?: boolean;
datasource: string;
packageName: string;
minimumConfidence?: string;
minimumConfidence?: MergeConfidence | undefined;
replacementName?: string;
replacementVersion?: string;
}
Expand Down
8 changes: 3 additions & 5 deletions lib/workers/repository/update/branch/status-checks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,8 @@ import type { RenovateConfig } from '../../../../config/types';
import { logger } from '../../../../logger';
import { platform } from '../../../../modules/platform';
import type { BranchStatus } from '../../../../types';
import {
MergeConfidence,
isActiveConfidenceLevel,
} from '../../../../util/merge-confidence';
import { isActiveConfidenceLevel } from '../../../../util/merge-confidence';
import type { MergeConfidence } from '../../../../util/merge-confidence/types';

export async function resolveBranchStatus(
branchName: string,
Expand Down Expand Up @@ -80,7 +78,7 @@ export async function setStability(config: StabilityConfig): Promise<void> {

export interface ConfidenceConfig extends RenovateConfig {
confidenceStatus?: BranchStatus;
minimumConfidence?: MergeConfidence;
minimumConfidence?: MergeConfidence | undefined;
}

export async function setConfidence(config: ConfidenceConfig): Promise<void> {
Expand Down
4 changes: 2 additions & 2 deletions lib/workers/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import type {
} from '../modules/manager/types';
import type { PlatformPrOptions } from '../modules/platform/types';
import type { FileChange } from '../util/git/types';
import type { MergeConfidence } from '../util/merge-confidence';
import type { MergeConfidence } from '../util/merge-confidence/types';
import type {
ChangeLogRelease,
ChangeLogResult,
Expand Down Expand Up @@ -61,7 +61,7 @@ export interface BranchUpgradeConfig
releases?: ReleaseWithNotes[];
releaseTimestamp?: string;
repoName?: string;
minimumConfidence?: MergeConfidence;
minimumConfidence?: MergeConfidence | undefined;
sourceDirectory?: string;

updatedPackageFiles?: FileChange[];
Expand Down