Skip to content

Commit

Permalink
fix: proj name when using assets-project-name flag (#5077)
Browse files Browse the repository at this point in the history
  • Loading branch information
37IulianPopovici authored Jun 10, 2024
1 parent 520bf8b commit 57dc718
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/cli/commands/monitor/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -371,6 +371,7 @@ function generateMonitorMeta(options, packageManager?): MonitorMeta {
prune: !!options.pruneRepeatedSubdependencies,
'remote-repo-url': options['remote-repo-url'],
targetReference: options['target-reference'],
assetsProjectName: options['assets-project-name'],
};
}

Expand Down
4 changes: 4 additions & 0 deletions src/lib/monitor/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@ export function getProjectName(
return scannedProject.meta.gradleProjectName;
}

if (meta.assetsProjectName && !meta['project-name']) {
return scannedProject.depTree?.name;
}

return meta['project-name'];
}

Expand Down
1 change: 1 addition & 0 deletions src/lib/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@ export interface MonitorMeta {
prune: boolean;
'remote-repo-url'?: string;
targetReference?: string;
assetsProjectName?: boolean;
}

export interface Tag {
Expand Down
58 changes: 58 additions & 0 deletions test/jest/unit/cli-monitor-utils.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,64 @@ describe('cli-monitor-utils test', () => {
expect(res).toEqual('project-name-override');
});

it('getProjectName returns nuget project name from scanned project meta when --assets-project-name is provided via options', () => {
const scannedProject: ScannedProject = {
depTree: {
dependencies: {
'Microsoft.Extensions.FileProviders.Embedded': {
name: 'Microsoft.Extensions.FileProviders.Embedded',
version: '6.0.22',
},
},
name: 'nuget-project-assets-name',
packageFormatVersion: 'nuget:0.0.0',
version: '0.0.1',
targetFile: 'project.assets.json',
},
targetFile: 'project.assets.json',
};

const res = utils.getProjectName(scannedProject, {
method: 'cli',
packageManager: 'nuget',
'policy-path': '',
'project-name': '',
isDocker: false,
prune: false,
assetsProjectName: true,
});
expect(res).toEqual('nuget-project-assets-name');
});

it('getProjectName overrides --assets-project-name with value from --project-name flag', () => {
const scannedProject: ScannedProject = {
depTree: {
dependencies: {
'Microsoft.Extensions.FileProviders.Embedded': {
name: 'Microsoft.Extensions.FileProviders.Embedded',
version: '6.0.22',
},
},
name: 'nuget-project-assets-name',
packageFormatVersion: 'nuget:0.0.0',
version: '0.0.1',
targetFile: 'project.assets.json',
},
targetFile: 'project.assets.json',
};

const res = utils.getProjectName(scannedProject, {
method: 'cli',
packageManager: 'nuget',
'policy-path': '',
'project-name': 'project-name-from-option',
isDocker: false,
prune: false,
assetsProjectName: true,
});
expect(res).toEqual('project-name-from-option');
});

it('getProjectName returns gradle project name from scanned project meta', () => {
const scannedProject: ScannedProject = {
depGraph: {} as any,
Expand Down

0 comments on commit 57dc718

Please sign in to comment.