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: Host rule types #28454

Merged
merged 1 commit into from
Apr 17, 2024
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions lib/modules/manager/composer/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import { quote } from 'shlex';
import { GlobalConfig } from '../../../config/global';
import { logger } from '../../../logger';
import type { HostRuleSearchResult } from '../../../types';
import type { CombinedHostRule } from '../../../types';
import type { ToolConstraint } from '../../../util/exec/types';
import { coerceNumber } from '../../../util/number';
import { api, id as composerVersioningId } from '../../versioning/composer';
Expand Down Expand Up @@ -113,6 +113,6 @@ export function extractConstraints(
return res;
}

export function isArtifactAuthEnabled(rule: HostRuleSearchResult): boolean {
export function isArtifactAuthEnabled(rule: CombinedHostRule): boolean {
return !rule.artifactAuth || rule.artifactAuth.includes('composer');
}
9 changes: 6 additions & 3 deletions lib/types/host-rules.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export interface HostRuleSearchResult {
export interface HostRule {
authType?: string;
token?: string;
username?: string;
Expand All @@ -20,11 +20,14 @@ export interface HostRuleSearchResult {
httpsCertificateAuthority?: string;
httpsPrivateKey?: string;
httpsCertificate?: string;
}

export interface HostRule extends HostRuleSearchResult {
encrypted?: HostRule;
hostType?: string;
matchHost?: string;
resolvedHost?: string;
}

export type CombinedHostRule = Omit<
HostRule,
'encrypted' | 'hostType' | 'matchHost' | 'resolvedHost'
>;
2 changes: 1 addition & 1 deletion lib/types/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
export type { CommitMessageJSON } from './commit-message-json';
export type { HostRule, HostRuleSearchResult } from './host-rules';
export type { HostRule, CombinedHostRule } from './host-rules';
export type { SkipReason } from './skip-reason';
export type { RangeStrategy } from './versioning';
export type { BranchStatus } from './branch-status';
Expand Down
4 changes: 2 additions & 2 deletions lib/util/check-token.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { GithubReleaseAttachmentsDatasource } from '../modules/datasource/github
import { GithubReleasesDatasource } from '../modules/datasource/github-releases';
import { GithubTagsDatasource } from '../modules/datasource/github-tags';
import type { PackageFileContent } from '../modules/manager/types';
import type { HostRuleSearchResult } from '../types';
import type { CombinedHostRule } from '../types';
import * as memCache from '../util/cache/memory';
import * as hostRules from './host-rules';

Expand Down Expand Up @@ -73,7 +73,7 @@ export function isGithubFineGrainedPersonalAccessToken(token: string): boolean {
}

export function findGithubToken(
searchResult: HostRuleSearchResult,
searchResult: CombinedHostRule,
): string | undefined {
return searchResult?.token?.replace('x-access-token:', '');
}
Expand Down
4 changes: 2 additions & 2 deletions lib/util/host-rules.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import is from '@sindresorhus/is';
import merge from 'deepmerge';
import { logger } from '../logger';
import type { HostRule, HostRuleSearchResult } from '../types';
import type { CombinedHostRule, HostRule } from '../types';
import { clone } from './clone';
import * as sanitize from './sanitize';
import { toBase64 } from './string';
Expand Down Expand Up @@ -123,7 +123,7 @@ function prioritizeLongestMatchHost(rule1: HostRule, rule2: HostRule): number {
return rule1.matchHost.length - rule2.matchHost.length;
}

export function find(search: HostRuleSearch): HostRuleSearchResult {
export function find(search: HostRuleSearch): CombinedHostRule {
if (!(!!search.hostType || search.url)) {
logger.warn({ search }, 'Invalid hostRules search');
return {};
Expand Down