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