Skip to content

Comment / discussion aggregation in the miners API #97

@aliangm

Description

@aliangm

Summary

Add a discussion_summary field to the existing /api/v1/miners/:githubId/pulls and /issues responses, backed by new SQL views over comments and review_comments. Additive, no breaking changes.

Motivation

The mirror already ingests every conversation comment (packages/db/05_comments.sql) and every inline review comment (packages/db/06_review_comments.sql), but none of it reaches consumers. miners.service.ts:56-61 builds review_summary (approvals / changes_requested counts) and stops there. The issue response shape has no comment fields at all.

Consequence: scoring consumers can't tell a PR merged after substantive review apart from one merged with zero discussion, or an issue with active maintainer engagement from one nobody touched.

Proposed Solution

New view — packages/db/26_view_pr_discussion_summary.sql

CREATE OR REPLACE VIEW pr_discussion_summary AS
SELECT
    repo_full_name,
    target_number AS pr_number,
    COUNT(*)                                                                AS conversation_comment_count,
    COUNT(DISTINCT author_github_id)                                        AS conversation_unique_authors,
    COUNT(*) FILTER (WHERE author_association IN ('OWNER','MEMBER','COLLABORATOR'))
                                                                            AS maintainer_conversation_comments,
    MAX(created_at)                                                         AS last_conversation_comment_at
FROM comments
WHERE comment_context = 'pr'
GROUP BY repo_full_name, target_number;

Plus a parallel pr_review_comment_summary over review_comments, and an issue_discussion_summary over comments where comment_context = 'issue'.

Wire into the miner response

Add a discussion_summary field built with the same LEFT JOIN + json_build_object pattern already used for review_summary:

"discussion_summary": {
  "conversation_comment_count": 12,
  "conversation_unique_authors": 4,
  "maintainer_conversation_comments": 5,
  "review_comment_count": 8,
  "author_self_reply_share": 0.25,
  "last_activity_at": "2026-05-14T18:22:00Z"
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions