Skip to content

Commit

Permalink
fix(manager/gomod): resolve multi-line indirect dependencies
Browse files Browse the repository at this point in the history
As noticed in #19440, the handling for indirect dependencies didn't
quite work when using a multi-line `require` block.

Closes #19440.
  • Loading branch information
Jamie Tanna committed Dec 16, 2022
1 parent 2f403dc commit 6ff7b71
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 1 deletion.
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
14 changes: 13 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,9 @@ 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('extracts replace directives from multi-line and single line', () => {
Expand Down Expand Up @@ -83,6 +84,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

0 comments on commit 6ff7b71

Please sign in to comment.