fix(languages/analyzer): TypeError on null committer#21
fix(languages/analyzer): TypeError on null committer#21ferferga wants to merge 1 commit intogh-metrics:masterfrom
Conversation
There was a problem hiding this comment.
Pull request overview
Fixes a crash in the languages “recently-used” analyzer when processing PushEvent commit entries that are undefined or have missing committer data.
Changes:
- Hardened PushEvent commit filtering to avoid destructuring
committerfrom anundefinedcommit. - Added an explicit guard for
commit.committer.emailbefore applying the authoring filter.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| commits | ||
| .flatMap(({payload}) => payload.commits) | ||
| .filter(({committer}) => filters.text(committer?.email, this.authoring, {debug: false})) | ||
| .filter(commit => commit?.committer?.email && filters.text(commit.committer.email, this.authoring, {debug: false})) |
There was a problem hiding this comment.
The new filter still uses filters.text(...), which returns true when the value is not in the patterns list. Given commits_authoring is documented/used elsewhere as the set of identifiers to match (e.g., code plugin filters commits where author matches an entry), this likely inverts the intent and can exclude the user’s own commits when commit.committer.email is present. Consider aligning with the other commit-authoring filters by treating commits_authoring as an inclusion match (or explicitly negating filters.text if you want exact-match semantics).
| .filter(commit => commit?.committer?.email && filters.text(commit.committer.email, this.authoring, {debug: false})) | |
| .filter(commit => commit?.committer?.email && !filters.text(commit.committer.email, this.authoring, {debug: false})) |
| commits | ||
| .flatMap(({payload}) => payload.commits) | ||
| .filter(({committer}) => filters.text(committer?.email, this.authoring, {debug: false})) | ||
| .filter(commit => commit?.committer?.email && filters.text(commit.committer.email, this.authoring, {debug: false})) |
There was a problem hiding this comment.
This fixes a runtime TypeError for malformed PushEvent commit entries, but there’s no automated coverage for the specific edge case (e.g., payload.commits containing undefined/null or commits missing committer). Since there is an existing languages plugin test case for the “recently-used” section, consider extending the GitHub activity mock to include such an entry so the regression is caught.
0d638c8 to
441b468
Compare
|
Are they really forcing copilot reviews on everybody these days? That sucks. This looks fine but there's like 20 equivalent PRs in the lowlighter repo and I want to attribute it correctly. |
|
Oops, kwoning it was unmaintained, I didn't even bother checking the original repo. I will leave the related PRs listed here for reference to future people coming across this thread, feel free to add more @lishaduck. I will also edit this comment if I find more |
Nah, you're good! I just keep directing people over there to file over here so I'd feel bad not giving them credit. |
db4a56e to
aaff3b5
Compare
Signed-off-by: Fernando Fernández <ferferga@hotmail.com>
aaff3b5 to
bcc79f0
Compare
|
@lishaduck Any news about this? |
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| //Compute changes | ||
| repos[handle] = {added: 0, deleted: 0, changed: 0} | ||
| const contributors = stats.filter(({author}) => (context.mode === "repository") || (context.mode === "organization") ? true : author?.login?.toLocaleLowerCase() === login.toLocaleLowerCase()) | ||
| const contributors = stats.filter(contributors => contributors && ((context.mode === "repository") || (context.mode === "organization") ? true : contributors.author?.login?.toLocaleLowerCase() === login.toLocaleLowerCase())) |
There was a problem hiding this comment.
The PR title/description focuses on the languages recent analyzer TypeError, but this PR also changes the lines plugin contributor filtering/logging. If this is intentional (same class of undefined entries), consider mentioning it in the PR description so reviewers understand the additional scope.
| //Compute changes | ||
| repos[handle] = {added: 0, deleted: 0, changed: 0} | ||
| const contributors = stats.filter(({author}) => (context.mode === "repository") || (context.mode === "organization") ? true : author?.login?.toLocaleLowerCase() === login.toLocaleLowerCase()) | ||
| const contributors = stats.filter(contributors => contributors && ((context.mode === "repository") || (context.mode === "organization") ? true : contributors.author?.login?.toLocaleLowerCase() === login.toLocaleLowerCase())) |
There was a problem hiding this comment.
The stats.filter(contributors => ...) callback parameter name (contributors) is plural and also very close to the outer contributors array constant, which makes this line harder to read and easier to mis-edit later. Rename the callback parameter to contributor (or similar) to avoid shadowing/confusion.
| const contributors = stats.filter(contributors => contributors && ((context.mode === "repository") || (context.mode === "organization") ? true : contributors.author?.login?.toLocaleLowerCase() === login.toLocaleLowerCase())) | |
| const contributors = stats.filter(contributor => contributor && ((context.mode === "repository") || (context.mode === "organization") ? true : contributor.author?.login?.toLocaleLowerCase() === login.toLocaleLowerCase())) |
Oh, yup. I've been really busy the last week or two, but I'll see if I can fit in the time to review this 👍🏻 |
First of all, thank you very much for trying to keep this project active.
In the old version (and in this one), I'm receiving this error at the rendering stage:
This pull request fixes the issue.