From bad3fdcce8f6b05a9716da4f1df2c8923a6eb8a6 Mon Sep 17 00:00:00 2001 From: Rhys Arkins <rhys@arkins.net> Date: Mon, 17 Jun 2019 18:36:21 +0200 Subject: [PATCH] fix(bazel): correct git tag sha Closes #3938 --- lib/datasource/github/index.js | 9 ++++++++- test/datasource/github.spec.js | 29 +++++++++++++++++++++++++++-- 2 files changed, 35 insertions(+), 3 deletions(-) diff --git a/lib/datasource/github/index.js b/lib/datasource/github/index.js index 748858005b..e8f9874173 100644 --- a/lib/datasource/github/index.js +++ b/lib/datasource/github/index.js @@ -75,7 +75,14 @@ async function getTagCommit(githubRepo, tag) { let digest; try { const url = `https://api.github.com/repos/${githubRepo}/git/refs/tags/${tag}`; - digest = (await ghGot(url)).body.object.sha; + const res = (await ghGot(url)).body.object; + if (res.type === 'commit') { + digest = res.sha; + } else if (res.type === 'tag') { + digest = (await ghGot(res.url)).body.object.sha; + } else { + logger.warn({ res }, 'Unknown git tag refs type'); + } } catch (err) { logger.info( { githubRepo, err }, diff --git a/test/datasource/github.spec.js b/test/datasource/github.spec.js index 6f51456399..562553254f 100644 --- a/test/datasource/github.spec.js +++ b/test/datasource/github.spec.js @@ -32,14 +32,39 @@ describe('datasource/github', () => { ); expect(res).toBe('abcdef'); }); - it('returns tagged digest', async () => { - ghGot.mockReturnValueOnce({ body: { object: { sha: 'ddd111' } } }); + it('returns commit digest', async () => { + ghGot.mockReturnValueOnce({ + body: { object: { type: 'commit', sha: 'ddd111' } }, + }); + const res = await github.getDigest( + { depName: 'some-dep', lookupName: 'some/dep' }, + 'v1.2.0' + ); + expect(res).toBe('ddd111'); + }); + it('returns tagged commit digest', async () => { + ghGot.mockReturnValueOnce({ + body: { object: { type: 'tag', url: 'some-url' } }, + }); + ghGot.mockReturnValueOnce({ + body: { object: { type: 'commit', sha: 'ddd111' } }, + }); const res = await github.getDigest( { depName: 'some-dep', lookupName: 'some/dep' }, 'v1.2.0' ); expect(res).toBe('ddd111'); }); + it('warns if unknown ref', async () => { + ghGot.mockReturnValueOnce({ + body: { object: { sha: 'ddd111' } }, + }); + const res = await github.getDigest( + { depName: 'some-dep', lookupName: 'some/dep' }, + 'v1.2.0' + ); + expect(res).toBeNull(); + }); it('returns null for missed tagged digest', async () => { ghGot.mockReturnValueOnce({}); const res = await github.getDigest( -- GitLab