Skip to content

Commit 29d9cba

Browse files
committed
Fix habits plugin: handle undefined commits and missing author property
- Filter out null/undefined commits from payload.commits - Add safety check for missing author property - Prevents 'Cannot destructure property author of undefined' error
1 parent 960289c commit 29d9cba

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

source/plugins/habits/index.mjs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,13 @@ export default async function({login, data, rest, imports, q, account}, {enabled
4747
const patches = [
4848
...await Promise.allSettled(
4949
commits
50-
.flatMap(({payload}) => payload.commits)
51-
.filter(({author}) => data.shared["commits.authoring"].filter(authoring => author?.login?.toLocaleLowerCase().includes(authoring) || author?.email?.toLocaleLowerCase().includes(authoring) || author?.name?.toLocaleLowerCase().includes(authoring)).length)
50+
.flatMap(({payload}) => payload?.commits ?? [])
51+
.filter(commit => commit != null) // Filter out null/undefined commits
52+
.filter(({author}) => {
53+
// Handle missing author property
54+
if (!author) return false
55+
return data.shared["commits.authoring"].filter(authoring => author?.login?.toLocaleLowerCase().includes(authoring) || author?.email?.toLocaleLowerCase().includes(authoring) || author?.name?.toLocaleLowerCase().includes(authoring)).length
56+
})
5257
.map(async commit => (await rest.request(commit)).data.files),
5358
),
5459
]

0 commit comments

Comments
 (0)