Skip to content

Commit

Permalink
fix(go): Ignore mod type of go-import header (#25039)
Browse files Browse the repository at this point in the history
  • Loading branch information
zharinov committed Oct 4, 2023
1 parent ee02ddc commit e504997
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
15 changes: 15 additions & 0 deletions lib/modules/datasource/go/base.spec.ts
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
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

0 comments on commit e504997

Please sign in to comment.