diff --git a/lib/datasource/git-refs/__snapshots__/index.spec.ts.snap b/lib/datasource/git-refs/__snapshots__/index.spec.ts.snap index c79c0dadfe9418d065920abac3b5942789af08fe..322630eefff64ffe0d49665758892510c3067214 100644 --- a/lib/datasource/git-refs/__snapshots__/index.spec.ts.snap +++ b/lib/datasource/git-refs/__snapshots__/index.spec.ts.snap @@ -5,14 +5,17 @@ Object { "releases": Array [ Object { "gitRef": "0.0.1", + "newDigest": "commithash1", "version": "0.0.1", }, Object { "gitRef": "v0.0.2", + "newDigest": "commithash2", "version": "v0.0.2", }, Object { "gitRef": "v0.0.3", + "newDigest": "commithash4", "version": "v0.0.3", }, ], diff --git a/lib/datasource/git-refs/index.ts b/lib/datasource/git-refs/index.ts index d95c50836c02917426b9ed02974532bfc8fe8c6c..6144276a80e9345753e2e41ccb4f846670d3de64 100644 --- a/lib/datasource/git-refs/index.ts +++ b/lib/datasource/git-refs/index.ts @@ -13,6 +13,7 @@ process.env.GIT_SSH_COMMAND = 'ssh -o BatchMode=yes'; export interface RawRefs { type: string; value: string; + hash: string; } export async function getRawRefs({ @@ -43,22 +44,27 @@ export async function getRawRefs({ return null; } + const refMatch = /(?<hash>.*?)\s+refs\/(?<type>.*?)\/(?<value>.*)/; + const refs = lsRemote .trim() - .replace(/^.+?refs\//gm, '') - .split('\n'); - - const refMatch = /(?<type>\w+)\/(?<value>.*)/; - const result = refs.map((ref) => { - const match = refMatch.exec(ref); - return { - type: match.groups.type, - value: match.groups.value, - }; - }); - - await renovateCache.set(cacheNamespace, lookupName, result, cacheMinutes); - return result; + .split('\n') + .map((line) => line.trim()) + .map((line) => { + const match = refMatch.exec(line); + if (!match) { + return null; + } + return { + type: match.groups.type, + value: match.groups.value, + hash: match.groups.hash, + }; + }) + .filter(Boolean); + + await renovateCache.set(cacheNamespace, lookupName, refs, cacheMinutes); + return refs; } catch (err) { logger.error({ err }, `Git-Raw-Refs lookup error in ${lookupName}`); } @@ -85,6 +91,7 @@ export async function getReleases({ releases: uniqueRefs.map((ref) => ({ version: ref, gitRef: ref, + newDigest: rawRefs.find((rawRef) => rawRef.value === ref).hash, })), }; diff --git a/lib/datasource/git-tags/__snapshots__/index.spec.ts.snap b/lib/datasource/git-tags/__snapshots__/index.spec.ts.snap index 8a6ed73d6dd2f0b5c21316c13360699025916727..4352fbb6e3b6d2b201298282d4c4244887576865 100644 --- a/lib/datasource/git-tags/__snapshots__/index.spec.ts.snap +++ b/lib/datasource/git-tags/__snapshots__/index.spec.ts.snap @@ -5,10 +5,12 @@ Object { "releases": Array [ Object { "gitRef": "0.0.1", + "newDigest": "commithash1", "version": "0.0.1", }, Object { "gitRef": "v0.0.2", + "newDigest": "commithash2", "version": "v0.0.2", }, ], diff --git a/lib/datasource/git-tags/index.ts b/lib/datasource/git-tags/index.ts index 85c374a6f24dc1639ec824f55788a4f8d7883dcc..6014caec6416ebd2730ac502e385cc3e7f61eaf2 100644 --- a/lib/datasource/git-tags/index.ts +++ b/lib/datasource/git-tags/index.ts @@ -12,19 +12,20 @@ export async function getReleases({ if (rawRefs === null) { return null; } - const tags = rawRefs + const releases = rawRefs .filter((ref) => ref.type === 'tags') - .map((ref) => ref.value) - .filter((tag) => semver.isVersion(tag)); + .filter((ref) => semver.isVersion(ref.value)) + .map((ref) => ({ + version: ref.value, + gitRef: ref.value, + newDigest: ref.hash, + })); const sourceUrl = lookupName.replace(/\.git$/, '').replace(/\/$/, ''); const result: ReleaseResult = { sourceUrl, - releases: tags.map((tag) => ({ - version: tag, - gitRef: tag, - })), + releases, }; return result;