Skip to content

Commit

Permalink
fix(go): match go-source by go module prefix (#6930)
Browse files Browse the repository at this point in the history
  • Loading branch information
rocwind committed Aug 10, 2020
1 parent 9154bc7 commit 9d61733
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 2 deletions.
14 changes: 14 additions & 0 deletions lib/datasource/go/__snapshots__/index.spec.ts.snap
Expand Up @@ -14,6 +14,20 @@ Array [
]
`;

exports[`datasource/go getDigest returns null for no go-source tag 1`] = `
Array [
Object {
"headers": Object {
"accept-encoding": "gzip, deflate",
"host": "golang.org",
"user-agent": "https://github.com/renovatebot/renovate",
},
"method": "GET",
"url": "https://golang.org/y/text?go-get=1",
},
]
`;

exports[`datasource/go getDigest returns null for wrong name 1`] = `
Array [
Object {
Expand Down
10 changes: 10 additions & 0 deletions lib/datasource/go/index.spec.ts
Expand Up @@ -34,6 +34,16 @@ describe('datasource/go', () => {
});

describe('getDigest', () => {
it('returns null for no go-source tag', async () => {
httpMock
.scope('https://golang.org/')
.get('/y/text?go-get=1')
.reply(200, '');
github.getDigest.mockResolvedValueOnce('abcdefabcdefabcdefabcdef');
const res = await getDigest({ lookupName: 'golang.org/y/text' }, null);
expect(res).toBeNull();
expect(httpMock.getTrace()).toMatchSnapshot();
});
it('returns null for wrong name', async () => {
httpMock
.scope('https://golang.org/')
Expand Down
8 changes: 6 additions & 2 deletions lib/datasource/go/index.ts
Expand Up @@ -37,10 +37,14 @@ async function getDatasource(goModule: string): Promise<DataSource | null> {
const pkgUrl = `https://${goModule}?go-get=1`;
const res = (await http.get(pkgUrl)).body;
const sourceMatch = regEx(
`<meta\\s+name="go-source"\\s+content="${goModule}\\s+([^\\s]+)`
`<meta\\s+name="go-source"\\s+content="([^\\s]+)\\s+([^\\s]+)`
).exec(res);
if (sourceMatch) {
const [, goSourceUrl] = sourceMatch;
const [, prefix, goSourceUrl] = sourceMatch;
if (!goModule.startsWith(prefix)) {
logger.trace({ goModule }, 'go-source header prefix not match');
return null;
}
logger.debug({ goModule, goSourceUrl }, 'Go lookup source url');
if (goSourceUrl?.startsWith('https://github.com/')) {
return {
Expand Down

0 comments on commit 9d61733

Please sign in to comment.