Skip to content

Commit 83edbc9

Browse files
committed
Qualifiers are a map of string key-value pairs
1 parent 5a8ce4a commit 83edbc9

File tree

5 files changed

+40
-15
lines changed

5 files changed

+40
-15
lines changed

componentDetection.test.ts

Lines changed: 27 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,39 @@
1-
import ComponentDetection from './componentDetection';
2-
import fs from 'fs';
1+
import ComponentDetection from "./componentDetection";
2+
import fs from "fs";
33

4-
test('Downloads CLI', async () => {
4+
test("Downloads CLI", async () => {
55
await ComponentDetection.downloadLatestRelease();
66
expect(fs.existsSync(ComponentDetection.componentDetectionPath));
77
});
88

9-
test('Runs CLI', async () => {
9+
test("Runs CLI", async () => {
1010
await ComponentDetection.downloadLatestRelease();
11-
await ComponentDetection.runComponentDetection('./test');
11+
await ComponentDetection.runComponentDetection("./test");
1212
expect(fs.existsSync(ComponentDetection.outputPath));
1313
});
1414

15-
test('Parses CLI output', async () => {
15+
test("Parses CLI output", async () => {
1616
await ComponentDetection.downloadLatestRelease();
17-
await ComponentDetection.runComponentDetection('./test');
17+
await ComponentDetection.runComponentDetection("./test");
1818
var manifests = await ComponentDetection.getManifestsFromResults();
1919
expect(manifests?.length == 2);
20-
});
20+
});
21+
22+
describe("ComponentDetection.makePackageUrl", () => {
23+
test("returns a valid package url", () => {
24+
const packageUrl = ComponentDetection.makePackageUrl({
25+
Scheme: "pkg",
26+
Type: "npm",
27+
Namespace: "github",
28+
Name: "component-detection-action",
29+
Version: "0.0.2",
30+
Qualifiers: {
31+
arch: "amd64",
32+
os: "linux",
33+
},
34+
});
35+
expect(packageUrl).toBe(
36+
"pkg:npm/github/component-detection-action@0.0.2?arch=amd64&os=linux"
37+
);
38+
});
39+
});

componentDetection.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ export default class ComponentDetection {
119119
return pkg.isDevelopmentDependency ? 'development' : 'runtime'
120120
}
121121

122-
private static makePackageUrl(packageUrlJson: any): string {
122+
public static makePackageUrl(packageUrlJson: any): string {
123123
var packageUrl = `${packageUrlJson.Scheme}:${packageUrlJson.Type}/`;
124124
if (packageUrlJson.Namespace) {
125125
packageUrl += `${packageUrlJson.Namespace.replaceAll("@", "%40")}/`;
@@ -128,8 +128,11 @@ export default class ComponentDetection {
128128
if (packageUrlJson.Version) {
129129
packageUrl += `@${packageUrlJson.Version}`;
130130
}
131-
if (packageUrlJson.Qualifiers) {
132-
packageUrl += `?${packageUrlJson.Qualifiers}`;
131+
if (packageUrlJson.Qualifiers !== null) {
132+
const qualifierString = Object.entries(packageUrlJson.Qualifiers)
133+
.map(([key, value]) => `${key}=${value}`)
134+
.join("&");
135+
packageUrl += `?${qualifierString}`;
133136
}
134137
return packageUrl;
135138
}

dist/componentDetection.d.ts

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/index.js

Lines changed: 5 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/index.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)