Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 53 additions & 0 deletions packages/das/src/api/miners/miners.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,26 @@ const PR_SELECT_COLUMNS = `
'approved_count', COALESCE(rs.approved_count, 0),
'commented_count', COALESCE(rs.commented_count, 0)
) AS review_summary,
json_build_object(
'conversation_comment_count', COALESCE(pds.conversation_comment_count, 0),
'conversation_unique_authors', COALESCE(pds.conversation_unique_authors, 0),
'maintainer_conversation_comments', COALESCE(pds.maintainer_conversation_comments, 0),
'review_comment_count', COALESCE(prc.review_comment_count, 0),
'review_comment_unique_authors', COALESCE(prc.review_comment_unique_authors, 0),
'author_self_reply_share',
CASE WHEN COALESCE(pds.conversation_comment_count, 0) > 0
THEN ROUND(
(COALESCE(pds.author_self_reply_count, 0)::numeric
/ pds.conversation_comment_count),
4
)::float8
ELSE 0::float8
END,
'last_activity_at', GREATEST(
pds.last_conversation_comment_at,
prc.last_review_comment_at
)
) AS discussion_summary,
COALESCE((
SELECT json_agg(json_build_object(
'name', plt.label_name,
Expand Down Expand Up @@ -102,6 +122,21 @@ const ISSUE_SELECT_COLUMNS = `
i.last_edited_at,
i.is_transferred,
i.solved_by_pr,
json_build_object(
'conversation_comment_count', COALESCE(ids.conversation_comment_count, 0),
'conversation_unique_authors', COALESCE(ids.conversation_unique_authors, 0),
'maintainer_conversation_comments', COALESCE(ids.maintainer_conversation_comments, 0),
'author_self_reply_share',
CASE WHEN COALESCE(ids.conversation_comment_count, 0) > 0
THEN ROUND(
(COALESCE(ids.author_self_reply_count, 0)::numeric
/ ids.conversation_comment_count),
4
)::float8
ELSE 0::float8
END,
'last_activity_at', ids.last_conversation_comment_at
) AS discussion_summary,
COALESCE((
SELECT json_agg(json_build_object(
'name', ilt.label_name,
Expand Down Expand Up @@ -180,6 +215,12 @@ export class MinersService {
LEFT JOIN pr_review_summary rs
ON rs.repo_full_name = p.repo_full_name
AND rs.pr_number = p.pr_number
LEFT JOIN pr_discussion_summary pds
ON pds.repo_full_name = p.repo_full_name
AND pds.pr_number = p.pr_number
LEFT JOIN pr_review_comment_summary prc
ON prc.repo_full_name = p.repo_full_name
AND prc.pr_number = p.pr_number
LEFT JOIN repos r
ON r.repo_full_name = p.repo_full_name
WHERE p.author_github_id = $1
Expand Down Expand Up @@ -229,6 +270,12 @@ export class MinersService {
LEFT JOIN pr_review_summary rs
ON rs.repo_full_name = p.repo_full_name
AND rs.pr_number = p.pr_number
LEFT JOIN pr_discussion_summary pds
ON pds.repo_full_name = p.repo_full_name
AND pds.pr_number = p.pr_number
LEFT JOIN pr_review_comment_summary prc
ON prc.repo_full_name = p.repo_full_name
AND prc.pr_number = p.pr_number
LEFT JOIN repos r
ON r.repo_full_name = p.repo_full_name
WHERE p.author_github_id = $1
Expand Down Expand Up @@ -263,6 +310,9 @@ export class MinersService {
`
SELECT${ISSUE_SELECT_COLUMNS}
FROM issues i
LEFT JOIN issue_discussion_summary ids
ON ids.repo_full_name = i.repo_full_name
AND ids.issue_number = i.issue_number
WHERE i.author_github_id = $1
AND (
(i.state = 'OPEN' AND ($2::timestamptz IS NULL OR i.created_at >= $2))
Expand Down Expand Up @@ -306,6 +356,9 @@ export class MinersService {
FROM issues i
JOIN windows w
ON w.repo_full_name = LOWER(i.repo_full_name)
LEFT JOIN issue_discussion_summary ids
ON ids.repo_full_name = i.repo_full_name
AND ids.issue_number = i.issue_number
WHERE i.author_github_id = $1
AND (
(i.state = 'OPEN' AND i.created_at >= w.since)
Expand Down
25 changes: 25 additions & 0 deletions packages/db/26_view_pr_discussion_summary.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
-- Aggregates conversation-thread comment activity per PR.
-- Pairs with pr_review_comment_summary (inline review comments) to give the
-- miners API a single discussion_summary field per row. See #97.
-- Maintainer counts identify reviewer engagement vs. drive-by noise;
-- author_self_reply_count plus the conversation total lets consumers compute
-- an author-self-reply share without rejoining to pull_requests.

CREATE OR REPLACE VIEW pr_discussion_summary AS
SELECT
c.repo_full_name,
c.target_number AS pr_number,
COUNT(*) AS conversation_comment_count,
COUNT(DISTINCT c.author_github_id) AS conversation_unique_authors,
COUNT(*) FILTER (WHERE c.author_association IN ('OWNER','MEMBER','COLLABORATOR'))
AS maintainer_conversation_comments,
COUNT(*) FILTER (WHERE c.author_github_id IS NOT NULL
AND c.author_github_id = p.author_github_id)
AS author_self_reply_count,
MAX(c.created_at) AS last_conversation_comment_at
FROM comments c
LEFT JOIN pull_requests p
ON p.repo_full_name = c.repo_full_name
AND p.pr_number = c.target_number
WHERE c.comment_context = 'pr'
GROUP BY c.repo_full_name, c.target_number, p.author_github_id;
17 changes: 17 additions & 0 deletions packages/db/27_view_pr_review_comment_summary.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
-- Aggregates inline diff-review comments per PR. Distinct from
-- pr_discussion_summary (thread-level comments) and pr_review_summary
-- (review-state counts: APPROVED / CHANGES_REQUESTED / COMMENTED). See #97.
-- review_comments has no `reviewer_association` column, so maintainer-only
-- counts are not derivable here without a join to repo roles — kept out of
-- v1 to keep this view self-contained; reuse pr_review_summary's
-- maintainer_changes_requested_count for "did a maintainer engage" signal.

CREATE OR REPLACE VIEW pr_review_comment_summary AS
SELECT
repo_full_name,
pr_number,
COUNT(*) AS review_comment_count,
COUNT(DISTINCT reviewer_github_id) AS review_comment_unique_authors,
MAX(created_at) AS last_review_comment_at
FROM review_comments
GROUP BY repo_full_name, pr_number;
22 changes: 22 additions & 0 deletions packages/db/28_view_issue_discussion_summary.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
-- Aggregates conversation-thread comment activity per issue. Parallel to
-- pr_discussion_summary; issues have no inline review-comment surface so
-- there is no review_comment companion view here. See #97.

CREATE OR REPLACE VIEW issue_discussion_summary AS
SELECT
c.repo_full_name,
c.target_number AS issue_number,
COUNT(*) AS conversation_comment_count,
COUNT(DISTINCT c.author_github_id) AS conversation_unique_authors,
COUNT(*) FILTER (WHERE c.author_association IN ('OWNER','MEMBER','COLLABORATOR'))
AS maintainer_conversation_comments,
COUNT(*) FILTER (WHERE c.author_github_id IS NOT NULL
AND c.author_github_id = i.author_github_id)
AS author_self_reply_count,
MAX(c.created_at) AS last_conversation_comment_at
FROM comments c
LEFT JOIN issues i
ON i.repo_full_name = c.repo_full_name
AND i.issue_number = c.target_number
WHERE c.comment_context = 'issue'
GROUP BY c.repo_full_name, c.target_number, i.author_github_id;