Skip to content

fix(habits): add null check for commit author property#1778

Closed
calilkhalil wants to merge 2 commits intolowlighter:masterfrom
calilkhalil:fix-habits-author-undefined
Closed

fix(habits): add null check for commit author property#1778
calilkhalil wants to merge 2 commits intolowlighter:masterfrom
calilkhalil:fix-habits-author-undefined

Conversation

@calilkhalil
Copy link
Copy Markdown

Description

This PR fixes a TypeError that occurs when the GitHub API returns events with commits that don't have an author property defined.

Problem

The habits plugin crashes with the following error:

TypeError: Cannot destructure property 'author' of 'undefined' as it is undefined.
    at file:///metrics/source/plugins/habits/index.mjs:51:21
    at Array.filter (<anonymous>)

This happens because some commits returned by the GitHub Events API don't have the author property (e.g., commits from deleted users, bots, or malformed API responses).

Solution

Added a null check before accessing the author property in the filter callback:

// Before
.filter(({author}) => data.shared["commits.authoring"].filter(...).length)

// After
.filter(commit => commit?.author && data.shared["commits.authoring"].filter(...).length)

Testing

  • Tested with a GitHub profile that was previously failing with this error
  • The habits plugin now works correctly and gracefully skips commits without author data

Related Issues

Fixes users experiencing "Cannot destructure property 'author' of 'undefined'" errors when using the habits plugin.

Fixes TypeError when GitHub API returns commits without author data.
Some events (from bots, deleted users, or malformed API responses)
don't have the author property defined, causing the destructuring
to fail with 'Cannot destructure property author of undefined'.
@calilkhalil
Copy link
Copy Markdown
Author

Duplicated

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant