diff --git a/lib/datasource/git-refs/index.spec.ts b/lib/datasource/git-refs/index.spec.ts index 92e389fca1f08e5d18173626b6cafb2e9070a8eb..1466081d0432a4374fe07e9d34e03b6399c93945 100644 --- a/lib/datasource/git-refs/index.spec.ts +++ b/lib/datasource/git-refs/index.spec.ts @@ -31,7 +31,7 @@ describe('datasource/git-refs', () => { simpleGit.mockReturnValue({ listRemote() { return Promise.resolve( - 'commithash1\trefs/tags/0.0.1\ncommithash2\trefs/tags/v0.0.2\ncommithash3\trefs/tags/v0.0.2^{}\ncommithash4\trefs/heads/v0.0.3\ncommithash5\trefs/tags/v0.0.3' + 'commithash1\trefs/tags/0.0.1\ncommithash2\trefs/tags/v0.0.2\ncommithash3\trefs/tags/v0.0.2^{}\ncommithash4\trefs/heads/v0.0.3\ncommithash5\trefs/tags/v0.0.3\n' ); }, }); diff --git a/lib/datasource/git-refs/index.ts b/lib/datasource/git-refs/index.ts index f7e774ceee2b4b468d0f6b45418cee1bd734eded..acf69abd18a2d338cbefd29a375dcacb85ae04cb 100644 --- a/lib/datasource/git-refs/index.ts +++ b/lib/datasource/git-refs/index.ts @@ -32,23 +32,36 @@ export async function getRawRefs({ } // fetch remote tags - const lsRemote = await git.listRemote([lookupName, '--sort=-v:refname']); + const lsRemote = await git.listRemote([ + '--sort=-v:refname', + '--tags', + '--heads', + '--refs', + lookupName, + ]); if (!lsRemote) { return null; } - const refs = lsRemote.replace(/^.+?refs\//gm, '').split('\n'); + const refs = lsRemote + .trim() + .replace(/^.+?refs\//gm, '') + .split('\n'); - const result = refs.map(ref => ({ - type: /(.*?)\//.exec(ref)[1], - value: /\/(.*)/.exec(ref)[1], - })); + 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; } catch (err) { - logger.debug({ err }, `Git-Raw-Refs lookup error in ${lookupName}`); + logger.error({ err }, `Git-Raw-Refs lookup error in ${lookupName}`); } return null; } @@ -78,7 +91,7 @@ export async function getPkgReleases({ return result; } catch (err) { - logger.debug({ err }, `Git-Refs lookup error in ${lookupName}`); + logger.error({ err }, `Git-Refs lookup error in ${lookupName}`); } return null; } diff --git a/lib/datasource/git-tags/index.spec.ts b/lib/datasource/git-tags/index.spec.ts index ba55b7940590c75978ca7d70f65f89155a96426f..007d26c24b60d883eefc69c80d41f973a9149bb1 100644 --- a/lib/datasource/git-tags/index.spec.ts +++ b/lib/datasource/git-tags/index.spec.ts @@ -31,7 +31,7 @@ describe('datasource/git-tags', () => { simpleGit.mockReturnValue({ listRemote() { return Promise.resolve( - 'commithash1\trefs/tags/0.0.1\ncommithash2\trefs/tags/v0.0.2\ncommithash3\trefs/tags/v0.0.2^{}' + 'commithash1\trefs/tags/0.0.1\ncommithash2\trefs/tags/v0.0.2\ncommithash3\trefs/tags/v0.0.2^{}\n' ); }, }); diff --git a/lib/datasource/git-tags/index.ts b/lib/datasource/git-tags/index.ts index 52caabcd90f99df4f6e99dd0ce29686f5fc21a1e..94392a72970af1418f7b39b762cca0d61b218527 100644 --- a/lib/datasource/git-tags/index.ts +++ b/lib/datasource/git-tags/index.ts @@ -1,6 +1,5 @@ import { ReleaseResult, GetReleasesConfig } from '../common'; import * as semver from '../../versioning/semver'; -import { logger } from '../../logger'; import * as gitRefs from '../git-refs'; export const id = 'git-tags'; @@ -8,28 +7,25 @@ export const id = 'git-tags'; export async function getPkgReleases({ lookupName, }: GetReleasesConfig): Promise<ReleaseResult | null> { - try { - // fetch remote tags - const rawRefs: gitRefs.RawRefs[] = await gitRefs.getRawRefs({ lookupName }); + const rawRefs: gitRefs.RawRefs[] = await gitRefs.getRawRefs({ lookupName }); - const tags = rawRefs - .filter(ref => ref.type === 'tags') - .map(ref => ref.value) - .filter(tag => semver.isVersion(tag)); + if (rawRefs === null) { + return null; + } + const tags = rawRefs + .filter(ref => ref.type === 'tags') + .map(ref => ref.value) + .filter(tag => semver.isVersion(tag)); - const sourceUrl = lookupName.replace(/\.git$/, '').replace(/\/$/, ''); + const sourceUrl = lookupName.replace(/\.git$/, '').replace(/\/$/, ''); - const result: ReleaseResult = { - sourceUrl, - releases: tags.map(tag => ({ - version: tag, - gitRef: tag, - })), - }; + const result: ReleaseResult = { + sourceUrl, + releases: tags.map(tag => ({ + version: tag, + gitRef: tag, + })), + }; - return result; - } catch (err) { - logger.debug({ err }, `Git-Tags lookup error in ${lookupName}`); - } - return null; + return result; }