Skip to content
Merged
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
30 changes: 18 additions & 12 deletions packages/das/src/api/miners/miners.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,13 @@ export class MinersService {
const rows = await this.dataSource.query(
`
SELECT
p.repo_full_name,
LOWER(p.repo_full_name) AS repo_full_name,
p.pr_number,
p.title,
COALESCE(p.title, '') AS title,
p.body,
p.state,
p.author_github_id,
p.author_login,
COALESCE(p.author_login, '') AS author_login,
p.author_association,
p.created_at,
p.closed_at,
Expand All @@ -35,14 +35,14 @@ export class MinersService {
p.merged_by_login,
p.base_ref,
p.head_ref,
p.head_repo_full_name,
LOWER(p.head_repo_full_name) AS head_repo_full_name,
r.default_branch,
p.head_sha,
p.base_sha,
p.merge_base_sha,
p.additions,
p.deletions,
p.commits_count,
COALESCE(p.additions, 0) AS additions,
COALESCE(p.deletions, 0) AS deletions,
COALESCE(p.commits_count, 0) AS commits_count,
p.scoring_data_stored,
(p.last_edited_at IS NOT NULL AND p.merged_at IS NOT NULL AND p.last_edited_at > p.merged_at)
AS edited_after_merge,
Expand Down Expand Up @@ -72,7 +72,7 @@ export class MinersService {
COALESCE((
SELECT json_agg(json_build_object(
'number', li.issue_number,
'title', li.issue_title,
'title', COALESCE(li.issue_title, ''),
'state', li.issue_state,
'state_reason', li.issue_state_reason,
'author_github_id', li.issue_author_github_id,
Expand Down Expand Up @@ -134,9 +134,9 @@ export class MinersService {
const rows = await this.dataSource.query(
`
SELECT
i.repo_full_name,
LOWER(i.repo_full_name) AS repo_full_name,
i.issue_number,
i.title,
COALESCE(i.title, '') AS title,
i.state,
i.state_reason,
i.author_github_id,
Expand Down Expand Up @@ -188,8 +188,10 @@ export class MinersService {
AND plt.pr_number = sp.pr_number
), '[]'::json),
'review_summary', json_build_object(
'maintainer_changes_requested_count',
COALESCE(rs.maintainer_changes_requested_count, 0)
'maintainer_changes_requested_count', COALESCE(rs.maintainer_changes_requested_count, 0),
'changes_requested_count', COALESCE(rs.changes_requested_count, 0),
'approved_count', COALESCE(rs.approved_count, 0),
'commented_count', COALESCE(rs.commented_count, 0)
)
)
FROM pull_requests sp
Expand All @@ -198,6 +200,10 @@ export class MinersService {
AND rs.pr_number = sp.pr_number
WHERE sp.repo_full_name = i.repo_full_name
AND sp.pr_number = i.solved_by_pr
-- Skip null-author solving PRs (no one to credit)
AND sp.author_github_id IS NOT NULL
-- Skip corrupted MERGED-without-merged_at shape
AND NOT (sp.state = 'MERGED' AND sp.merged_at IS NULL)
) AS solving_pr
FROM issues i
WHERE i.author_github_id = $1
Expand Down
11 changes: 8 additions & 3 deletions packages/das/src/api/pulls/pulls.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export class PullsService {
const rows = await this.dataSource.query(
`
SELECT
p.repo_full_name,
LOWER(p.repo_full_name) AS repo_full_name,
p.pr_number,
p.head_sha,
p.base_sha,
Expand Down Expand Up @@ -44,8 +44,13 @@ export class PullsService {
AND f.pr_number = p.pr_number
), '[]'::json) AS files
FROM pull_requests p
WHERE p.repo_full_name = $1
AND p.pr_number = $2
-- Look up the canonical-case repo_full_name via the small repos
-- table so the pull_requests PK seek stays index-driven
WHERE p.repo_full_name = (
SELECT repo_full_name FROM repos
WHERE LOWER(repo_full_name) = LOWER($1)
)
AND p.pr_number = $2
`,
[repoFullName, prNumber],
);
Expand Down
2 changes: 1 addition & 1 deletion packages/das/src/webhook/handlers/pull-request.handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export class PullRequestHandler {
authorLogin: pr.user.login,
authorAssociation: pr.author_association,
title: pr.title,
state: pr.merged ? "MERGED" : pr.state.toUpperCase(),
state: pr.merged && pr.merged_at ? "MERGED" : pr.state.toUpperCase(),
createdAt: pr.created_at,
closedAt: pr.closed_at ?? null,
mergedAt: pr.merged_at ?? null,
Expand Down
4 changes: 3 additions & 1 deletion packages/db/02_pull_requests.sql
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@ CREATE TABLE IF NOT EXISTS pull_requests (
closing_issue_numbers INTEGER[],
scoring_data_stored BOOLEAN NOT NULL DEFAULT FALSE,

PRIMARY KEY (repo_full_name, pr_number)
PRIMARY KEY (repo_full_name, pr_number),
CONSTRAINT pull_requests_merged_has_merged_at
CHECK (state != 'MERGED' OR merged_at IS NOT NULL)
);

CREATE INDEX IF NOT EXISTS idx_pull_requests_author ON pull_requests(author_github_id);
Expand Down
Loading