mirror of
https://github.com/renovatebot/renovate.git
synced 2026-10-30 17:27:26 +00:00
a473e73b3e
Adds a custom oxlint rule renovate/v8-ignore-no-count that flags the count form '/* v8 ignore next <N> */'. The count is not honored by vitest's ast-v8-to-istanbul hint parser, which captures only the keyword (if/else/next/file); 'next' always exempts exactly the next AST node. Trailing counts therefore suggest a line range that is never applied and mislead readers. The rule is autofixable (drops the count, preserving actual behavior) and has been applied to all existing occurrences.
103 lines
2.5 KiB
TypeScript
103 lines
2.5 KiB
TypeScript
import { logger } from '../../../logger/index.ts';
|
|
import { withCache } from '../../../util/cache/package/with-cache.ts';
|
|
import { regEx } from '../../../util/regex.ts';
|
|
import type {
|
|
DigestConfig,
|
|
GetReleasesConfig,
|
|
ReleaseResult,
|
|
} from '../types.ts';
|
|
import { GitDatasource } from './base.ts';
|
|
import type { RawRefs } from './types.ts';
|
|
|
|
export class GitRefsDatasource extends GitDatasource {
|
|
static override readonly id = 'git-refs';
|
|
|
|
constructor() {
|
|
super(GitRefsDatasource.id);
|
|
}
|
|
|
|
override readonly customRegistrySupport = false;
|
|
|
|
override readonly sourceUrlSupport = 'package';
|
|
override readonly sourceUrlNote =
|
|
'The source URL is determined by using the `packageName` and `registryUrl`.';
|
|
|
|
private async _getReleases({
|
|
packageName,
|
|
}: GetReleasesConfig): Promise<ReleaseResult | null> {
|
|
let rawRefs: RawRefs[] | null = null;
|
|
|
|
try {
|
|
rawRefs = await this.getRawRefs({ packageName });
|
|
} catch (err) /* istanbul ignore next */ {
|
|
logger.debug({ err }, 'Error getting git-refs');
|
|
}
|
|
|
|
if (!rawRefs) {
|
|
return null;
|
|
}
|
|
|
|
const refs = rawRefs
|
|
.filter((ref) => ref.type === 'tags' || ref.type === 'heads')
|
|
.map((ref) => ref.value);
|
|
|
|
const uniqueRefs = [...new Set(refs)];
|
|
|
|
const sourceUrl = packageName
|
|
.replace(regEx(/\.git$/), '')
|
|
.replace(regEx(/\/$/), '');
|
|
|
|
const result: ReleaseResult = {
|
|
sourceUrl,
|
|
releases: uniqueRefs.map((ref) => ({
|
|
version: ref,
|
|
gitRef: ref,
|
|
newDigest: rawRefs.find((rawRef) => rawRef.value === ref)?.hash,
|
|
})),
|
|
};
|
|
|
|
return result;
|
|
}
|
|
|
|
override getReleases(
|
|
config: GetReleasesConfig,
|
|
): Promise<ReleaseResult | null> {
|
|
return withCache(
|
|
{
|
|
namespace: `datasource-${GitRefsDatasource.id}`,
|
|
key: config.packageName,
|
|
fallback: true,
|
|
},
|
|
() => this._getReleases(config),
|
|
);
|
|
}
|
|
|
|
override async getDigest(
|
|
{ packageName }: DigestConfig,
|
|
newValue?: string,
|
|
): Promise<string | null> {
|
|
const rawRefs: RawRefs[] | null = await this.getRawRefs({ packageName });
|
|
|
|
/* v8 ignore next -- TODO: add test */
|
|
if (!rawRefs) {
|
|
return null;
|
|
}
|
|
|
|
let ref: RawRefs | undefined;
|
|
if (newValue) {
|
|
ref = rawRefs.find(
|
|
(rawRef) =>
|
|
['heads', 'tags'].includes(rawRef.type) && rawRef.value === newValue,
|
|
);
|
|
} else {
|
|
ref = rawRefs.find(
|
|
(rawRef) => rawRef.type === '' && rawRef.value === 'HEAD',
|
|
);
|
|
}
|
|
if (ref) {
|
|
return ref.hash;
|
|
}
|
|
return null;
|
|
}
|
|
}
|