Skip to content

Commit

Permalink
refactor: extract more types (#9959)
Browse files Browse the repository at this point in the history
  • Loading branch information
viceice committed May 11, 2021
1 parent f7dbce9 commit 9ca604b
Show file tree
Hide file tree
Showing 89 changed files with 546 additions and 552 deletions.
14 changes: 14 additions & 0 deletions lib/config/presets/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,17 @@ export interface ParsedPreset {
presetName: string;
params?: string[];
}

export type PresetFetcher = (
repo: string,
fileName: string,
endpoint: string
) => Promise<Preset>;

export type FetchPresetConfig = {
pkgName: string;
filePreset: string;
presetPath?: string;
endpoint: string;
fetch: PresetFetcher;
};
9 changes: 2 additions & 7 deletions lib/config/presets/util.spec.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
import { getName } from '../../../test/util';
import type { Preset } from './types';
import {
FetchPresetConfig,
PRESET_DEP_NOT_FOUND,
PRESET_NOT_FOUND,
fetchPreset,
} from './util';
import type { FetchPresetConfig, Preset } from './types';
import { PRESET_DEP_NOT_FOUND, PRESET_NOT_FOUND, fetchPreset } from './util';

const config: FetchPresetConfig = {
pkgName: 'some/repo',
Expand Down
16 changes: 1 addition & 15 deletions lib/config/presets/util.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { logger } from '../../logger';
import { ensureTrailingSlash } from '../../util/url';
import type { Preset } from './types';
import type { FetchPresetConfig, Preset } from './types';

export const PRESET_DEP_NOT_FOUND = 'dep not found';
export const PRESET_INVALID = 'invalid preset';
Expand All @@ -10,20 +10,6 @@ export const PRESET_PROHIBITED_SUBPRESET = 'prohibited sub-preset';
export const PRESET_RENOVATE_CONFIG_NOT_FOUND =
'preset renovate-config not found';

export type PresetFetcher = (
repo: string,
fileName: string,
endpoint: string
) => Promise<Preset>;

export type FetchPresetConfig = {
pkgName: string;
filePreset: string;
presetPath?: string;
endpoint: string;
fetch: PresetFetcher;
};

export async function fetchPreset({
pkgName,
filePreset,
Expand Down
7 changes: 1 addition & 6 deletions lib/datasource/github-releases/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import * as packageCache from '../../util/cache/package';
import { GithubHttp } from '../../util/http/github';
import { ensureTrailingSlash } from '../../util/url';
import type { GetReleasesConfig, ReleaseResult } from '../types';
import type { GithubRelease } from './types';

export const id = 'github-releases';
export const customRegistrySupport = true;
Expand All @@ -17,12 +18,6 @@ function getCacheKey(depHost: string, repo: string): string {
return `${depHost}:${repo}:${type}`;
}

type GithubRelease = {
tag_name: string;
published_at: string;
prerelease: boolean;
};

/**
* github.getReleases
*
Expand Down
5 changes: 5 additions & 0 deletions lib/datasource/github-releases/types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export type GithubRelease = {
tag_name: string;
published_at: string;
prerelease: boolean;
};
9 changes: 2 additions & 7 deletions lib/datasource/gitlab-tags/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import URL from 'url';
import * as packageCache from '../../util/cache/package';
import { GitlabHttp } from '../../util/http/gitlab';
import type { GetReleasesConfig, ReleaseResult } from '../types';
import type { GitlabTag } from './types';

const gitlabApi = new GitlabHttp();

Expand All @@ -11,18 +12,12 @@ export const defaultRegistryUrls = ['https://gitlab.com'];
export const registryStrategy = 'first';

const cacheNamespace = 'datasource-gitlab';

function getCacheKey(depHost: string, repo: string): string {
const type = 'tags';
return `${depHost}:${repo}:${type}`;
}

type GitlabTag = {
name: string;
commit?: {
created_at?: string;
};
};

export async function getReleases({
registryUrl: depHost,
lookupName: repo,
Expand Down
6 changes: 6 additions & 0 deletions lib/datasource/gitlab-tags/types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
export type GitlabTag = {
name: string;
commit?: {
created_at?: string;
};
};
10 changes: 5 additions & 5 deletions lib/datasource/maven/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,11 @@ import * as mavenVersioning from '../../versioning/maven';
import { compare } from '../../versioning/maven/compare';
import type { GetReleasesConfig, Release, ReleaseResult } from '../types';
import { MAVEN_REPO } from './common';
import type { MavenDependency } from './types';
import type {
ArtifactInfoResult,
ArtifactsInfo,
MavenDependency,
} from './types';
import {
downloadMavenXml,
getDependencyInfo,
Expand Down Expand Up @@ -80,8 +84,6 @@ async function getVersionsFromMetadata(
return versions;
}

type ArtifactsInfo = Record<string, boolean | null>;

// istanbul ignore next
function isValidArtifactsInfo(
info: ArtifactsInfo | null,
Expand All @@ -93,8 +95,6 @@ function isValidArtifactsInfo(
return versions.every((v) => info[v] !== undefined);
}

type ArtifactInfoResult = [string, boolean | string | null];

async function getArtifactInfo(
version: string,
artifactUrl: url.URL
Expand Down
4 changes: 4 additions & 0 deletions lib/datasource/maven/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,7 @@ export interface MavenXml {
authorization?: boolean;
xml?: XmlDocument;
}

export type ArtifactsInfo = Record<string, boolean | null>;

export type ArtifactInfoResult = [string, boolean | string | null];
17 changes: 1 addition & 16 deletions lib/datasource/pypi/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { Http } from '../../util/http';
import { ensureTrailingSlash } from '../../util/url';
import * as pep440 from '../../versioning/pep440';
import type { GetReleasesConfig, Release, ReleaseResult } from '../types';
import type { PypiJSON, PypiJSONRelease, Releases } from './types';

export const id = 'pypi';
export const customRegistrySupport = true;
Expand All @@ -19,22 +20,6 @@ export const caching = true;
const githubRepoPattern = /^https?:\/\/github\.com\/[^\\/]+\/[^\\/]+$/;
const http = new Http(id);

type PypiJSONRelease = {
requires_python?: string;
upload_time?: string;
yanked?: boolean;
};
type Releases = Record<string, PypiJSONRelease[]>;
type PypiJSON = {
info: {
name: string;
home_page?: string;
project_urls?: Record<string, string>;
};

releases?: Releases;
};

function normalizeName(input: string): string {
return input.toLowerCase().replace(/(-|\.)/g, '_');
}
Expand Down
15 changes: 15 additions & 0 deletions lib/datasource/pypi/types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
export type PypiJSONRelease = {
requires_python?: string;
upload_time?: string;
yanked?: boolean;
};
export type Releases = Record<string, PypiJSONRelease[]>;
export type PypiJSON = {
info: {
name: string;
home_page?: string;
project_urls?: Record<string, string>;
};

releases?: Releases;
};
20 changes: 1 addition & 19 deletions lib/manager/azure-pipelines/extract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,7 @@ import * as datasourceGitTags from '../../datasource/git-tags';
import { logger } from '../../logger';
import { getDep } from '../dockerfile/extract';
import type { PackageDependency, PackageFile } from '../types';

interface Container {
image: string;
}

interface Repository {
type: 'git' | 'github' | 'bitbucket';
name: string;
ref: string;
}

interface Resources {
repositories: Repository[];
containers: Container[];
}

interface AzurePipelines {
resources: Resources;
}
import type { AzurePipelines, Container, Repository } from './types';

export function extractRepository(
repository: Repository
Expand Down
15 changes: 15 additions & 0 deletions lib/manager/azure-pipelines/types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
export interface Container {
image: string;
}
export interface Repository {
type: 'git' | 'github' | 'bitbucket';
name: string;
ref: string;
}
export interface Resources {
repositories: Repository[];
containers: Container[];
}
export interface AzurePipelines {
resources: Resources;
}
7 changes: 1 addition & 6 deletions lib/manager/batect/extract.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { safeLoad } from 'js-yaml';
import * as upath from 'upath';

import { id as gitTagDatasource } from '../../datasource/git-tags';
import { logger } from '../../logger';
import { readLocalFile } from '../../util/fs';
Expand All @@ -13,6 +12,7 @@ import type {
BatectFileInclude,
BatectGitInclude,
BatectInclude,
ExtractionResult,
} from './types';

function loadConfig(content: string): BatectConfig {
Expand Down Expand Up @@ -116,11 +116,6 @@ function extractReferencedConfigFiles(
return paths.map((p) => upath.join(dirName, p));
}

interface ExtractionResult {
deps: PackageDependency[];
referencedConfigFiles: string[];
}

export function extractPackageFile(
content: string,
fileName: string
Expand Down
7 changes: 7 additions & 0 deletions lib/manager/batect/types.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import type { PackageDependency } from '../types';

export interface BatectConfig {
containers?: Record<string, BatectContainer>;
include?: BatectInclude[];
Expand All @@ -19,3 +21,8 @@ export interface BatectGitInclude {
repo: string;
ref: string;
}

export interface ExtractionResult {
deps: PackageDependency[];
referencedConfigFiles: string[];
}
7 changes: 1 addition & 6 deletions lib/manager/bazel/extract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,7 @@ import { logger } from '../../logger';
import { SkipReason } from '../../types';
import * as dockerVersioning from '../../versioning/docker';
import type { PackageDependency, PackageFile } from '../types';

interface UrlParsedResult {
datasource: string;
repo: string;
currentValue: string;
}
import type { UrlParsedResult } from './types';

function parseUrl(urlString: string): UrlParsedResult | null {
// istanbul ignore if
Expand Down
5 changes: 5 additions & 0 deletions lib/manager/bazel/types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export interface UrlParsedResult {
datasource: string;
repo: string;
currentValue: string;
}
13 changes: 1 addition & 12 deletions lib/manager/cocoapods/extract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { logger } from '../../logger';
import { SkipReason } from '../../types';
import { getSiblingFileName, localPathExists } from '../../util/fs';
import type { PackageDependency, PackageFile } from '../types';
import type { ParsedLine } from './types';

const regexMappings = [
/^\s*pod\s+(['"])(?<spec>[^'"/]+)(\/(?<subspec>[^'"]+))?\1/,
Expand All @@ -14,18 +15,6 @@ const regexMappings = [
/^\s*source\s*(['"])(?<source>[^'"]+)\1/,
];

export interface ParsedLine {
depName?: string;
groupName?: string;
spec?: string;
subspec?: string;
currentValue?: string;
git?: string;
tag?: string;
path?: string;
source?: string;
}

export function parseLine(line: string): ParsedLine {
let result: ParsedLine = {};
if (!line) {
Expand Down
11 changes: 11 additions & 0 deletions lib/manager/cocoapods/types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
export interface ParsedLine {
depName?: string;
groupName?: string;
spec?: string;
subspec?: string;
currentValue?: string;
git?: string;
tag?: string;
path?: string;
source?: string;
}
13 changes: 1 addition & 12 deletions lib/manager/composer/artifacts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,20 +25,9 @@ import {
import { getRepoStatus } from '../../util/git';
import * as hostRules from '../../util/host-rules';
import type { UpdateArtifact, UpdateArtifactsResult } from '../types';
import type { AuthJson } from './types';
import { composerVersioningId, getConstraint } from './utils';

interface UserPass {
username: string;
password: string;
}

interface AuthJson {
'github-oauth'?: Record<string, string>;
'gitlab-token'?: Record<string, string>;
'gitlab-domains'?: string[];
'http-basic'?: Record<string, UserPass>;
}

function getAuthJson(): string | null {
const authJson: AuthJson = {};

Expand Down
2 changes: 1 addition & 1 deletion lib/manager/composer/range.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { logger } from '../../logger';
import type { RangeStrategy } from '../../types';
import type { RangeConfig } from '../types';
import { ComposerManagerData } from './types';
import type { ComposerManagerData } from './types';

export function getRangeStrategy(config: RangeConfig): RangeStrategy {
const {
Expand Down
12 changes: 12 additions & 0 deletions lib/manager/composer/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,15 @@ export interface ComposerLock {
export interface ComposerManagerData {
composerJsonType?: string;
}

export interface UserPass {
username: string;
password: string;
}

export interface AuthJson {
'github-oauth'?: Record<string, string>;
'gitlab-token'?: Record<string, string>;
'gitlab-domains'?: string[];
'http-basic'?: Record<string, UserPass>;
}

0 comments on commit 9ca604b

Please sign in to comment.