Skip to content

Commit ab6d36f

Browse files
committed
fix: handle arrays that could be undefined
1 parent 5321bc1 commit ab6d36f

File tree

5 files changed

+30
-22
lines changed

5 files changed

+30
-22
lines changed

dist/index.js

+9-6
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/index.js.map

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/comment.ts

+10-7
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,17 @@ export const upsertComment = async (res: CheckReleaseResponse) => {
2222
const prNumber = context.payload.pull_request.number
2323
// Marker to find the comment to update.
2424
const startMarker = `<!--BYTEBASE_MARKER-PR_${prNumber}-DO_NOT_EDIT-->`
25-
const totalErrorAdviceCount = res.results.reduce(
25+
const totalErrorAdviceCount = (res.results ?? []).reduce(
2626
(acc, result) =>
27-
acc + result.advices.filter(advice => advice.status === 'ERROR').length,
27+
acc +
28+
(result.advices ?? []).filter(advice => advice.status === 'ERROR').length,
2829
0
2930
)
30-
const totalWarningAdviceCount = res.results.reduce(
31+
const totalWarningAdviceCount = (res.results ?? []).reduce(
3132
(acc, result) =>
32-
acc + result.advices.filter(advice => advice.status === 'WARNING').length,
33+
acc +
34+
(result.advices ?? []).filter(advice => advice.status === 'WARNING')
35+
.length,
3336
0
3437
)
3538
// Construct the comment message.
@@ -56,14 +59,14 @@ export const upsertComment = async (res: CheckReleaseResponse) => {
5659
</thead>
5760
<tbody>`
5861

59-
for (const result of res.results) {
62+
for (const result of res.results ?? []) {
6063
if (message.length > maxCommentLength - 1000) {
6164
break
6265
}
63-
const errorAdvicesCount = result.advices.filter(
66+
const errorAdvicesCount = (result.advices ?? []).filter(
6467
advice => advice.status === 'ERROR'
6568
).length
66-
const warningAdvicesCount = result.advices.filter(
69+
const warningAdvicesCount = (result.advices ?? []).filter(
6770
advice => advice.status === 'WARNING'
6871
).length
6972
core.debug(`result: ${JSON.stringify(result)}`)

src/main.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,7 @@ async function doCheckRelease(
284284
> = new Map()
285285
let hasError = false
286286
let hasWarning = false
287-
for (const result of checkReleaseResponse.results) {
287+
for (const result of checkReleaseResponse.results ?? []) {
288288
const file = result.file
289289
const target = result.target
290290
const advices = result.advices

src/type.ts

+9-7
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,15 @@ export interface httpClient {
77
}
88

99
export interface CheckReleaseResponse {
10-
results: {
11-
file: string
12-
target: string
13-
advices: any[]
14-
affectedRows: number
15-
riskLevel: string
16-
}[]
10+
results:
11+
| {
12+
file: string
13+
target: string
14+
advices: any[] | undefined
15+
affectedRows: number
16+
riskLevel: string
17+
}[]
18+
| undefined
1719
affectedRows: number
1820
riskLevel: string
1921
}

0 commit comments

Comments
 (0)