Skip to content

fix(habits): guard against null commit entries in PushEvent payload#1807

Open
Br1an67 wants to merge 4 commits intolowlighter:mainfrom
Br1an67:fix/habits-null-commit-author
Open

fix(habits): guard against null commit entries in PushEvent payload#1807
Br1an67 wants to merge 4 commits intolowlighter:mainfrom
Br1an67:fix/habits-null-commit-author

Conversation

@Br1an67
Copy link

@Br1an67 Br1an67 commented Mar 17, 2026

Problem

The habits plugin crashes with TypeError: Cannot destructure property 'author' of 'undefined' when processing PushEvent payloads that contain null/undefined commit entries.

This can happen when:

  • A commit author's account has been deleted
  • Commits were force-pushed and no longer exist
  • The GitHub API returns sparse commit arrays

Root Cause

In source/plugins/habits/index.mjs, the commit processing chain:

commits
  .flatMap(({payload}) => payload.commits)
  .filter(({author}) => ...)

payload.commits may contain null/undefined entries. The next .filter() immediately destructures {author} from each entry, which throws when the entry is undefined.

Fix

Add .filter(commit => commit) between the flatMap and the author filter to skip null/undefined entries before attempting destructuring.

Testing

Tested against a GitHub account with 788+ PRs across 152+ contributed repositories where this error was consistently reproducible.

ilanRosenbaum and others added 4 commits December 18, 2023 18:01
Some PushEvent payloads contain null/undefined commit entries (e.g. from
deleted users or force-pushed commits). The subsequent destructuring of
`{author}` throws TypeError when encountering these entries.

Add a filter to skip null/undefined commits before accessing their
properties.
Instead of building the entire Docker image from scratch (which fails
due to nokogiri compilation issues), extend the official pre-built
image and only COPY the patched habits plugin file.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants