diff --git a/lib/datasource/github/index.js b/lib/datasource/github/index.js index 748858005be78dfae065bb96e6226e9783c27974..e8f98741732b484a6a6e285de30b4eff09382bde 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 6f51456399d1e56c78b35adefde79c7179d58ef9..562553254f1dbffaa225cf420f385fa2fe511c40 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(