From a39ca891014eeeafbcf8d10ea0289d35cf1cecdd Mon Sep 17 00:00:00 2001
From: Sergei Zharinov <zharinov@users.noreply.github.com>
Date: Wed, 17 Apr 2024 02:00:00 -0300
Subject: [PATCH] refactor: Host rule types (#28454)

---
 lib/modules/manager/composer/utils.ts | 4 ++--
 lib/types/host-rules.ts               | 9 ++++++---
 lib/types/index.ts                    | 2 +-
 lib/util/check-token.ts               | 4 ++--
 lib/util/host-rules.ts                | 4 ++--
 5 files changed, 13 insertions(+), 10 deletions(-)

diff --git a/lib/modules/manager/composer/utils.ts b/lib/modules/manager/composer/utils.ts
index 353f2b7d03..89328f611e 100644
--- a/lib/modules/manager/composer/utils.ts
+++ b/lib/modules/manager/composer/utils.ts
@@ -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';
@@ -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');
 }
diff --git a/lib/types/host-rules.ts b/lib/types/host-rules.ts
index 38a571314a..f8a61fd9f7 100644
--- a/lib/types/host-rules.ts
+++ b/lib/types/host-rules.ts
@@ -1,4 +1,4 @@
-export interface HostRuleSearchResult {
+export interface HostRule {
   authType?: string;
   token?: string;
   username?: string;
@@ -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'
+>;
diff --git a/lib/types/index.ts b/lib/types/index.ts
index 8c4a98d7ff..a111c9ade7 100644
--- a/lib/types/index.ts
+++ b/lib/types/index.ts
@@ -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';
diff --git a/lib/util/check-token.ts b/lib/util/check-token.ts
index 48cf641bd9..996b73f1ee 100644
--- a/lib/util/check-token.ts
+++ b/lib/util/check-token.ts
@@ -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';
 
@@ -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:', '');
 }
diff --git a/lib/util/host-rules.ts b/lib/util/host-rules.ts
index 19e3addbb0..de5ea2bd27 100644
--- a/lib/util/host-rules.ts
+++ b/lib/util/host-rules.ts
@@ -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';
@@ -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 {};
-- 
GitLab