Skip to content

Commit 9f4ff02

Browse files
authored
Handle closed pull requests and empty pull requests with no commit (#6108)
Fixes #6106. The issue is caused by an closed empty pull request with no commit pytorch/pytorch#143615. * Handle a PR with no commit in `fetchPR`. This function is used by Dr.CI to get all the commits in a pull request. * Make sure that Dr.CI only queries for open pull requests. * Fix the broken HUD PR page https://hud.pytorch.org/pr/143615 ### Testing Both ``` curl --request POST \ --url 'http://localhost:3000/api/drci/drci' \ --header 'Authorization: <REDACTED>' \ --data 'repo=pytorch' ``` and ``` curl --request POST \ --url 'http://localhost:3000/api/drci/drci?prNumber=143615' \ --header 'Authorization: <REDACTED>' \ --data 'repo=pytorch' ``` are working ok now. https://torchci-git-fork-huydhn-fix-drci-issue-6106-fbopensource.vercel.app/pr/143615 can be loaded now.
1 parent 46989f6 commit 9f4ff02

File tree

4 files changed

+28
-14
lines changed

4 files changed

+28
-14
lines changed

torchci/clickhouse_queries/recent_pr_workflows_query/query.sql

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ recent_prs AS (
3131
pull_request.base.'repo'.'full_name' = {repo: String}
3232
-- Filter pull request table to be smaller to amke query faster
3333
and pull_request.number in (select number from materialized_views.pr_by_sha where head_sha in (select head_sha from relevant_shas))
34+
-- This query is used by Dr.CI, so we just want to update open PR(s)
35+
and pull_request.state = 'open'
3436
)
3537
SELECT
3638
w.id AS workflowId,

torchci/lib/fetchPR.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,11 +47,13 @@ export default async function fetchPR(
4747

4848
// Ideally historicalCommits will be a superset of commits, but if there's a propagation delay with
4949
// getting the data to our database it may be missing recent commits for a bit.
50-
if (shas.length == 0) {
50+
if (shas.length === 0) {
5151
// If we got no data from our database, just use the commits from GitHub.
5252
shas = commits.map((commit) => {
5353
return { sha: commit.sha, title: commit.commit.message.split("\n")[0] };
5454
});
55+
} else if (commits.length === 0) {
56+
return { title, body, shas };
5557
} else {
5658
// For the very last sha, check to see if the shas themselves match as a proxy for detecting any missing commit.
5759
const lastCommit = commits[commits.length - 1];

torchci/pages/[repoOwner]/[repoName]/pull/[prNumber].tsx

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -120,8 +120,9 @@ function Page() {
120120

121121
useEffect(() => {
122122
const selected = (sha ??
123-
prData?.shas[prData.shas.length - 1].sha ??
124-
"") as string;
123+
(prData && prData.shas.length > 0
124+
? prData?.shas[prData.shas.length - 1].sha
125+
: "")) as string;
125126
setSelectedSha(selected);
126127
}, [prData?.shas, sha]);
127128

@@ -130,6 +131,7 @@ function Page() {
130131
if (prData === undefined) {
131132
return <div>Loading...</div>;
132133
}
134+
133135
return (
134136
<div>
135137
<Stack
@@ -156,18 +158,23 @@ function Page() {
156158
repo={repoName as string}
157159
/>
158160
</Stack>
159-
<CommitHeader
160-
repoOwner={repoOwner as string}
161-
repoName={repoName as string}
162-
prData={prData}
163-
selectedSha={selectedSha}
164-
/>
165-
<ErrorBoundary>
166-
<CommitInfo
161+
{selectedSha === "" && <div>Empty pull request without any commit</div>}
162+
{selectedSha !== "" && (
163+
<CommitHeader
167164
repoOwner={repoOwner as string}
168165
repoName={repoName as string}
169-
sha={selectedSha}
166+
prData={prData}
167+
selectedSha={selectedSha}
170168
/>
169+
)}
170+
<ErrorBoundary>
171+
{selectedSha !== "" && (
172+
<CommitInfo
173+
repoOwner={repoOwner as string}
174+
repoName={repoName as string}
175+
sha={selectedSha}
176+
/>
177+
)}
171178
</ErrorBoundary>
172179
</div>
173180
);

torchci/pages/api/drci/drci.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -305,14 +305,17 @@ function removeFailureContext(failure: {
305305
async function getPRsWithPendingJobInComment(repo: String): Promise<number[]> {
306306
const query = `
307307
select
308-
issue_url
308+
issue_comment.issue_url
309309
from
310310
default.issue_comment final
311+
join default.pull_request on issue_comment.issue_url = pull_request.issue_url
311312
where
312313
body like '<!-- drci-comment-start -->%'
313314
and match(body, '\\d Pending')
314315
and issue_comment.updated_at > now() - interval 1 month
315-
and issue_url like {repo: String}`;
316+
and issue_url like {repo: String }
317+
and pull_request.state = 'open'
318+
`;
316319
const results = await queryClickhouse(query, { repo: `%${repo}%` });
317320
return results.map((v) => parseInt(v.issue_url.split("/").pop()));
318321
}

0 commit comments

Comments
 (0)