Skip to content

Commit e2b1555

Browse files
committed
better handling of responses
1 parent 1c0ce39 commit e2b1555

File tree

2 files changed

+11
-6
lines changed

2 files changed

+11
-6
lines changed

build/index.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -112,29 +112,31 @@ server.tool("depscore", "Get the dependency score of packages with the `depscore
112112
}
113113
// Process each result
114114
for (const jsonData of jsonLines) {
115+
let purl = `pkg:${jsonData.type || 'unknown'}/${jsonData.name || 'unknown'}@${jsonData.version || 'unknown'}`;
115116
if (jsonData.score && jsonData.score.overall !== undefined) {
116117
const scoreEntries = Object.entries(jsonData.score)
117118
.filter(([key]) => key !== "overall" && key !== "uuid")
118119
.map(([key, value]) => `${key}: ${value}`)
119120
.join(', ');
120121
const packageName = jsonData.name || 'unknown';
121-
results.push(`${packageName}: ${scoreEntries}`);
122+
results.push(`${purl}: ${scoreEntries}`);
122123
}
123124
else {
124125
const packageName = jsonData.name || 'unknown';
125-
results.push(`${packageName}: No score found`);
126+
results.push(`${purl}: No score found`);
126127
}
127128
}
128129
}
129130
else {
130131
const jsonData = JSON.parse(responseText);
132+
let purl = `pkg:${jsonData.type || 'unknown'}/${jsonData.name || 'unknown'}@${jsonData.version || 'unknown'}`;
131133
if (jsonData.score && jsonData.score.overall !== undefined) {
132134
const scoreEntries = Object.entries(jsonData.score)
133135
.filter(([key]) => key !== "overall" && key !== "uuid")
134136
.map(([key, value]) => `${key}: ${value}`)
135137
.join(', ');
136138
const packageName = jsonData.package?.name || 'unknown';
137-
results.push(`${packageName}: ${scoreEntries}`);
139+
results.push(`${purl}: ${scoreEntries}`);
138140
}
139141
}
140142
return {

src/index.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -136,29 +136,32 @@ server.tool(
136136

137137
// Process each result
138138
for (const jsonData of jsonLines) {
139+
let purl: string = `pkg:${jsonData.type || 'unknown'}/${jsonData.name || 'unknown'}@${jsonData.version || 'unknown'}`;
139140
if (jsonData.score && jsonData.score.overall !== undefined) {
141+
140142
const scoreEntries = Object.entries(jsonData.score)
141143
.filter(([key]) => key !== "overall" && key !== "uuid")
142144
.map(([key, value]) => `${key}: ${value}`)
143145
.join(', ');
144146

145147
const packageName = jsonData.name || 'unknown';
146-
results.push(`${packageName}: ${scoreEntries}`);
148+
results.push(`${purl}: ${scoreEntries}`);
147149
} else {
148150
const packageName = jsonData.name || 'unknown';
149-
results.push(`${packageName}: No score found`);
151+
results.push(`${purl}: No score found`);
150152
}
151153
}
152154
} else {
153155
const jsonData = JSON.parse(responseText);
156+
let purl: string = `pkg:${jsonData.type || 'unknown'}/${jsonData.name || 'unknown'}@${jsonData.version || 'unknown'}`;
154157
if (jsonData.score && jsonData.score.overall !== undefined) {
155158
const scoreEntries = Object.entries(jsonData.score)
156159
.filter(([key]) => key !== "overall" && key !== "uuid")
157160
.map(([key, value]) => `${key}: ${value}`)
158161
.join(', ');
159162

160163
const packageName = jsonData.package?.name || 'unknown';
161-
results.push(`${packageName}: ${scoreEntries}`);
164+
results.push(`${purl}: ${scoreEntries}`);
162165
}
163166
}
164167

0 commit comments

Comments
 (0)