Skip to content
Snippets Groups Projects
Unverified Commit 9d61733e authored by Roc's avatar Roc Committed by GitHub
Browse files

fix(go): match go-source by go module prefix (#6930)

parent 9154bc76
No related branches found
No related tags found
No related merge requests found
...@@ -14,6 +14,20 @@ Array [ ...@@ -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`] = ` exports[`datasource/go getDigest returns null for wrong name 1`] = `
Array [ Array [
Object { Object {
......
...@@ -34,6 +34,16 @@ describe('datasource/go', () => { ...@@ -34,6 +34,16 @@ describe('datasource/go', () => {
}); });
describe('getDigest', () => { 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 () => { it('returns null for wrong name', async () => {
httpMock httpMock
.scope('https://golang.org/') .scope('https://golang.org/')
......
...@@ -37,10 +37,14 @@ async function getDatasource(goModule: string): Promise<DataSource | null> { ...@@ -37,10 +37,14 @@ async function getDatasource(goModule: string): Promise<DataSource | null> {
const pkgUrl = `https://${goModule}?go-get=1`; const pkgUrl = `https://${goModule}?go-get=1`;
const res = (await http.get(pkgUrl)).body; const res = (await http.get(pkgUrl)).body;
const sourceMatch = regEx( 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); ).exec(res);
if (sourceMatch) { 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'); logger.debug({ goModule, goSourceUrl }, 'Go lookup source url');
if (goSourceUrl?.startsWith('https://github.com/')) { if (goSourceUrl?.startsWith('https://github.com/')) {
return { return {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment