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(manager/gomod): resolve multi-line indirect dependencies #19442

Merged
merged 2 commits into from
Dec 16, 2022
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
13 changes: 13 additions & 0 deletions lib/modules/manager/gomod/__snapshots__/extract.spec.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -636,6 +636,19 @@ exports[`modules/manager/gomod/extract extractPackageFile() extracts multi-line
"multiLine": true,
},
},
{
"currentDigest": "d98b1b443823",
"currentValue": "v0.0.0-20191003171128-d98b1b443823",
"datasource": "go",
"depName": "golang.org/x/net",
"depType": "indirect",
"digestOneAndOnly": true,
"enabled": false,
"managerData": {
"lineNumber": 61,
"multiLine": true,
},
},
]
`;

Expand Down
28 changes: 27 additions & 1 deletion lib/modules/manager/gomod/extract.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,23 @@ describe('modules/manager/gomod/extract', () => {
it('extracts multi-line requires', () => {
const res = extractPackageFile(gomod2)?.deps;
expect(res).toMatchSnapshot();
expect(res).toHaveLength(58);
expect(res).toHaveLength(59);
expect(res?.filter((e) => e.skipReason)).toHaveLength(0);
expect(res?.filter((e) => e.depType === 'indirect')).toHaveLength(1);
});

it('ignores empty spaces in multi-line requires', () => {
const goMod = `
module github.com/renovate-tests/gomod
go 1.19
require (
cloud.google.com/go v0.45.1

github.com/Microsoft/go-winio v0.4.15-0.20190919025122-fc70bd9a86b5 // indirect
)
`;
const res = extractPackageFile(goMod)?.deps;
expect(res).toHaveLength(3);
});

it('extracts replace directives from multi-line and single line', () => {
Expand Down Expand Up @@ -83,6 +98,17 @@ replace (
currentValue: 'v0.17.3',
datasource: 'go',
},
{
managerData: {
lineNumber: 9,
multiLine: true,
},
depName: 'k8s.io/cluster-bootstrap',
depType: 'indirect',
enabled: false,
currentValue: 'v0.17.3',
datasource: 'go',
},
{
managerData: {
lineNumber: 10,
Expand Down
6 changes: 6 additions & 0 deletions lib/modules/manager/gomod/extract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,12 @@ function parseMultiLine(
const dep = getDep(lineNumber, multiMatch, blockType);
dep.managerData!.multiLine = true;
deps.push(dep);
} else if (multiMatch && line.endsWith('// indirect')) {
logger.trace({ lineNumber }, `${blockType} indirect line: "${line}"`);
const dep = getDep(lineNumber, multiMatch, 'indirect');
dep.managerData!.multiLine = true;
dep.enabled = false;
deps.push(dep);
} else if (line.trim() !== ')') {
logger.trace(`No multi-line match: ${line}`);
}
Expand Down