Skip to content

Commit 2f934ef

Browse files
authored
[Refactor] Extract out a utility function: getFilesChangedByPr (#5100)
Two refactorings in this PR, setting the stage for a follow up: - Extract a method to get a list of files changed in the given PR - Sort all bots alphabetically (fixing an eyesore)
1 parent 2ad9e57 commit 2f934ef

File tree

3 files changed

+36
-21
lines changed

3 files changed

+36
-21
lines changed

torchci/lib/bot/autoLabelBot.ts

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import {
66
hasApprovedPullRuns,
77
hasWritePermissions,
88
isPyTorchPyTorch,
9+
getFilesChangedByPr,
910
} from "./utils";
1011
import { minimatch } from "minimatch";
1112
import {
@@ -388,16 +389,12 @@ function myBot(app: Probot): void {
388389
const owner = context.payload.repository.owner.login;
389390
const repo = context.payload.repository.name;
390391
const title = context.payload.pull_request.title;
391-
const filesChangedRes = await context.octokit.paginate(
392-
"GET /repos/{owner}/{repo}/pulls/{pull_number}/files",
393-
{
394-
owner,
395-
repo,
396-
pull_number: context.payload.pull_request.number,
397-
per_page: 100,
398-
}
392+
const filesChanged = await getFilesChangedByPr(
393+
context.octokit,
394+
owner,
395+
repo,
396+
context.payload.pull_request.number
399397
);
400-
const filesChanged = filesChangedRes.map((f: any) => f.filename);
401398
context.log({ labels, title, filesChanged });
402399

403400
var labelsToAdd = getLabelsToAddFromTitle(title);

torchci/lib/bot/index.ts

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,30 @@
11
import { Probot } from "probot";
22
import autoCcBot from "./autoCcBot";
33
import autoLabelBot from "./autoLabelBot";
4+
import cancelWorkflowsOnCloseBot from "./cancelWorkflowsOnCloseBot";
45
import ciflowPushTrigger from "./ciflowPushTrigger";
6+
import codevNoWritePerm from "./codevNoWritePermBot";
57
import drciBot from "./drciBot";
8+
import isTheBotStateful from "./statefulBot";
69
import pytorchBot from "./pytorchBot";
710
import retryBot from "./retryBot";
11+
import stripApprovalBot from "./stripApprovalBot";
812
import triggerCircleCIWorkflows from "./triggerCircleCIWorkflows";
913
import verifyDisableTestIssueBot from "./verifyDisableTestIssueBot";
1014
import webhookToDynamo from "./webhookToDynamo";
11-
import cancelWorkflowsOnCloseBot from "./cancelWorkflowsOnCloseBot";
12-
import stripApprovalBot from "./stripApprovalBot";
13-
import codevNoWritePerm from "./codevNoWritePermBot";
14-
import isTheBotStateful from "./statefulBot";
1515

1616
export default function bot(app: Probot) {
1717
autoCcBot(app);
18-
stripApprovalBot(app);
1918
autoLabelBot(app);
20-
verifyDisableTestIssueBot(app);
21-
ciflowPushTrigger(app);
22-
webhookToDynamo(app);
23-
triggerCircleCIWorkflows(app);
24-
pytorchBot(app);
25-
drciBot(app);
26-
retryBot(app);
2719
cancelWorkflowsOnCloseBot(app);
20+
ciflowPushTrigger(app);
2821
codevNoWritePerm(app);
22+
drciBot(app);
2923
isTheBotStateful(app);
24+
pytorchBot(app);
25+
retryBot(app);
26+
stripApprovalBot(app);
27+
triggerCircleCIWorkflows(app);
28+
verifyDisableTestIssueBot(app);
29+
webhookToDynamo(app);
3030
}

torchci/lib/bot/utils.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -266,3 +266,21 @@ export async function isFirstTimeContributor(
266266
});
267267
return commits?.data?.length === 0;
268268
}
269+
270+
export async function getFilesChangedByPr(
271+
octokit: Octokit,
272+
owner: string,
273+
repo: string,
274+
prNumber: number
275+
): Promise<string[]> {
276+
const filesChangedRes = await octokit.paginate(
277+
"GET /repos/{owner}/{repo}/pulls/{pull_number}/files",
278+
{
279+
owner,
280+
repo,
281+
pull_number: prNumber,
282+
per_page: 100,
283+
}
284+
);
285+
return filesChangedRes.map((f: any) => f.filename);
286+
}

0 commit comments

Comments
 (0)