From f5a588eb5a25f3de31d66dbfeccca1a55cdfc5ef Mon Sep 17 00:00:00 2001 From: Rhys Arkins Date: Wed, 17 Jun 2020 10:07:22 +0200 Subject: [PATCH] fix: Revert "fix(cache): distinguish between null and undefined (#6509)" This reverts commit 0345b40a181134236d65ccebd450efd46700deb9. --- lib/datasource/cache.ts | 2 +- lib/datasource/crate/index.ts | 2 +- lib/datasource/docker/index.ts | 6 +++--- lib/datasource/galaxy/index.ts | 2 +- lib/datasource/git-refs/index.ts | 2 +- lib/datasource/git-submodules/index.ts | 2 +- lib/datasource/github-releases/index.ts | 2 +- lib/datasource/github-tags/index.ts | 11 +++++++---- lib/datasource/gitlab-tags/index.ts | 2 +- lib/datasource/helm/index.ts | 2 +- lib/datasource/maven/index.ts | 2 +- lib/datasource/npm/get.ts | 2 +- lib/datasource/nuget/v3.ts | 2 +- lib/datasource/orb/index.ts | 2 +- lib/datasource/packagist/index.ts | 2 +- lib/datasource/pod/index.ts | 2 +- lib/datasource/repology/index.ts | 2 +- lib/datasource/ruby-version/index.ts | 2 +- lib/datasource/terraform-module/index.ts | 2 +- lib/datasource/terraform-provider/index.ts | 2 +- lib/manager/bazel/update.ts | 2 +- lib/util/cache/global/file.spec.ts | 8 +++----- lib/util/cache/global/file.ts | 2 +- lib/workers/pr/changelog/release-notes.ts | 4 ++-- lib/workers/pr/changelog/source-github.ts | 2 +- lib/workers/pr/changelog/source-gitlab.ts | 2 +- lib/workers/repository/stats.ts | 2 +- 27 files changed, 38 insertions(+), 37 deletions(-) diff --git a/lib/datasource/cache.ts b/lib/datasource/cache.ts index f0ad5eaa3198e2..ecd74cbe79e176 100644 --- a/lib/datasource/cache.ts +++ b/lib/datasource/cache.ts @@ -60,7 +60,7 @@ export async function cacheAble({ const cacheKey = JSON.stringify(lookup); const cachedResult = await globalCache.get(cacheNamespace, cacheKey); // istanbul ignore if - if (cachedResult !== undefined) { + if (cachedResult) { logger.trace({ id, lookup }, 'datasource cachedResult'); return cachedResult; } diff --git a/lib/datasource/crate/index.ts b/lib/datasource/crate/index.ts index e8e64eba5eef4d..fe948c1ab79079 100644 --- a/lib/datasource/crate/index.ts +++ b/lib/datasource/crate/index.ts @@ -22,7 +22,7 @@ export async function getReleases({ cacheKey ); // istanbul ignore if - if (cachedResult !== undefined) { + if (cachedResult) { return cachedResult; } diff --git a/lib/datasource/docker/index.ts b/lib/datasource/docker/index.ts index 0317e4927b2e41..9ab3c01480fad5 100644 --- a/lib/datasource/docker/index.ts +++ b/lib/datasource/docker/index.ts @@ -341,7 +341,7 @@ export async function getDigest( const cacheKey = `${registry}:${repository}:${newTag}`; const cachedResult = await globalCache.get(cacheNamespace, cacheKey); // istanbul ignore if - if (cachedResult !== undefined) { + if (cachedResult) { return cachedResult; } const manifestResponse = await getManifestResponse( @@ -386,7 +386,7 @@ async function getTags( cacheKey ); // istanbul ignore if - if (cachedResult !== undefined) { + if (cachedResult) { return cachedResult; } // AWS ECR limits the maximum number of results to 1000 @@ -486,7 +486,7 @@ async function getLabels( cacheKey ); // istanbul ignore if - if (cachedResult !== undefined) { + if (cachedResult) { return cachedResult; } try { diff --git a/lib/datasource/galaxy/index.ts b/lib/datasource/galaxy/index.ts index b49eca902d18a5..ce6b9e89643596 100644 --- a/lib/datasource/galaxy/index.ts +++ b/lib/datasource/galaxy/index.ts @@ -22,7 +22,7 @@ export async function getReleases({ cacheKey ); // istanbul ignore if - if (cachedResult !== undefined) { + if (cachedResult) { return cachedResult; } diff --git a/lib/datasource/git-refs/index.ts b/lib/datasource/git-refs/index.ts index 4b608589da1be9..afd75aed8c0bd0 100644 --- a/lib/datasource/git-refs/index.ts +++ b/lib/datasource/git-refs/index.ts @@ -29,7 +29,7 @@ export async function getRawRefs({ lookupName ); /* istanbul ignore next line */ - if (cachedResult !== undefined) { + if (cachedResult) { return cachedResult; } diff --git a/lib/datasource/git-submodules/index.ts b/lib/datasource/git-submodules/index.ts index bf0dbfda00c943..b00fe9afa52dd4 100644 --- a/lib/datasource/git-submodules/index.ts +++ b/lib/datasource/git-submodules/index.ts @@ -18,7 +18,7 @@ export async function getReleases({ cacheKey ); // istanbul ignore if - if (cachedResult !== undefined) { + if (cachedResult) { return cachedResult; } diff --git a/lib/datasource/github-releases/index.ts b/lib/datasource/github-releases/index.ts index 621a5b0f446d56..8b4c2c89dcd503 100644 --- a/lib/datasource/github-releases/index.ts +++ b/lib/datasource/github-releases/index.ts @@ -33,7 +33,7 @@ export async function getReleases({ repo ); // istanbul ignore if - if (cachedResult !== undefined) { + if (cachedResult) { return cachedResult; } try { diff --git a/lib/datasource/github-tags/index.ts b/lib/datasource/github-tags/index.ts index 6f5ce1689fb140..fea2bae705bd85 100644 --- a/lib/datasource/github-tags/index.ts +++ b/lib/datasource/github-tags/index.ts @@ -29,7 +29,7 @@ async function getTagCommit( getCacheKey(githubRepo, `tag-${tag}`) ); // istanbul ignore if - if (cachedResult !== undefined) { + if (cachedResult) { return cachedResult; } let digest: string; @@ -81,7 +81,7 @@ export async function getDigest( getCacheKey(githubRepo, 'commit') ); // istanbul ignore if - if (cachedResult !== undefined) { + if (cachedResult) { return cachedResult; } let digest: string; @@ -95,6 +95,9 @@ export async function getDigest( 'Error getting latest commit from GitHub repo' ); } + if (!digest) { + return null; + } const cacheMinutes = 10; await globalCache.set( cacheNamespace, @@ -102,7 +105,7 @@ export async function getDigest( digest, cacheMinutes ); - return digest || null; + return digest; } /** @@ -124,7 +127,7 @@ export async function getReleases({ getCacheKey(repo, 'tags') ); // istanbul ignore if - if (cachedResult !== undefined) { + if (cachedResult) { return cachedResult; } try { diff --git a/lib/datasource/gitlab-tags/index.ts b/lib/datasource/gitlab-tags/index.ts index 93f5169b642307..15411d83cf8c0c 100644 --- a/lib/datasource/gitlab-tags/index.ts +++ b/lib/datasource/gitlab-tags/index.ts @@ -35,7 +35,7 @@ export async function getReleases({ getCacheKey(depHost, repo) ); // istanbul ignore if - if (cachedResult !== undefined) { + if (cachedResult) { return cachedResult; } diff --git a/lib/datasource/helm/index.ts b/lib/datasource/helm/index.ts index 06854b78883348..d646d07d2178fd 100644 --- a/lib/datasource/helm/index.ts +++ b/lib/datasource/helm/index.ts @@ -21,7 +21,7 @@ export async function getRepositoryData( const cacheKey = repository; const cachedIndex = await globalCache.get(cacheNamespace, cacheKey); // istanbul ignore if - if (cachedIndex !== undefined) { + if (cachedIndex) { return cachedIndex; } let res: any; diff --git a/lib/datasource/maven/index.ts b/lib/datasource/maven/index.ts index d381e81472120e..99efb384dde0ef 100644 --- a/lib/datasource/maven/index.ts +++ b/lib/datasource/maven/index.ts @@ -162,7 +162,7 @@ async function getVersionsFromMetadata( cacheKey ); /* istanbul ignore if */ - if (cachedVersions !== undefined) { + if (cachedVersions) { return cachedVersions; } diff --git a/lib/datasource/npm/get.ts b/lib/datasource/npm/get.ts index 9caed7b5d1a82c..d2f0e2ab362cc6 100644 --- a/lib/datasource/npm/get.ts +++ b/lib/datasource/npm/get.ts @@ -75,7 +75,7 @@ export async function getDependency( pkgUrl ); // istanbul ignore if - if (cachedResult !== undefined) { + if (cachedResult) { return cachedResult; } const headers: OutgoingHttpHeaders = {}; diff --git a/lib/datasource/nuget/v3.ts b/lib/datasource/nuget/v3.ts index cec3735a4fce7c..507af6cbea3542 100644 --- a/lib/datasource/nuget/v3.ts +++ b/lib/datasource/nuget/v3.ts @@ -24,7 +24,7 @@ export async function getQueryUrl(url: string): Promise { const cachedResult = await globalCache.get(cacheNamespace, cacheKey); // istanbul ignore if - if (cachedResult !== undefined) { + if (cachedResult) { return cachedResult; } diff --git a/lib/datasource/orb/index.ts b/lib/datasource/orb/index.ts index cb5d4aefdf197d..0d54db74e9217f 100644 --- a/lib/datasource/orb/index.ts +++ b/lib/datasource/orb/index.ts @@ -31,7 +31,7 @@ export async function getReleases({ cacheKey ); // istanbul ignore if - if (cachedResult !== undefined) { + if (cachedResult) { return cachedResult; } const url = 'https://circleci.com/graphql-unstable'; diff --git a/lib/datasource/packagist/index.ts b/lib/datasource/packagist/index.ts index 365990dabdc527..73d8d3e238ff7b 100644 --- a/lib/datasource/packagist/index.ts +++ b/lib/datasource/packagist/index.ts @@ -236,7 +236,7 @@ async function packagistOrgLookup(name: string): Promise { name ); // istanbul ignore if - if (cachedResult !== undefined) { + if (cachedResult) { return cachedResult; } let dep: ReleaseResult = null; diff --git a/lib/datasource/pod/index.ts b/lib/datasource/pod/index.ts index d4dfe7ede82fcf..ce957dad14780c 100644 --- a/lib/datasource/pod/index.ts +++ b/lib/datasource/pod/index.ts @@ -158,7 +158,7 @@ export async function getReleases({ podName ); /* istanbul ignore next line */ - if (cachedResult !== undefined) { + if (cachedResult) { logger.debug(`CocoaPods: Return cached result for ${podName}`); return cachedResult; } diff --git a/lib/datasource/repology/index.ts b/lib/datasource/repology/index.ts index d0c144354df5d5..e45c10f021ed23 100644 --- a/lib/datasource/repology/index.ts +++ b/lib/datasource/repology/index.ts @@ -89,7 +89,7 @@ async function getCachedPackage( cacheKey ); // istanbul ignore if - if (cachedResult !== undefined) { + if (cachedResult) { return cachedResult; } diff --git a/lib/datasource/ruby-version/index.ts b/lib/datasource/ruby-version/index.ts index f5665342b25479..c3315f04e16dc2 100644 --- a/lib/datasource/ruby-version/index.ts +++ b/lib/datasource/ruby-version/index.ts @@ -21,7 +21,7 @@ export async function getReleases( 'all' ); // istanbul ignore if - if (cachedResult !== undefined) { + if (cachedResult) { return cachedResult; } try { diff --git a/lib/datasource/terraform-module/index.ts b/lib/datasource/terraform-module/index.ts index b18997eadb7e30..62498efef9bb95 100644 --- a/lib/datasource/terraform-module/index.ts +++ b/lib/datasource/terraform-module/index.ts @@ -71,7 +71,7 @@ export async function getReleases({ pkgUrl ); // istanbul ignore if - if (cachedResult !== undefined) { + if (cachedResult) { return cachedResult; } try { diff --git a/lib/datasource/terraform-provider/index.ts b/lib/datasource/terraform-provider/index.ts index a97f2c333ed002..abe32ad04aa3a4 100644 --- a/lib/datasource/terraform-provider/index.ts +++ b/lib/datasource/terraform-provider/index.ts @@ -34,7 +34,7 @@ export async function getReleases({ pkgUrl ); // istanbul ignore if - if (cachedResult !== undefined) { + if (cachedResult) { return cachedResult; } try { diff --git a/lib/manager/bazel/update.ts b/lib/manager/bazel/update.ts index ea03cc3ff00118..9d9def06e3e578 100644 --- a/lib/manager/bazel/update.ts +++ b/lib/manager/bazel/update.ts @@ -51,7 +51,7 @@ async function getHashFromUrl(url: string): Promise { url ); /* istanbul ignore next line */ - if (cachedResult !== undefined) { + if (cachedResult) { return cachedResult; } try { diff --git a/lib/util/cache/global/file.spec.ts b/lib/util/cache/global/file.spec.ts index e01b33536de1d9..7a774e39019ad2 100644 --- a/lib/util/cache/global/file.spec.ts +++ b/lib/util/cache/global/file.spec.ts @@ -6,10 +6,8 @@ describe('lib/util/cache/global/file', () => { init(os.tmpdir()); }); - it('returns undefined if no match', async () => { - expect( - await global.renovateCache.get('test', 'missing-key') - ).toBeUndefined(); + it('gets null', async () => { + expect(await global.renovateCache.get('test', 'missing-key')).toBeNull(); }); it('sets and gets', async () => { @@ -19,6 +17,6 @@ describe('lib/util/cache/global/file', () => { it('expires', async () => { await global.renovateCache.set('test', 'key', 1234, -5); - expect(await global.renovateCache.get('test', 'key')).toBeUndefined(); + expect(await global.renovateCache.get('test', 'key')).toBeNull(); }); }); diff --git a/lib/util/cache/global/file.ts b/lib/util/cache/global/file.ts index e13818c5af40be..589dd84e3a52c8 100644 --- a/lib/util/cache/global/file.ts +++ b/lib/util/cache/global/file.ts @@ -29,7 +29,7 @@ async function get(namespace: string, key: string): Promise { } catch (err) { logger.trace({ namespace, key }, 'Cache miss'); } - return undefined; + return null; } async function set( diff --git a/lib/workers/pr/changelog/release-notes.ts b/lib/workers/pr/changelog/release-notes.ts index 124c3456052b5d..2ac8bae972b617 100644 --- a/lib/workers/pr/changelog/release-notes.ts +++ b/lib/workers/pr/changelog/release-notes.ts @@ -355,7 +355,7 @@ export async function addReleaseNotes( let releaseNotes: ChangeLogNotes; const cacheKey = getCacheKey(v.version); releaseNotes = await globalCache.get(cacheNamespace, cacheKey); - if (releaseNotes === undefined) { + if (!releaseNotes) { if (input.project.github != null) { releaseNotes = await getReleaseNotesMd( repository, @@ -388,7 +388,7 @@ export async function addReleaseNotes( await globalCache.set( cacheNamespace, cacheKey, - releaseNotes || null, + releaseNotes, cacheMinutes ); } diff --git a/lib/workers/pr/changelog/source-github.ts b/lib/workers/pr/changelog/source-github.ts index 24237281af30b1..33e7a6c0dafc0f 100644 --- a/lib/workers/pr/changelog/source-github.ts +++ b/lib/workers/pr/changelog/source-github.ts @@ -155,7 +155,7 @@ export async function getChangeLogJSON({ getCacheKey(prev.version, next.version) ); // istanbul ignore else - if (release === undefined) { + if (!release) { release = { version: next.version, date: next.releaseTimestamp, diff --git a/lib/workers/pr/changelog/source-gitlab.ts b/lib/workers/pr/changelog/source-gitlab.ts index 694519ca0762dd..4826fe4dd612cb 100644 --- a/lib/workers/pr/changelog/source-gitlab.ts +++ b/lib/workers/pr/changelog/source-gitlab.ts @@ -135,7 +135,7 @@ export async function getChangeLogJSON({ cacheNamespace, getCacheKey(prev.version, next.version) ); - if (release === undefined) { + if (!release) { release = { version: next.version, date: next.releaseTimestamp, diff --git a/lib/workers/repository/stats.ts b/lib/workers/repository/stats.ts index dc015fc3b1aebe..167a8b659df7b3 100644 --- a/lib/workers/repository/stats.ts +++ b/lib/workers/repository/stats.ts @@ -26,7 +26,7 @@ export function printRequestStats(): void { requestHosts[hostname] = requestHosts[hostname] || []; requestHosts[hostname].push(request.duration); } - logger.debug({ allRequests, requestHosts }, 'full stats'); + logger.trace({ allRequests, requestHosts }, 'full stats'); const hostStats: string[] = []; let totalRequests = 0; for (const [hostname, requests] of Object.entries(requestHosts)) {