Skip to content

Commit 6a62d59

Browse files
committed
Fixed SPDX expression resolution in detection matches
Signed-off-by: Omkar Phansopkar <[email protected]>
1 parent 3874b5e commit 6a62d59

File tree

12 files changed

+348
-119
lines changed

12 files changed

+348
-119
lines changed

src/components/LicenseEntity/licenseEntity.css

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,6 @@
6969

7070
.rule-info-button {
7171
font-size: 1.05em !important;
72-
color: #007bff !important;
72+
color: var(--bs-btn-bg) !important;
7373
vertical-align: bottom !important;
7474
}

src/pages/Licenses/Licenses.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -298,7 +298,8 @@ const LicenseDetections = () => {
298298
rootClose
299299
overlay={
300300
<Tooltip>
301-
Tick the checkboxes below to mark licenses as reviewed
301+
Tick the checkboxes below to mark license detections as
302+
reviewed
302303
</Tooltip>
303304
}
304305
>

src/services/importedJsonTypes.ts

Lines changed: 20 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,4 @@
1-
export interface LicenseReference {
2-
key: string;
3-
language: string;
4-
short_name: string;
5-
name: string;
6-
category: string;
7-
owner: string;
8-
homepage_url: string;
9-
notes: string;
10-
is_builtin: boolean;
11-
is_exception: boolean;
12-
is_unknown: boolean;
13-
is_generic: boolean;
14-
spdx_license_key: string;
15-
other_spdx_license_keys: string[];
16-
osi_license_key: string | null;
17-
text_urls: string[];
18-
osi_url?: string;
19-
faq_url?: string;
20-
other_urls: string[];
21-
key_aliases: string[];
22-
minimum_coverage: number;
23-
standard_notice: string | null;
24-
ignorable_copyrights: string[];
25-
ignorable_holders: string[];
26-
ignorable_authors: string[];
27-
ignorable_urls: string[];
28-
ignorable_emails: string[];
29-
text: string;
30-
scancode_url: string | null;
31-
licensedb_url: string | null;
32-
spdx_url: string | null;
33-
}
1+
import { LicenseDetectionAttributes } from "./models/licenseDetections";
342

353
export interface LicenseExpressionKey {
364
key: string;
@@ -107,6 +75,22 @@ export interface ResourceLicenseDetection {
10775
identifier: string;
10876
}
10977

78+
export interface LicensePolicy {
79+
license_key: string;
80+
label: string;
81+
color_code: string;
82+
icon: string;
83+
84+
// Parser-added fields
85+
fileId?: number;
86+
}
87+
88+
export interface RawTopLevelTodo {
89+
detection_id: string;
90+
review_comments: Record<string, string>;
91+
detection: LicenseDetectionAttributes;
92+
}
93+
11094
export interface Resource {
11195
id?: number;
11296
path: string;
@@ -192,6 +176,8 @@ export interface Resource {
192176
for_license_detections?: string[];
193177
license_detections?: ResourceLicenseDetection[];
194178
license_clues?: LicenseClue[];
179+
emails?: unknown[];
180+
urls?: unknown[];
195181
copyrights?: {
196182
copyright: string;
197183
start_line: number;
@@ -208,14 +194,7 @@ export interface Resource {
208194
end_line: number;
209195
}[];
210196
percentage_of_license_text?: number;
211-
license_policy?: {
212-
license_key: string;
213-
label: string;
214-
color_code: string;
215-
icon: string;
216-
// Parser-added fields
217-
fileId?: number;
218-
}[];
197+
license_policy?: LicensePolicy[];
219198
scan_errors?: string[];
220199

221200
// Parser-added fields

src/services/models/database.ts

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -39,17 +39,9 @@ import licenseRuleReferenceModel, {
3939
LicenseRuleReferenceAttributes,
4040
} from "./licenseRuleReference";
4141
import todoModel, { TodoAttributes } from "./todo";
42-
43-
// let Header;
44-
// let File;
45-
// let License;
46-
// let Copyright;
47-
// let Package;
48-
// let Email;
49-
// let Url;
50-
// let Scan;
51-
52-
// type SupportedModels = <Model<HeaderAttributes, HeaderAttributes>>;
42+
import licenseReferenceModel, {
43+
LicenseReferenceAttributes,
44+
} from "./licenseReference";
5345

5446
export interface DatabaseStructure {
5547
// Top level entities
@@ -61,6 +53,9 @@ export interface DatabaseStructure {
6153
LicenseDetections: ModelStatic<
6254
Model<LicenseDetectionAttributes, LicenseDetectionAttributes>
6355
>;
56+
LicenseReferences: ModelStatic<
57+
Model<LicenseReferenceAttributes, LicenseReferenceAttributes>
58+
>;
6459
LicenseRuleReferences: ModelStatic<
6560
Model<LicenseRuleReferenceAttributes, LicenseRuleReferenceAttributes>
6661
>;
@@ -94,6 +89,7 @@ export function newDatabase(sequelize: Sequelize): DatabaseStructure {
9489
Packages: packagesModel(sequelize),
9590
Dependencies: dependenciesModel(sequelize),
9691
LicenseDetections: licenseDetectionModel(sequelize),
92+
LicenseReferences: licenseReferenceModel(sequelize),
9793
LicenseRuleReferences: licenseRuleReferenceModel(sequelize),
9894
LicenseClues: licenseClueModel(sequelize),
9995
Todo: todoModel(sequelize),

src/services/models/flatFile.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
import path from "path";
1818
import { Sequelize, DataTypes, Model } from "sequelize";
1919
import { jsonDataType, parentPath } from "./databaseUtils";
20+
import { LicensePolicy, Resource } from "../importedJsonTypes";
2021

2122
export interface InfoFlatFileAttributes {
2223
type: string;
@@ -265,7 +266,7 @@ interface FlattenedFile {
265266
name: string;
266267
extension: string;
267268
date: string;
268-
size: string;
269+
size: number;
269270
sha1: string;
270271
md5: string;
271272
file_count: number;
@@ -310,7 +311,7 @@ interface FlattenedFile {
310311
package_data_dependencies: unknown[];
311312
package_data_related_packages: unknown[];
312313
}
313-
export function flattenFile(file: any): FlattenedFile {
314+
export function flattenFile(file: Resource): FlattenedFile {
314315
return {
315316
id: file.id,
316317
fileId: file.id,
@@ -406,7 +407,7 @@ export function flattenFile(file: any): FlattenedFile {
406407
};
407408
}
408409

409-
function getLicensePolicyLabel(policy: any[]) {
410+
function getLicensePolicyLabel(policy: LicensePolicy[]) {
410411
if (!policy) {
411412
return [];
412413
}
@@ -429,7 +430,7 @@ function getCopyrightValues(
429430
if (!array || !Array.isArray(array)) {
430431
array = [];
431432
}
432-
const values = array.map((val: any) => val[field]);
433+
const values = array.map((val: Record<string, unknown>) => val[field]);
433434
// must wrap this in a list for datatables display; not sure why
434435
return [values];
435436
}
Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
/*
2+
#
3+
# Copyright (c) nexB Inc. and others. All rights reserved.
4+
# https://nexb.com and https://github.com/nexB/scancode-workbench/
5+
# The ScanCode Workbench software is licensed under the Apache License version 2.0.
6+
# ScanCode is a trademark of nexB Inc.
7+
#
8+
# You may not use this software except in compliance with the License.
9+
# You may obtain a copy of the License at: http://apache.org/licenses/LICENSE-2.0
10+
# Unless required by applicable law or agreed to in writing, software distributed
11+
# under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
12+
# CONDITIONS OF ANY KIND, either express or implied. See the License for the
13+
# specific language governing permissions and limitations under the License.
14+
#
15+
*/
16+
17+
import { Sequelize, DataTypes, Model } from "sequelize";
18+
import { jsonDataType } from "./databaseUtils";
19+
20+
export interface LicenseReferenceAttributes {
21+
id: number;
22+
key: string;
23+
language: string;
24+
short_name: string;
25+
name: string;
26+
category: string;
27+
owner: string;
28+
homepage_url: string;
29+
is_builtin: boolean;
30+
is_exception: boolean;
31+
is_unknown: boolean;
32+
is_generic: boolean;
33+
spdx_license_key: string;
34+
other_spdx_license_keys: string[];
35+
osi_license_key: string;
36+
osi_url: string;
37+
// notes: string;
38+
// ignorable_copyrights: string[];
39+
// ignorable_holders: string[];
40+
// ignorable_authors: string[];
41+
// ignorable_urls: string[];
42+
// ignorable_emails: string[];
43+
text: string;
44+
scancode_url: string;
45+
licensedb_url: string;
46+
spdx_url: string;
47+
}
48+
49+
export default function licenseReferenceModel(sequelize: Sequelize) {
50+
return sequelize.define<Model<LicenseReferenceAttributes>>(
51+
"license_reference",
52+
{
53+
id: {
54+
allowNull: false,
55+
autoIncrement: true,
56+
primaryKey: true,
57+
type: DataTypes.INTEGER,
58+
},
59+
key: DataTypes.STRING,
60+
language: DataTypes.STRING,
61+
short_name: DataTypes.STRING,
62+
name: DataTypes.STRING,
63+
category: DataTypes.STRING,
64+
owner: DataTypes.STRING,
65+
homepage_url: DataTypes.STRING,
66+
is_builtin: DataTypes.BOOLEAN,
67+
is_exception: DataTypes.BOOLEAN,
68+
is_unknown: DataTypes.BOOLEAN,
69+
is_generic: DataTypes.BOOLEAN,
70+
spdx_license_key: DataTypes.STRING,
71+
other_spdx_license_keys: jsonDataType("other_spdx_license_keys", []),
72+
osi_license_key: DataTypes.STRING,
73+
osi_url: DataTypes.STRING,
74+
// notes: DataTypes.STRING,
75+
// ignorable_copyrights: jsonDataType("ignorable_copyrights", []),
76+
// ignorable_holders: jsonDataType("ignorable_holders", []),
77+
// ignorable_authors: jsonDataType("ignorable_authors", []),
78+
// ignorable_urls: jsonDataType("ignorable_urls", []),
79+
// ignorable_emails: jsonDataType("ignorable_emails", []),
80+
text: DataTypes.STRING,
81+
scancode_url: DataTypes.STRING,
82+
licensedb_url: DataTypes.STRING,
83+
spdx_url: DataTypes.STRING,
84+
},
85+
{
86+
timestamps: false,
87+
}
88+
);
89+
}

0 commit comments

Comments
 (0)