From c9d87d8564f5567f960b31d79587e899e3624cfa Mon Sep 17 00:00:00 2001 From: Sergei Zharinov <zharinov@users.noreply.github.com> Date: Wed, 31 Aug 2022 17:57:42 +0300 Subject: [PATCH] fix: Disable token warning on githubTokenWarn=true (#17548) --- lib/util/check-token.spec.ts | 16 ++++++++++++++++ lib/util/check-token.ts | 11 +++++++++-- .../update/pr/changelog/source-github.ts | 2 +- 3 files changed, 26 insertions(+), 3 deletions(-) diff --git a/lib/util/check-token.spec.ts b/lib/util/check-token.spec.ts index 7c73e802a2..c1d8b9077f 100644 --- a/lib/util/check-token.spec.ts +++ b/lib/util/check-token.spec.ts @@ -1,4 +1,5 @@ import { hostRules, logger } from '../../test/util'; +import { GlobalConfig } from '../config/global'; import { GithubReleasesDatasource } from '../modules/datasource/github-releases'; import { GithubTagsDatasource } from '../modules/datasource/github-tags'; import type { PackageFile } from '../modules/manager/types'; @@ -11,6 +12,7 @@ describe('util/check-token', () => { beforeEach(() => { jest.resetAllMocks(); memCache.reset(); + GlobalConfig.set({ githubTokenWarn: true }); }); it('does nothing if data is empty', () => { @@ -31,6 +33,20 @@ describe('util/check-token', () => { expect(logger.logger.warn).not.toHaveBeenCalled(); }); + it('returns early if token warnings are disabled', () => { + GlobalConfig.set({ githubTokenWarn: false }); + hostRules.find.mockReturnValueOnce({}); + checkGithubToken({}); + expect(hostRules.find).toHaveBeenCalledWith({ + hostType: 'github', + url: 'https://api.github.com', + }); + expect(logger.logger.trace).toHaveBeenCalledWith( + 'GitHub token warning is disabled' + ); + expect(logger.logger.warn).not.toHaveBeenCalled(); + }); + it('does not warn if there is dependencies with GitHub sourceUrl', () => { hostRules.find.mockReturnValueOnce({}); checkGithubToken({ diff --git a/lib/util/check-token.ts b/lib/util/check-token.ts index 752ecd5939..9fad02f977 100644 --- a/lib/util/check-token.ts +++ b/lib/util/check-token.ts @@ -1,3 +1,4 @@ +import { GlobalConfig } from '../config/global'; import { PlatformId } from '../constants'; import { logger } from '../logger'; import { GithubReleasesDatasource } from '../modules/datasource/github-releases'; @@ -19,13 +20,19 @@ export function checkGithubToken( return; } + if (!GlobalConfig.get('githubTokenWarn')) { + logger.trace('GitHub token warning is disabled'); + 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 && + (dep.datasource === GithubTagsDatasource.id || + dep.datasource === GithubReleasesDatasource.id) ) { dep.skipReason = 'github-token-required'; if (dep.depName) { diff --git a/lib/workers/repository/update/pr/changelog/source-github.ts b/lib/workers/repository/update/pr/changelog/source-github.ts index d8dabe224e..03fcd6c013 100644 --- a/lib/workers/repository/update/pr/changelog/source-github.ts +++ b/lib/workers/repository/update/pr/changelog/source-github.ts @@ -59,7 +59,7 @@ export async function getChangeLogJSON( // istanbul ignore if if (!token) { if (host!.endsWith('.github.com') || host === 'github.com') { - if (!GlobalConfig.get().githubTokenWarn) { + if (!GlobalConfig.get('githubTokenWarn')) { logger.debug( { manager, depName, sourceUrl }, 'GitHub token warning has been suppressed. Skipping release notes retrieval' -- GitLab