mirror of
https://github.com/renovatebot/renovate.git
synced 2025-01-12 23:16:26 +00:00
refactor(datasource): Fix lint warnings (#7115)
This commit is contained in:
parent
28d16d17bc
commit
0ae8cc2e89
11 changed files with 55 additions and 35 deletions
|
@ -28,7 +28,7 @@ export interface GetPkgReleasesConfig extends ReleasesConfigBase {
|
||||||
}
|
}
|
||||||
|
|
||||||
export function isGetPkgReleasesConfig(
|
export function isGetPkgReleasesConfig(
|
||||||
input: any
|
input: unknown
|
||||||
): input is GetPkgReleasesConfig {
|
): input is GetPkgReleasesConfig {
|
||||||
return (
|
return (
|
||||||
(input as GetPkgReleasesConfig).datasource !== undefined &&
|
(input as GetPkgReleasesConfig).datasource !== undefined &&
|
||||||
|
@ -75,7 +75,7 @@ export interface DatasourceApi {
|
||||||
getReleases(config: GetReleasesConfig): Promise<ReleaseResult | null>;
|
getReleases(config: GetReleasesConfig): Promise<ReleaseResult | null>;
|
||||||
defaultRegistryUrls?: string[];
|
defaultRegistryUrls?: string[];
|
||||||
appendRegistryUrls?: string[];
|
appendRegistryUrls?: string[];
|
||||||
defaultConfig?: object;
|
defaultConfig?: Record<string, unknown>;
|
||||||
registryStrategy?: 'first' | 'hunt' | 'merge';
|
registryStrategy?: 'first' | 'hunt' | 'merge';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -230,7 +230,7 @@ describe(getName(__filename), () => {
|
||||||
AWSMock.mock(
|
AWSMock.mock(
|
||||||
'ECR',
|
'ECR',
|
||||||
'getAuthorizationToken',
|
'getAuthorizationToken',
|
||||||
(params: {}, callback: Function) => {
|
(params: unknown, callback: (...unknown) => void) => {
|
||||||
callback(null, {
|
callback(null, {
|
||||||
authorizationData: [{ authorizationToken: 'abcdef' }],
|
authorizationData: [{ authorizationToken: 'abcdef' }],
|
||||||
});
|
});
|
||||||
|
@ -262,7 +262,7 @@ describe(getName(__filename), () => {
|
||||||
AWSMock.mock(
|
AWSMock.mock(
|
||||||
'ECR',
|
'ECR',
|
||||||
'getAuthorizationToken',
|
'getAuthorizationToken',
|
||||||
(params: {}, callback: Function) => {
|
(params: unknown, callback: (...unknown) => void) => {
|
||||||
callback(null, {});
|
callback(null, {});
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
@ -291,7 +291,7 @@ describe(getName(__filename), () => {
|
||||||
AWSMock.mock(
|
AWSMock.mock(
|
||||||
'ECR',
|
'ECR',
|
||||||
'getAuthorizationToken',
|
'getAuthorizationToken',
|
||||||
(params: {}, callback: Function) => {
|
(params: unknown, callback: (...unknown) => void) => {
|
||||||
callback(Error('some error'), null);
|
callback(Error('some error'), null);
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
|
@ -175,7 +175,7 @@ async function getAuthHeaders(
|
||||||
}
|
}
|
||||||
|
|
||||||
// prettier-ignore
|
// prettier-ignore
|
||||||
const authUrl = `${authenticateHeader.parms.realm}?service=${authenticateHeader.parms.service}&scope=repository:${repository}:pull`;
|
const authUrl = `${String(authenticateHeader.parms.realm)}?service=${String(authenticateHeader.parms.service)}&scope=repository:${repository}:pull`;
|
||||||
logger.trace(
|
logger.trace(
|
||||||
`Obtaining docker registry token for ${repository} using url ${authUrl}`
|
`Obtaining docker registry token for ${repository} using url ${authUrl}`
|
||||||
);
|
);
|
||||||
|
@ -497,7 +497,7 @@ async function getLabels(
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
let labels: Record<string, string> = {};
|
let labels: Record<string, string> = {};
|
||||||
const configDigest = manifest.config.digest;
|
const configDigest: string = manifest.config.digest;
|
||||||
const headers = await getAuthHeaders(registry, repository);
|
const headers = await getAuthHeaders(registry, repository);
|
||||||
// istanbul ignore if: Should never be happen
|
// istanbul ignore if: Should never be happen
|
||||||
if (!headers) {
|
if (!headers) {
|
||||||
|
|
|
@ -71,12 +71,9 @@ export async function getReleases({
|
||||||
};
|
};
|
||||||
|
|
||||||
result.dependencyUrl = galaxyProjectUrl;
|
result.dependencyUrl = galaxyProjectUrl;
|
||||||
if (resultObject.github_user && resultObject.github_repo) {
|
const { github_user: user = null, github_repo: repo = null } = resultObject;
|
||||||
result.sourceUrl =
|
if (typeof user === 'string' && typeof repo === 'string') {
|
||||||
'https://github.com/' +
|
result.sourceUrl = `https://github.com/${user}/${repo}`;
|
||||||
resultObject.github_user +
|
|
||||||
'/' +
|
|
||||||
resultObject.github_repo;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
result.releases = versions.map(
|
result.releases = versions.map(
|
||||||
|
|
|
@ -214,11 +214,10 @@ async function fetchReleases(
|
||||||
function getRawReleases(
|
function getRawReleases(
|
||||||
config: GetReleasesInternalConfig
|
config: GetReleasesInternalConfig
|
||||||
): Promise<ReleaseResult | null> {
|
): Promise<ReleaseResult | null> {
|
||||||
const cacheKey =
|
const { datasource, lookupName, registryUrls } = config;
|
||||||
cacheNamespace +
|
const cacheKey = `${cacheNamespace}${datasource}${lookupName}${String(
|
||||||
config.datasource +
|
registryUrls
|
||||||
config.lookupName +
|
)}`;
|
||||||
config.registryUrls;
|
|
||||||
// By returning a Promise and reusing it, we should only fetch each package at most once
|
// By returning a Promise and reusing it, we should only fetch each package at most once
|
||||||
const cachedResult = memCache.get(cacheKey);
|
const cachedResult = memCache.get(cacheKey);
|
||||||
// istanbul ignore if
|
// istanbul ignore if
|
||||||
|
@ -291,7 +290,9 @@ export function getDigest(
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
export function getDefaultConfig(datasource: string): Promise<object> {
|
export function getDefaultConfig(
|
||||||
|
datasource: string
|
||||||
|
): Promise<Record<string, unknown>> {
|
||||||
const loadedDatasource = load(datasource);
|
const loadedDatasource = load(datasource);
|
||||||
return Promise.resolve(loadedDatasource?.defaultConfig || {});
|
return Promise.resolve(loadedDatasource?.defaultConfig || Object.create({}));
|
||||||
}
|
}
|
||||||
|
|
|
@ -45,6 +45,29 @@ export interface NpmDependency extends ReleaseResult {
|
||||||
sourceDirectory?: string;
|
sourceDirectory?: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
interface NpmResponse {
|
||||||
|
_id: string;
|
||||||
|
name?: string;
|
||||||
|
versions?: Record<
|
||||||
|
string,
|
||||||
|
{
|
||||||
|
repository?: {
|
||||||
|
url: string;
|
||||||
|
directory: string;
|
||||||
|
};
|
||||||
|
homepage?: string;
|
||||||
|
deprecated?: boolean;
|
||||||
|
gitHead?: string;
|
||||||
|
}
|
||||||
|
>;
|
||||||
|
repository?: {
|
||||||
|
url?: string;
|
||||||
|
directory?: string;
|
||||||
|
};
|
||||||
|
homepage?: string;
|
||||||
|
time?: Record<string, string>;
|
||||||
|
}
|
||||||
|
|
||||||
export async function getDependency(
|
export async function getDependency(
|
||||||
packageName: string,
|
packageName: string,
|
||||||
retries = 3
|
retries = 3
|
||||||
|
@ -135,8 +158,7 @@ export async function getDependency(
|
||||||
headers,
|
headers,
|
||||||
useCache,
|
useCache,
|
||||||
};
|
};
|
||||||
// TODO: fix type
|
const raw = await http.getJson<NpmResponse>(pkgUrl, opts);
|
||||||
const raw = await http.getJson<any>(pkgUrl, opts);
|
|
||||||
if (retries < 3) {
|
if (retries < 3) {
|
||||||
logger.debug({ pkgUrl, retries }, 'Recovered from npm error');
|
logger.debug({ pkgUrl, retries }, 'Recovered from npm error');
|
||||||
}
|
}
|
||||||
|
|
|
@ -39,7 +39,7 @@ function sanitize(key: string, val: string): void {
|
||||||
add(val);
|
add(val);
|
||||||
const password = Buffer.from(val, 'base64').toString();
|
const password = Buffer.from(val, 'base64').toString();
|
||||||
add(password);
|
add(password);
|
||||||
const username = npmrc[key.replace(':_password', ':username')];
|
const username: string = npmrc[key.replace(':_password', ':username')];
|
||||||
add(Buffer.from(`${username}:${password}`).toString('base64'));
|
add(Buffer.from(`${username}:${password}`).toString('base64'));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -133,7 +133,7 @@ export async function getReleases(
|
||||||
).flat();
|
).flat();
|
||||||
|
|
||||||
let homepage = null;
|
let homepage = null;
|
||||||
let latestStable = null;
|
let latestStable: string = null;
|
||||||
const releases = catalogEntries.map(
|
const releases = catalogEntries.map(
|
||||||
({ version, published: releaseTimestamp, projectUrl }) => {
|
({ version, published: releaseTimestamp, projectUrl }) => {
|
||||||
const release: Release = { version };
|
const release: Release = { version };
|
||||||
|
|
|
@ -14,7 +14,7 @@ export const defaultRegistryUrls = [
|
||||||
];
|
];
|
||||||
export const registryStrategy = 'merge';
|
export const registryStrategy = 'merge';
|
||||||
|
|
||||||
const github_repo_pattern = /^https?:\/\/github\.com\/[^\\/]+\/[^\\/]+$/;
|
const githubRepoPattern = /^https?:\/\/github\.com\/[^\\/]+\/[^\\/]+$/;
|
||||||
const http = new Http(id);
|
const http = new Http(id);
|
||||||
|
|
||||||
type PypiJSONRelease = {
|
type PypiJSONRelease = {
|
||||||
|
@ -82,7 +82,7 @@ async function getDependency(
|
||||||
|
|
||||||
if (dep.info?.home_page) {
|
if (dep.info?.home_page) {
|
||||||
dependency.homepage = dep.info.home_page;
|
dependency.homepage = dep.info.home_page;
|
||||||
if (github_repo_pattern.exec(dep.info.home_page)) {
|
if (githubRepoPattern.exec(dep.info.home_page)) {
|
||||||
dependency.sourceUrl = dep.info.home_page.replace('http://', 'https://');
|
dependency.sourceUrl = dep.info.home_page.replace('http://', 'https://');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -96,7 +96,7 @@ async function getDependency(
|
||||||
(lower.startsWith('repo') ||
|
(lower.startsWith('repo') ||
|
||||||
lower === 'code' ||
|
lower === 'code' ||
|
||||||
lower === 'source' ||
|
lower === 'source' ||
|
||||||
github_repo_pattern.exec(projectUrl))
|
githubRepoPattern.exec(projectUrl))
|
||||||
) {
|
) {
|
||||||
dependency.sourceUrl = projectUrl;
|
dependency.sourceUrl = projectUrl;
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,13 +8,13 @@ import { RepologyPackage, id as datasource } from '.';
|
||||||
|
|
||||||
const repologyApiHost = 'https://repology.org/';
|
const repologyApiHost = 'https://repology.org/';
|
||||||
|
|
||||||
type mockResponse = { status: number; body?: string };
|
type ResponseMock = { status: number; body?: string };
|
||||||
|
|
||||||
const mockProjectBy = (
|
const mockProjectBy = (
|
||||||
repo: string,
|
repo: string,
|
||||||
name: string,
|
name: string,
|
||||||
binary: mockResponse,
|
binary: ResponseMock,
|
||||||
source: mockResponse
|
source: ResponseMock
|
||||||
) => {
|
) => {
|
||||||
const endpoint = '/tools/project-by';
|
const endpoint = '/tools/project-by';
|
||||||
const defaultParams = {
|
const defaultParams = {
|
||||||
|
|
|
@ -94,15 +94,15 @@ function isDataStale(): boolean {
|
||||||
return minutesElapsed >= 5;
|
return minutesElapsed >= 5;
|
||||||
}
|
}
|
||||||
|
|
||||||
let _updateRubyGemsVersions: Promise<void> | undefined;
|
let updateRubyGemsVersionsPromise: Promise<void> | undefined;
|
||||||
|
|
||||||
async function syncVersions(): Promise<void> {
|
async function syncVersions(): Promise<void> {
|
||||||
if (isDataStale()) {
|
if (isDataStale()) {
|
||||||
_updateRubyGemsVersions =
|
updateRubyGemsVersionsPromise =
|
||||||
// eslint-disable-next-line @typescript-eslint/no-misused-promises
|
// eslint-disable-next-line @typescript-eslint/no-misused-promises
|
||||||
_updateRubyGemsVersions || updateRubyGemsVersions();
|
updateRubyGemsVersionsPromise || updateRubyGemsVersions();
|
||||||
await _updateRubyGemsVersions;
|
await updateRubyGemsVersionsPromise;
|
||||||
_updateRubyGemsVersions = null;
|
updateRubyGemsVersionsPromise = null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue