Skip to content

fix: repair dead discussion mentor-counting branch#776

Open
kaizeenn wants to merge 1 commit into
github-community-projects:mainfrom
kaizeenn:fix/774-discussion-mentor-counting
Open

fix: repair dead discussion mentor-counting branch#776
kaizeenn wants to merge 1 commit into
github-community-projects:mainfrom
kaizeenn:fix/774-discussion-mentor-counting

Conversation

@kaizeenn

Copy link
Copy Markdown

Description

Fixes #774.

Three layered defects made enable_mentor_count a complete no-op (or a crash) for GitHub Discussions:

1. GraphQL fetched no comment author data

discussions.py queried comments(first: 1) { nodes { createdAt } } — no author field, and only 1 comment. Expanded to comments(first: 100) with author { login __typename } on each comment node. 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, comment.ready_for_review_at 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 guard comment_user.login == issue_user.login always fired and every comment was skipped. Fixed by threading discussion['author']['login'] as the discussion-author login and comparing directly, without going through ignore_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 passes issue=None, discussion=<dict> (as issue_metrics.py does).

Development notes

Changed files: discussions.py, most_active_mentors.py, test_most_active_mentors.py.

Added TestCountCommentsDiscussions with 7 cases:

  • basic count
  • author self-comment is ignored
  • bot commenter is ignored
  • ignore_users respected
  • multiple distinct commenters
  • empty comments list
  • null author (deleted account) handled gracefully

pytest test_most_active_mentors.py11 passed (4 baseline + 7 new). Commit signed off (DCO).

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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Discussion mentor counting is dead code (GraphQL + ignore_comment self-reference + dict-vs-object mismatch)

1 participant