Fix bugs in scorecard
This commit is contained in:
+11
-2
@@ -1001,13 +1001,21 @@ const packageurl_js_1 = __nccwpck_require__(8915);
|
|||||||
const core = __importStar(__nccwpck_require__(2186));
|
const core = __importStar(__nccwpck_require__(2186));
|
||||||
function getScorecardLevels(changes) {
|
function getScorecardLevels(changes) {
|
||||||
return __awaiter(this, void 0, void 0, function* () {
|
return __awaiter(this, void 0, void 0, function* () {
|
||||||
|
const data = { dependencies: [] };
|
||||||
for (const change of changes) {
|
for (const change of changes) {
|
||||||
const purl = packageurl_js_1.PackageURL.fromString(change.package_url);
|
const purl = packageurl_js_1.PackageURL.fromString(change.package_url);
|
||||||
const ecosystem = purl.type;
|
const ecosystem = purl.type;
|
||||||
const packageName = purl.name;
|
const packageName = purl.name;
|
||||||
const version = purl.version;
|
const version = purl.version;
|
||||||
return getDepsDevData(ecosystem, packageName, String(version));
|
data.dependencies.push({
|
||||||
|
purl: purl,
|
||||||
|
ecosystem: ecosystem,
|
||||||
|
packageName: packageName,
|
||||||
|
version: version,
|
||||||
|
depsDevData: yield getDepsDevData(ecosystem, packageName, version)
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
return data;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
exports.getScorecardLevels = getScorecardLevels;
|
exports.getScorecardLevels = getScorecardLevels;
|
||||||
@@ -1022,7 +1030,7 @@ function getDepsDevData(ecosystem, packageName, version) {
|
|||||||
const data = yield response.json();
|
const data = yield response.json();
|
||||||
const projects = data.relatedProjects;
|
const projects = data.relatedProjects;
|
||||||
for (const project of projects) {
|
for (const project of projects) {
|
||||||
return getDepsDevProjectData(project.projectKey);
|
return yield getDepsDevProjectData(project.projectKey);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
@@ -1032,6 +1040,7 @@ function getDepsDevData(ecosystem, packageName, version) {
|
|||||||
catch (error) {
|
catch (error) {
|
||||||
core.error(`Error fetching data: ${error.message}`);
|
core.error(`Error fetching data: ${error.message}`);
|
||||||
}
|
}
|
||||||
|
return {};
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
function getDepsDevProjectData(projectKey) {
|
function getDepsDevProjectData(projectKey) {
|
||||||
|
|||||||
+1
-1
File diff suppressed because one or more lines are too long
+15
-5
@@ -3,14 +3,23 @@ import {isSPDXValid, octokitClient} from './utils'
|
|||||||
import {PackageURL} from 'packageurl-js'
|
import {PackageURL} from 'packageurl-js'
|
||||||
import * as core from '@actions/core'
|
import * as core from '@actions/core'
|
||||||
|
|
||||||
export async function getScorecardLevels(changes: Change[]): Promise<any> {
|
export async function getScorecardLevels(changes: Change[]): Promise<object> {
|
||||||
|
const data: any = {dependencies: []}
|
||||||
for (const change of changes) {
|
for (const change of changes) {
|
||||||
const purl = PackageURL.fromString(change.package_url)
|
const purl = PackageURL.fromString(change.package_url)
|
||||||
const ecosystem = purl.type
|
const ecosystem = purl.type
|
||||||
const packageName = purl.name
|
const packageName = purl.name
|
||||||
const version = purl.version
|
const version = purl.version
|
||||||
return getDepsDevData(ecosystem, packageName, String(version))
|
|
||||||
|
data.dependencies.push({
|
||||||
|
purl: purl,
|
||||||
|
ecosystem: ecosystem,
|
||||||
|
packageName: packageName,
|
||||||
|
version: version,
|
||||||
|
depsDevData: await getDepsDevData(ecosystem, packageName, version)
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
return data;
|
||||||
}
|
}
|
||||||
|
|
||||||
const depsDevAPIRoot = 'https://api.deps.dev'
|
const depsDevAPIRoot = 'https://api.deps.dev'
|
||||||
@@ -18,8 +27,8 @@ const depsDevAPIRoot = 'https://api.deps.dev'
|
|||||||
async function getDepsDevData(
|
async function getDepsDevData(
|
||||||
ecosystem: String,
|
ecosystem: String,
|
||||||
packageName: String,
|
packageName: String,
|
||||||
version: String
|
version: any
|
||||||
): Promise<any> {
|
): Promise<object> {
|
||||||
try {
|
try {
|
||||||
core.debug(`Getting deps.dev data for ${packageName} ${version}`)
|
core.debug(`Getting deps.dev data for ${packageName} ${version}`)
|
||||||
const url = `${depsDevAPIRoot}//v3alpha/systems/${ecosystem}/packages/${packageName}/versions/${version}`
|
const url = `${depsDevAPIRoot}//v3alpha/systems/${ecosystem}/packages/${packageName}/versions/${version}`
|
||||||
@@ -28,7 +37,7 @@ async function getDepsDevData(
|
|||||||
const data = await response.json()
|
const data = await response.json()
|
||||||
const projects = data.relatedProjects
|
const projects = data.relatedProjects
|
||||||
for (const project of projects) {
|
for (const project of projects) {
|
||||||
return getDepsDevProjectData(project.projectKey)
|
return await getDepsDevProjectData(project.projectKey)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
throw new Error(`Failed to fetch data with status code: ${response.status}`)
|
throw new Error(`Failed to fetch data with status code: ${response.status}`)
|
||||||
@@ -36,6 +45,7 @@ async function getDepsDevData(
|
|||||||
} catch (error: any) {
|
} catch (error: any) {
|
||||||
core.error(`Error fetching data: ${error.message}`)
|
core.error(`Error fetching data: ${error.message}`)
|
||||||
}
|
}
|
||||||
|
return {}
|
||||||
}
|
}
|
||||||
|
|
||||||
async function getDepsDevProjectData(
|
async function getDepsDevProjectData(
|
||||||
|
|||||||
Reference in New Issue
Block a user