Files
renovate/lib/util/check-token.ts
T
Sergei Zharinov f8c789efb4 feat(github): Log warning when GitHub token is not configured (#16566)
* feat(github): Log warning when GitHub token is not configured

* Check `sourceUrl`

* Add tests

* Fix test

* Fix

* Remove `sourceUrl` check

* Test nullable input

* Fix nulls
2022-08-01 06:16:09 +00:00

52 lines
1.5 KiB
TypeScript

import { PlatformId } from '../constants';
import { logger } from '../logger';
import { GithubReleasesDatasource } from '../modules/datasource/github-releases';
import { GithubTagsDatasource } from '../modules/datasource/github-tags';
import type { PackageFile } from '../modules/manager/types';
import * as memCache from '../util/cache/memory';
import * as hostRules from './host-rules';
export function checkGithubToken(
packageFiles: Record<string, PackageFile[]> | undefined
): void {
const { token } = hostRules.find({
hostType: PlatformId.Github,
url: 'https://api.github.com',
});
if (token) {
logger.trace('GitHub token is found');
return;
}
const githubDeps: string[] = [];
for (const files of Object.values(packageFiles ?? {})) {
for (const file of files ?? []) {
for (const dep of file.deps ?? []) {
if (
dep.datasource === GithubTagsDatasource.id ||
dep.datasource === GithubReleasesDatasource.id
) {
dep.skipReason = 'github-token-required';
if (dep.depName) {
githubDeps.push(dep.depName);
}
}
}
}
}
if (githubDeps.length > 0) {
const warningLogged = memCache.get<boolean | undefined>(
'github-token-required-warning-logged'
);
if (!warningLogged) {
logger.warn(
{ githubDeps },
`GitHub token is required for some dependencies`
);
memCache.set('github-token-required-warning-logged', true);
}
}
}