fix: repair dead discussion mentor-counting branch#776
Open
kaizeenn wants to merge 1 commit into
Open
Conversation
Three layered defects made `enable_mentor_count` a no-op (or crash) for discussions (reported in github-community-projects#774): 1. GraphQL fetched no comment author data discussions.py queried `comments(first: 1) { nodes { createdAt } }`, so each comment node had no author field. Expanded to `comments(first: 100)` with `author { login __typename }`, and added `author { login __typename }` to the discussion node itself so the opener's login is available for the self-comment filter. 2. Attribute access on dict nodes would AttributeError most_active_mentors.py used `comment.user.login`, `comment.submitted_at` etc. on plain GraphQL dicts. Replaced with `comment.get('author') or {}` dict access throughout. 3. Self-reference in ignore_comment The old code passed `comment.user` as both `issue_user` AND `comment_user`, so the 'same user' guard always fired and every comment was skipped. Replaced by threading `discussion['author']['login']` as the discussion-author login and comparing directly. Also moved the discussion block outside the `if issue:` guard so it runs when `issue=None` (the call-site in issue_metrics.py passes `issue=None, discussion=<dict>`). Added TestCountCommentsDiscussions with 7 cases: basic count, author self-comment ignored, bot ignored, ignore_users respected, multiple commenters, empty comments, null author (deleted account). Closes github-community-projects#774 Signed-off-by: kaizeenn <khairil0153@gmail.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Fixes #774.
Three layered defects made
enable_mentor_counta complete no-op (or a crash) for GitHub Discussions:1. GraphQL fetched no comment author data
discussions.pyqueriedcomments(first: 1) { nodes { createdAt } }— noauthorfield, and only 1 comment. Expanded tocomments(first: 100)withauthor { login __typename }on each comment node. Addedauthor { login __typename }to the discussion node itself so the opener's login is available for the self-comment filter.2. Attribute access on dict nodes would AttributeError
most_active_mentors.pyusedcomment.user.login,comment.submitted_at,comment.ready_for_review_aton plain GraphQL dicts. Replaced withcomment.get('author') or {}dict access throughout.3. Self-reference in
ignore_commentThe old code passed
comment.useras bothissue_userandcomment_user, so the guardcomment_user.login == issue_user.loginalways fired and every comment was skipped. Fixed by threadingdiscussion['author']['login']as the discussion-author login and comparing directly, without going throughignore_comment(which expects github3 objects, not dicts).Structural fix
Moved the discussion block outside the
if issue:guard so it actually runs when the call-site passesissue=None, discussion=<dict>(asissue_metrics.pydoes).Development notes
Changed files:
discussions.py,most_active_mentors.py,test_most_active_mentors.py.Added
TestCountCommentsDiscussionswith 7 cases:ignore_usersrespectedpytest test_most_active_mentors.py— 11 passed (4 baseline + 7 new). Commit signed off (DCO).