Skip to content

Commit ea0a894

Browse files
authored
Merge pull request #186 from fairdataihub/copying-license
feat: ✨ Detect COPYING & COPYING.LESSER license files
2 parents b0d94e9 + 04bbd88 commit ea0a894

5 files changed

Lines changed: 19 additions & 5 deletions

File tree

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
-- AlterTable
2+
ALTER TABLE "LicenseRequest" ADD COLUMN "license_path" TEXT NOT NULL DEFAULT '';

ui/prisma/schema.prisma

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ model LicenseRequest {
5959
contains_license Boolean @default(false)
6060
license_status String @default("")
6161
license_id String?
62+
license_path String @default("")
6263
license_content String @default("")
6364
pull_request_url String @default("")
6465
created_at DateTime @default(now())

ui/server/services/compliance/license.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ export interface LicenseResult {
1717
interface ExistingLicense {
1818
id: string;
1919
license_id: string | null;
20+
license_path: string;
2021
license_content: string;
2122
license_status: string;
2223
contains_license: boolean;
@@ -59,7 +60,13 @@ function normalizeContent(content: string | null | undefined): string {
5960

6061
// == Public API ===============================================================
6162

62-
const LICENSE_PATHS = ["LICENSE", "LICENSE.md", "LICENSE.txt"];
63+
const LICENSE_PATHS = [
64+
"LICENSE",
65+
"LICENSE.md",
66+
"LICENSE.txt",
67+
"COPYING",
68+
"COPYING.LESSER",
69+
];
6370

6471
/**
6572
* Checks whether a LICENSE file exists in the repository and detects its SPDX ID.
@@ -205,6 +212,7 @@ export async function updateLicenseDatabase(
205212
let licenseId: string | null = license.spdx_id;
206213
let licenseContent = license.content;
207214
let licenseContentEmpty = license.content === "";
215+
let licensePath = license.status ? license.path : "";
208216

209217
const existingLicense = await prisma.licenseRequest.findUnique({
210218
where: { repository_id: repositoryId },
@@ -222,13 +230,15 @@ export async function updateLicenseDatabase(
222230
licenseId = existingLicense.license_id;
223231
licenseContent = existingLicense.license_content;
224232
licenseContentEmpty = !licenseContent;
233+
licensePath = existingLicense.license_path;
225234
}
226235

227236
return prisma.licenseRequest.update({
228237
data: {
229238
contains_license: license.status,
230239
license_status: licenseContentEmpty ? "invalid" : "valid",
231240
license_id: licenseId,
241+
license_path: licensePath,
232242
license_content: licenseContent,
233243
custom_license_title:
234244
licenseId === "Custom" ? existingLicense.custom_license_title : "",
@@ -252,6 +262,7 @@ export async function updateLicenseDatabase(
252262
contains_license: license.status,
253263
license_status: licenseContentEmpty ? "invalid" : "valid",
254264
license_id: licenseId,
265+
license_path: licensePath,
255266
license_content: licenseContent,
256267
custom_license_title: "",
257268
repository: { connect: { id: repositoryId } },

ui/server/services/dashboard/manager.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -498,7 +498,7 @@ async function _subjectsFromDb(repositoryId: number): Promise<{
498498
cwl: null,
499499
license: {
500500
content: licenseDb?.license_content ?? "",
501-
path: "",
501+
path: licenseDb?.license_path ?? "",
502502
spdx_id: licenseDb?.license_id ?? null,
503503
status: licenseDb?.contains_license ?? false,
504504
},

ui/server/services/dashboard/renderer.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -543,17 +543,17 @@ function renderLicense(
543543

544544
let section = "";
545545
if (license.status && licenseId && licenseId !== "Custom") {
546-
section = `## LICENSE ✔️\n\nA \`LICENSE\` file is found at the root level of the repository.\n\n${badge}\n\n`;
546+
section = `## LICENSE ✔️\n\nA \`${license.path}\` file is found at the root level of the repository.\n\n**Detected license:** \`${licenseId}\` (SPDX identifier)\n\n${badge}\n\n`;
547547
} else if (license.status && licenseId === "Custom" && !customLicenseTitle) {
548548
section =
549-
`## LICENSE ❗\n\nYour \`LICENSE\` file needs verification. This can happen when:\n` +
549+
`## LICENSE ❗\n\nYour \`${license.path}\` file needs verification. This can happen when:\n` +
550550
`- Your license content was modified and we need you to confirm the license type\n` +
551551
`- You're using a license that GitHub doesn't recognize but may still be a valid SPDX license\n` +
552552
`- You're using a truly custom license\n\n` +
553553
`> [!NOTE]\n> If you plan to archive on Zenodo, you'll need to select a license from the SPDX license list. Custom licenses are not currently supported by Zenodo's API.\n\n` +
554554
`Click the "Edit license" button below to **confirm your license type** (select from the dropdown and choose "Keep existing content") or provide a custom license title.\n\n${badge}\n\n`;
555555
} else if (license.status && licenseId === "Custom" && customLicenseTitle) {
556-
section = `## LICENSE ✔️\n\nA custom \`LICENSE\` file titled as **${customLicenseTitle}**, has been found at the root level of this repository. If you would like to update the title or change license, click the "Edit license" button below.\n\n${badge}\n\n`;
556+
section = `## LICENSE ✔️\n\nA custom \`${license.path}\` file titled as **${customLicenseTitle}**, has been found at the root level of this repository. If you would like to update the title or change license, click the "Edit license" button below.\n\n${badge}\n\n`;
557557
} else {
558558
section =
559559
`## LICENSE ❌\n\nTo make your software reusable, a \`LICENSE\` file is expected at the root level of your repository.\n` +

0 commit comments

Comments
 (0)