Skip to content

Commit c267d3a

Browse files
authored
[drci] add sev info to dr ci comment (#829)
Links to sev go to hud, which then redirect to back to github. This is because if I link the github issue directly, the PR would get mentioned in the sev, and even editing the comment to get rid of the link won't get rid of the mention * change rockset query to include body of issue to know if the sev is merge blocking * moves a mostly duplicate function `getDrciComment` from drciBot.ts and drci.ts to the drci bot utils file looks like ![image](https://user-images.githubusercontent.com/44682903/193171743-cf3a9cf6-4bb0-45d8-8501-521ae6a87cff.png)
1 parent b30d1f3 commit c267d3a

File tree

10 files changed

+225
-78
lines changed

10 files changed

+225
-78
lines changed

torchci/lib/bot/drciBot.ts

Lines changed: 7 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,7 @@
1-
import { Context, Probot } from "probot";
2-
import { DRCI_COMMENT_START, OWNER, REPO, formDrciComment } from "lib/drciUtils";
1+
import { Probot } from "probot";
2+
import { OWNER, REPO, formDrciComment, getDrciComment, getActiveSEVs, formDrciSevBody } from "lib/drciUtils";
3+
import fetchIssuesByLabel from "lib/fetchIssuesByLabel";
34

4-
async function getDrciComment(
5-
context: Context,
6-
owner: string,
7-
repo: string,
8-
prNum: number,
9-
): Promise<{ id: number; body: string }> {
10-
const commentsRes = await context.octokit.issues.listComments({
11-
owner: owner,
12-
repo: repo,
13-
issue_number: prNum,
14-
});
15-
for (const comment of commentsRes.data) {
16-
if (comment.body!.includes(DRCI_COMMENT_START)) {
17-
return { id: comment.id, body: comment.body! };
18-
}
19-
}
20-
return { id: 0, body: "" };
21-
}
225

236
export default function drciBot(app: Probot): void {
247
app.on(
@@ -45,14 +28,15 @@ export default function drciBot(app: Probot): void {
4528
context.log(prOwner);
4629

4730
const existingDrciData = await getDrciComment(
48-
context,
31+
context.octokit,
4932
owner,
5033
repo,
51-
prNum,
34+
prNum
5235
);
5336
const existingDrciID = existingDrciData.id;
5437
const existingDrciComment = existingDrciData.body;
55-
const drciComment = formDrciComment(prNum);
38+
const sev = getActiveSEVs(await fetchIssuesByLabel("ci: sev"));
39+
const drciComment = formDrciComment(prNum, "", formDrciSevBody(sev));
5640

5741
if (existingDrciComment === drciComment) {
5842
return;

torchci/lib/drciUtils.ts

Lines changed: 78 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
import _ from "lodash";
2+
import { Octokit } from "octokit";
3+
import { IssueData } from "./types";
4+
15
export const NUM_MINUTES = 15;
26
export const REPO: string = "pytorch";
37
export const OWNER: string = "pytorch";
@@ -24,14 +28,82 @@ Note: Links to docs will display an error until the docs builds have been comple
2428
}
2529

2630
export function formDrciComment(
27-
pr_num: number,
28-
pr_results: string = "",
31+
pr_num: number,
32+
pr_results: string = "",
33+
sevs: string = ""
2934
): string {
30-
const header = formDrciHeader(pr_num);
31-
const comment =
32-
`${DRCI_COMMENT_START}
35+
const header = formDrciHeader(pr_num);
36+
const comment = `${DRCI_COMMENT_START}
3337
${header}
38+
${sevs}
3439
${pr_results}
3540
${DRCI_COMMENT_END}`;
36-
return comment;
41+
return comment;
42+
}
43+
44+
45+
export async function getDrciComment(
46+
octokit: Octokit,
47+
owner: string,
48+
repo: string,
49+
prNum: number
50+
): Promise<{ id: number; body: string }> {
51+
const commentsRes = await octokit.rest.issues.listComments({
52+
owner: owner,
53+
repo: repo,
54+
issue_number: prNum,
55+
});
56+
for (const comment of commentsRes.data) {
57+
if (comment.body!.includes(DRCI_COMMENT_START)) {
58+
return { id: comment.id, body: comment.body! };
59+
}
60+
}
61+
return { id: 0, body: "" };
62+
}
63+
64+
export function getActiveSEVs(issues: IssueData[]): [IssueData[], IssueData[]] {
65+
const activeSEVs = issues.filter(
66+
(issue: IssueData) => issue.state === "open"
67+
);
68+
return _.partition(activeSEVs, (issue: IssueData) =>
69+
issue.body.toLowerCase().includes("merge blocking")
70+
);
71+
}
72+
73+
export function formDrciSevBody(sevs: [IssueData[], IssueData[]]): string {
74+
const [mergeBlocking, notMergeBlocking] = sevs;
75+
if (mergeBlocking.length + notMergeBlocking.length === 0) {
76+
return "";
77+
}
78+
const sev_list = mergeBlocking
79+
.concat(notMergeBlocking)
80+
.map(
81+
(issue: IssueData) =>
82+
`* ${
83+
issue.body.toLowerCase().includes("merge blocking")
84+
? "(merge blocking) "
85+
: ""
86+
}[${issue.title}](${issue.html_url.replace(
87+
"github.com",
88+
"hud.pytorch.org"
89+
)})`
90+
)
91+
.join("\n");
92+
if (mergeBlocking.length > 0) {
93+
return (
94+
`## :heavy_exclamation_mark: ${mergeBlocking.length} Merge Blocking SEVs
95+
There is ${mergeBlocking.length} active merge blocking SEVs` +
96+
(notMergeBlocking.length > 0
97+
? ` and ${notMergeBlocking.length} non merge blocking SEVs`
98+
: "") +
99+
`. Please view them below:
100+
${sev_list}\n
101+
If you must merge, use \`@pytorchbot merge -f\`.`
102+
);
103+
} else {
104+
return `## :heavy_exclamation_mark: ${notMergeBlocking.length} Active SEVs
105+
There are ${notMergeBlocking.length} currently active SEVs. If your PR is affected, please view them below:
106+
${sev_list}\n
107+
`;
108+
}
37109
}

torchci/lib/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ export interface IssueData {
6262
title: string;
6363
html_url: string;
6464
state: "open" | "closed";
65+
body: string;
6566
}
6667

6768
export interface HudParams {
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import { useRouter } from "next/router";
2+
import React from "react";
3+
4+
export default function Page() {
5+
const router = useRouter();
6+
const { repoOwner, repoName, issueNumber } = router.query;
7+
if (repoOwner && repoName && issueNumber) {
8+
const githubLink = `https://github.com/${repoOwner}/${repoName}/issues/${issueNumber}`;
9+
window.location.replace(githubLink);
10+
return <div>Redirecting to <a href={githubLink}>github</a></div>;
11+
}
12+
}

torchci/pages/api/drci/drci.ts

Lines changed: 14 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,17 @@
11
import type { NextApiRequest, NextApiResponse } from "next";
22
import { getOctokit } from "lib/github";
3-
import { Octokit } from "octokit";
43
import fetchRecentWorkflows from "lib/fetchRecentWorkflows";
54
import { RecentWorkflowsData } from "lib/types";
6-
import { NUM_MINUTES, REPO, DRCI_COMMENT_END, formDrciComment, OWNER } from "lib/drciUtils";
5+
import {
6+
NUM_MINUTES,
7+
REPO,
8+
formDrciComment,
9+
OWNER,
10+
getDrciComment,
11+
getActiveSEVs,
12+
formDrciSevBody,
13+
} from "lib/drciUtils";
14+
import fetchIssuesByLabel from "lib/fetchIssuesByLabel";
715

816
interface PRandJobs {
917
head_sha: string;
@@ -30,12 +38,13 @@ export async function updateDrciComments() {
3038
);
3139

3240
const workflowsByPR = reorganizeWorkflows(recentWorkflows);
41+
const sevs = getActiveSEVs(await fetchIssuesByLabel("ci: sev"));
3342

3443
for (const [pr_number, pr_info] of workflowsByPR) {
3544
const { pending, failedJobs } = getWorkflowJobsStatuses(pr_info);
3645

3746
const failureInfo = constructResultsComment(pending, failedJobs, pr_info.head_sha);
38-
const comment = formDrciComment(pr_number, failureInfo);
47+
const comment = formDrciComment(pr_number, failureInfo, formDrciSevBody(sevs));
3948

4049
await updateCommentWithWorkflow(pr_info, comment);
4150
}
@@ -122,14 +131,9 @@ export async function updateCommentWithWorkflow(
122131
pr_info: PRandJobs,
123132
comment: string,
124133
): Promise<void> {
125-
const { pr_number, owner_login } = pr_info;
134+
const { pr_number } = pr_info;
126135
const octokit = await getOctokit(OWNER, REPO);
127-
const { id, body } = await getDrciComment(
128-
pr_number!,
129-
OWNER,
130-
REPO,
131-
octokit
132-
);
136+
const { id, body } = await getDrciComment(octokit, OWNER, REPO, pr_number!);
133137

134138
if (id === 0 || body === comment) {
135139
return;
@@ -142,22 +146,3 @@ export async function updateCommentWithWorkflow(
142146
comment_id: id,
143147
});
144148
}
145-
146-
async function getDrciComment(
147-
prNum: number,
148-
owner: string,
149-
repo: string,
150-
octokit: Octokit
151-
): Promise<{ id: number; body: string }> {
152-
const commentsRes = await octokit.rest.issues.listComments({
153-
owner,
154-
repo,
155-
issue_number: prNum,
156-
});
157-
for (const comment of commentsRes.data) {
158-
if (comment.body!.includes(DRCI_COMMENT_END)) {
159-
return { id: comment.id, body: comment.body! };
160-
}
161-
}
162-
return { id: 0, body: "" };
163-
}

torchci/rockset/commons/__sql/issue_query.sql

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,9 @@ SELECT
33
issue.title,
44
issue.html_url,
55
issue.state,
6+
issue.body
67
from
78
issues as issue
89
cross join UNNEST(issue.labels as label) as labels
910
where
10-
labels.label.name = :label
11+
labels.label.name = :label

torchci/rockset/prodVersions.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"slow_tests": "ef8d035d23aa8ab6",
77
"test_time_per_file": "50cb3694334ed63a",
88
"test_time_per_file_periodic_jobs": "39c105542e297c09",
9-
"issue_query": "f29a1afe94563601",
9+
"issue_query": "5d4dfeb992e2f29b",
1010
"failure_samples_query": "ab2b589414b966a8",
1111
"recent_pr_workflows_query": "4e03cb13e8372050",
1212
"reverted_prs_with_reason": "bf2b0607bddcc552",

torchci/test/disableFlakyBot.test.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,7 @@ describe("Disable Flaky Test Bot Integration Tests", () => {
145145
title: "DISABLED test_a (__main__.suite_a)",
146146
html_url: "https://api.github.com/repos/pytorch/pytorch/issues/1",
147147
state: "open" as "open" | "closed",
148+
body: "random"
148149
},
149150
];
150151

@@ -179,6 +180,7 @@ describe("Disable Flaky Test Bot Integration Tests", () => {
179180
title: "DISABLED test_a (__main__.suite_a)",
180181
html_url: "https://api.github.com/pytorch/pytorch/issues/1",
181182
state: "closed" as "open" | "closed",
183+
body: "random"
182184
},
183185
];
184186

0 commit comments

Comments
 (0)