Skip to content

Commit

Permalink
fix: Disable token warning on githubTokenWarn=true (#17548)
Browse files Browse the repository at this point in the history
  • Loading branch information
zharinov committed Aug 31, 2022
1 parent 6fa3aad commit c9d87d8
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 3 deletions.
16 changes: 16 additions & 0 deletions lib/util/check-token.spec.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -11,6 +12,7 @@ describe('util/check-token', () => {
beforeEach(() => {
jest.resetAllMocks();
memCache.reset();
GlobalConfig.set({ githubTokenWarn: true });
});

it('does nothing if data is empty', () => {
Expand All @@ -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({
Expand Down
11 changes: 9 additions & 2 deletions lib/util/check-token.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { GlobalConfig } from '../config/global';
import { PlatformId } from '../constants';
import { logger } from '../logger';
import { GithubReleasesDatasource } from '../modules/datasource/github-releases';
Expand All @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down

0 comments on commit c9d87d8

Please sign in to comment.