Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(go): Ignore mod type of go-import header #25039

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions lib/modules/datasource/go/base.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -378,6 +378,21 @@ describe('modules/datasource/go/base', () => {
packageName: 'ssh://git.example.com/uncommon',
});
});

it('returns null for mod imports', async () => {
const meta =
'<meta name="go-import" content="buf.build/gen/go/gogo/protobuf/protocolbuffers/go mod https://buf.build/gen/go">';
httpMock
.scope('https://buf.build')
.get('/gen/go/gogo/protobuf/protocolbuffers/go?go-get=1')
.reply(200, meta);

const res = await BaseGoDatasource.getDatasource(
'buf.build/gen/go/gogo/protobuf/protocolbuffers/go'
);

expect(res).toBeNull();
});
});
});
});
7 changes: 6 additions & 1 deletion lib/modules/datasource/go/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -179,12 +179,17 @@ export class BaseGoDatasource {
return null;
}

const [, prefix, , goImportURL] = importMatch;
const [, prefix, proto, goImportURL] = importMatch;
if (!goModule.startsWith(prefix)) {
logger.trace({ goModule }, 'go-import header prefix not match');
return null;
}

if (proto !== 'git') {
logger.trace({ goModule }, 'go-import header proto not git');
return null;
}

logger.debug(`Go module: ${goModule} lookup import url ${goImportURL}`);
// get server base url from import url
const parsedUrl = URL.parse(goImportURL);
Expand Down