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/nuget): return null for no deps #22282

Merged
merged 1 commit into from May 17, 2023
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
14 changes: 10 additions & 4 deletions lib/modules/manager/nuget/extract.spec.ts
Expand Up @@ -22,10 +22,10 @@ describe('modules/manager/nuget/extract', () => {
GlobalConfig.reset();
});

it('returns empty for invalid csproj', async () => {
expect(await extractPackageFile('nothing here', 'bogus', config)).toEqual(
{ deps: [] }
);
it('returns null for invalid csproj', async () => {
expect(
await extractPackageFile('nothing here', 'bogus', config)
).toBeNull();
});

it('extracts package version dependency', async () => {
Expand Down Expand Up @@ -347,6 +347,12 @@ describe('modules/manager/nuget/extract', () => {
).toBeNull();
});

it('returns null for no deps', async () => {
expect(
await extractPackageFile('{"version": 1}', packageFile, config)
).toBeNull();
});

it('does not throw', async () => {
expect(await extractPackageFile('{{', packageFile, config)).toBeNull();
});
Expand Down
11 changes: 8 additions & 3 deletions lib/modules/manager/nuget/extract.ts
Expand Up @@ -74,7 +74,7 @@ function extractDepsFromXml(xmlNode: XmlDocument): PackageDependency[] {
export async function extractPackageFile(
content: string,
packageFile: string,
config: ExtractConfig
_config: ExtractConfig
): Promise<PackageFileContent | null> {
logger.trace({ packageFile }, 'nuget.extractPackageFile()');

Expand All @@ -99,7 +99,7 @@ export async function extractPackageFile(
return null;
}

for (const depName of Object.keys(manifest.tools)) {
for (const depName of Object.keys(manifest.tools ?? {})) {
const tool = manifest.tools[depName];
const currentValue = tool.version;
const dep: PackageDependency = {
Expand All @@ -115,7 +115,7 @@ export async function extractPackageFile(
deps.push(dep);
}

return { deps };
return deps.length ? { deps } : null;
}

if (packageFile.endsWith('global.json')) {
Expand All @@ -134,6 +134,11 @@ export async function extractPackageFile(
} catch (err) {
logger.debug({ err }, `Failed to parse ${packageFile}`);
}

if (!deps.length) {
return null;
}

const res: PackageFileContent = { deps, packageFileVersion };
const lockFileName = getSiblingFileName(packageFile, 'packages.lock.json');
// istanbul ignore if
Expand Down