Skip to content

Commit 9cdfd10

Browse files
committed
refactor: ♻️ Workflow update for getting license id and content
1 parent e631459 commit 9cdfd10

2 files changed

Lines changed: 24 additions & 14 deletions

File tree

bot/compliance-checks/license/index.js

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ const CODEFAIR_DOMAIN = process.env.CODEFAIR_APP_DOMAIN;
1717
* @returns {boolean} - Returns true if a license is found in the repository, false otherwise
1818
*/
1919
export async function checkForLicense(context, owner, repoName) {
20-
const readmeFilesTypes = [
20+
const licenseFilesTypes = [
2121
"LICENSE.md",
2222
"LICENSE.txt",
2323
"LICENSE",
@@ -29,23 +29,38 @@ export async function checkForLicense(context, owner, repoName) {
2929
".github/LICENSE",
3030
];
3131

32-
for (const filePath of readmeFilesTypes) {
33-
const readme = await checkForFile(context, owner, repoName, filePath);
34-
if (readme) {
35-
const content = await context.octokit.repos.getContent({
32+
for (const filePath of licenseFilesTypes) {
33+
const file = await checkForFile(context, owner, repoName, filePath);
34+
if (file) {
35+
// Get the actual file content from the repository
36+
const fileContent = await context.octokit.rest.repos.getContent({
3637
owner,
3738
repo: repoName,
3839
path: filePath,
3940
});
40-
const contentData = Buffer.from(content.data.content, "base64").toString(
41-
"utf-8"
42-
);
41+
42+
const contentData = Buffer.from(
43+
fileContent.data.content,
44+
"base64"
45+
).toString("utf-8");
46+
47+
// Try to get the detected license information for the repository
48+
let spdxId = null;
49+
try {
50+
const repoLicense = await context.octokit.rest.licenses.getForRepo({
51+
owner,
52+
repo: repoName,
53+
});
54+
spdxId = repoLicense.data?.license?.spdx_id || null;
55+
} catch (error) {
56+
logwatch.warn(`Could not detect license SPDX ID: ${error.message}`);
57+
}
4358

4459
return {
4560
status: true,
4661
path: filePath,
4762
content: contentData,
48-
spdx_id: content.data?.license?.spdx_id || null,
63+
spdx_id: spdxId,
4964
};
5065
}
5166
}

ui/components.d.ts

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,25 +17,20 @@ declare module 'vue' {
1717
NCheckbox: typeof import('naive-ui')['NCheckbox']
1818
NCollapse: typeof import('naive-ui')['NCollapse']
1919
NCollapseItem: typeof import('naive-ui')['NCollapseItem']
20-
NCollapseTransition: typeof import('naive-ui')['NCollapseTransition']
21-
NDatePicker: typeof import('naive-ui')['NDatePicker']
2220
NDivider: typeof import('naive-ui')['NDivider']
2321
NDropdown: typeof import('naive-ui')['NDropdown']
24-
NDynamicInput: typeof import('naive-ui')['NDynamicInput']
2522
NEmpty: typeof import('naive-ui')['NEmpty']
2623
NFlex: typeof import('naive-ui')['NFlex']
2724
NForm: typeof import('naive-ui')['NForm']
2825
NFormItem: typeof import('naive-ui')['NFormItem']
2926
NImage: typeof import('naive-ui')['NImage']
3027
NInput: typeof import('naive-ui')['NInput']
3128
NModal: typeof import('naive-ui')['NModal']
32-
NPopconfirm: typeof import('naive-ui')['NPopconfirm']
3329
NPopover: typeof import('naive-ui')['NPopover']
3430
NRadio: typeof import('naive-ui')['NRadio']
3531
NRadioButton: typeof import('naive-ui')['NRadioButton']
3632
NRadioGroup: typeof import('naive-ui')['NRadioGroup']
3733
NSelect: typeof import('naive-ui')['NSelect']
38-
NSpace: typeof import('naive-ui')['NSpace']
3934
NSpin: typeof import('naive-ui')['NSpin']
4035
NSwitch: typeof import('naive-ui')['NSwitch']
4136
NTag: typeof import('naive-ui')['NTag']

0 commit comments

Comments
 (0)