mirror of
https://github.com/renovatebot/renovate.git
synced 2026-10-27 07:50:47 +00:00
1e6ffa8171
Every datasource that caches its releases hand-wrote the same
`withCache({ namespace: `datasource-${id}`, ... }, () => this._getReleases(config))`
wrapper, repeating the namespace literal and using underscore-prefixed
method names that `docs/development/best-practices.md` discourages.
Add `Datasource.cacheNamespace` (derived from the datasource id) and a
protected `Datasource.cached()` helper that defaults `namespace` to it,
exporting `CachedOptions` from `with-cache.ts`. Migrate 29 datasources
onto the helper, dropping their namespace literals, the static
`cacheNamespace` field in `github-digest`, and renaming the wrapped
`_getX` methods to `fetchX`.
Behaviour change: `golang-version` used the constant cache key `'all'`
while declaring `customRegistrySupport = true`, so a custom registryUrl
shared the cache entry with the default one. The key is now
`${config.registryUrl}`, which invalidates existing entries once.
86 lines
2.3 KiB
TypeScript
86 lines
2.3 KiB
TypeScript
import { regEx } from '../../../util/regex.ts';
|
|
import { asTimestamp } from '../../../util/timestamp.ts';
|
|
import * as semver from '../../versioning/semver/index.ts';
|
|
import { Datasource } from '../datasource.ts';
|
|
import type { GetReleasesConfig, ReleaseResult } from '../types.ts';
|
|
import { Applications } from './schema.ts';
|
|
|
|
export class NextcloudDatasource extends Datasource {
|
|
static readonly id = 'nextcloud';
|
|
|
|
private static readonly defaultTranslationLanguage = 'en';
|
|
|
|
private static readonly sourceUrlRegex = regEx(
|
|
/(?<prefix>.*github.com\/nextcloud)(?<suffix>\/.*)/,
|
|
);
|
|
|
|
override readonly defaultVersioning = semver.id;
|
|
|
|
constructor() {
|
|
super(NextcloudDatasource.id);
|
|
}
|
|
|
|
private async fetchReleases({
|
|
packageName,
|
|
registryUrl,
|
|
}: GetReleasesConfig): Promise<ReleaseResult | null> {
|
|
if (!registryUrl) {
|
|
return null;
|
|
}
|
|
|
|
const response = await this.http.getJson(registryUrl, Applications);
|
|
|
|
const application = response.body.find((a) => a.id === packageName);
|
|
|
|
if (!application) {
|
|
return null;
|
|
}
|
|
|
|
const sourceUrlMatches = NextcloudDatasource.sourceUrlRegex.exec(
|
|
application.website,
|
|
);
|
|
|
|
const result: ReleaseResult = {
|
|
releases: [],
|
|
homepage: application.website,
|
|
registryUrl,
|
|
changelogUrl: sourceUrlMatches?.groups
|
|
? `${sourceUrlMatches.groups.prefix}-releases${sourceUrlMatches.groups.suffix}`
|
|
: application.website,
|
|
};
|
|
|
|
if (sourceUrlMatches !== null) {
|
|
result.sourceUrl = application.website;
|
|
}
|
|
|
|
for (const release of application.releases) {
|
|
const translation =
|
|
release.translations[NextcloudDatasource.defaultTranslationLanguage];
|
|
|
|
const changelogContent = translation?.changelog ?? null;
|
|
|
|
result.releases.push({
|
|
version: release.version,
|
|
releaseTimestamp: asTimestamp(release.created),
|
|
changelogContent:
|
|
changelogContent !== null && changelogContent.length > 0
|
|
? changelogContent
|
|
: undefined,
|
|
isStable: !release.isNightly,
|
|
});
|
|
}
|
|
|
|
return result;
|
|
}
|
|
|
|
getReleases(config: GetReleasesConfig): Promise<ReleaseResult | null> {
|
|
return this.cached(
|
|
{
|
|
key: `${config.registryUrl}:${config.packageName}`,
|
|
fallback: true,
|
|
},
|
|
() => this.fetchReleases(config),
|
|
);
|
|
}
|
|
}
|