Skip to content

Commit

Permalink
fix(go): missing Go module v2+ major upgrades (#8945)
Browse files Browse the repository at this point in the history
  • Loading branch information
56KBs authored Mar 7, 2021
1 parent 573de66 commit ac34124
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 1 deletion.
25 changes: 25 additions & 0 deletions lib/datasource/go/__snapshots__/index.spec.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -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",
},
]
`;
27 changes: 27 additions & 0 deletions lib/datasource/go/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
});
});
});
2 changes: 1 addition & 1 deletion lib/datasource/go/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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('/');
Expand Down

0 comments on commit ac34124

Please sign in to comment.