From ac34124f8c2ca048cad8ee510e6f08e5f3a46cbc Mon Sep 17 00:00:00 2001 From: Matt Palmer <9059517+56KBs@users.noreply.github.com> Date: Sun, 7 Mar 2021 20:27:05 +0000 Subject: [PATCH] fix(go): missing Go module v2+ major upgrades (#8945) --- .../go/__snapshots__/index.spec.ts.snap | 25 +++++++++++++++++ lib/datasource/go/index.spec.ts | 27 +++++++++++++++++++ lib/datasource/go/index.ts | 2 +- 3 files changed, 53 insertions(+), 1 deletion(-) diff --git a/lib/datasource/go/__snapshots__/index.spec.ts.snap b/lib/datasource/go/__snapshots__/index.spec.ts.snap index f897c9532e..625877a6e8 100644 --- a/lib/datasource/go/__snapshots__/index.spec.ts.snap +++ b/lib/datasource/go/__snapshots__/index.spec.ts.snap @@ -570,3 +570,28 @@ Array [ }, ] `; + +exports[`datasource/go getReleases works for nested modules on github v2+ major upgrades 1`] = ` +Array [ + Object { + "headers": Object { + "accept": "application/vnd.github.v3+json", + "accept-encoding": "gzip, deflate", + "host": "api.github.com", + "user-agent": "https://github.com/renovatebot/renovate", + }, + "method": "GET", + "url": "https://api.github.com/repos/x/text/tags?per_page=100", + }, + Object { + "headers": Object { + "accept": "application/vnd.github.v3+json", + "accept-encoding": "gzip, deflate", + "host": "api.github.com", + "user-agent": "https://github.com/renovatebot/renovate", + }, + "method": "GET", + "url": "https://api.github.com/repos/x/text/releases?per_page=100", + }, +] +`; diff --git a/lib/datasource/go/index.spec.ts b/lib/datasource/go/index.spec.ts index 276712b1b8..ea5993f520 100644 --- a/lib/datasource/go/index.spec.ts +++ b/lib/datasource/go/index.spec.ts @@ -418,5 +418,32 @@ describe('datasource/go', () => { httpMock.reset(); } }); + it('works for nested modules on github v2+ major upgrades', async () => { + const pkg = { datasource, depName: 'github.com/x/text/b/v2' }; + const tags = [ + { name: 'a/v1.0.0' }, + { name: 'v5.0.0' }, + { name: 'b/v2.0.0' }, + { name: 'b/v3.0.0' }, + ]; + + httpMock.setup(); + httpMock + .scope('https://api.github.com/') + .get('/repos/x/text/tags?per_page=100') + .reply(200, tags) + .get('/repos/x/text/releases?per_page=100') + .reply(200, []); + + const result = await getPkgReleases(pkg); + expect(result.releases).toEqual([ + { gitRef: 'b/v2.0.0', version: 'v2.0.0' }, + { gitRef: 'b/v3.0.0', version: 'v3.0.0' }, + ]); + + const httpCalls = httpMock.getTrace(); + expect(httpCalls).toMatchSnapshot(); + httpMock.reset(); + }); }); }); diff --git a/lib/datasource/go/index.ts b/lib/datasource/go/index.ts index a1d8add342..ba341aea2b 100644 --- a/lib/datasource/go/index.ts +++ b/lib/datasource/go/index.ts @@ -181,7 +181,7 @@ export async function getReleases({ * and that tag should be used instead of just va.b.c, although for compatibility * the old behaviour stays the same. */ - const nameParts = lookupName.split('/'); + const nameParts = lookupName.replace(/\/v\d+$/, '').split('/'); logger.trace({ nameParts, releases: res.releases }, 'go.getReleases'); if (nameParts.length > 3) { const prefix = nameParts.slice(3, nameParts.length).join('/'); -- GitLab