Skip to content

Commit 2e92f0b

Browse files
authored
add logic to store github labeled webhook event to DynamoDB (#6497)
only merge this after meta-pytorch/pytorch-gha-infra#646 has been merged & deployed Goal is to keep track of when issues are labeled or unlabeled for statistics purposes. Test plan: - added unit test to test double Dynamo update
1 parent 4f7eb22 commit 2e92f0b

File tree

3 files changed

+32
-4
lines changed

3 files changed

+32
-4
lines changed

torchci/lib/bot/webhookToDynamo.ts

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,16 +35,37 @@ async function handleWorkflowJob(
3535
}
3636

3737
async function handleIssues(event: Context<"issues">) {
38-
const key_prefix = event.payload.repository.full_name + "/";
3938
const client = getDynamoClient();
4039

40+
const issue_number = event.payload.issue.number;
41+
const repo_name = event.payload.repository.full_name;
42+
4143
await client.put({
4244
TableName: "torchci-issues",
4345
Item: {
44-
dynamoKey: `${key_prefix}${event.payload.issue.number}`,
46+
dynamoKey: `${repo_name}/${event.payload.issue.number}`,
4547
...event.payload.issue,
4648
},
4749
});
50+
51+
if (
52+
event.payload.action === "labeled" ||
53+
event.payload.action === "unlabeled"
54+
) {
55+
const datetime = event.payload.issue.updated_at;
56+
const label_name = event.payload.label?.name;
57+
await client.put({
58+
TableName: "torchci-issues-label-event",
59+
Item: {
60+
dynamoKey: `${repo_name}/${issue_number}-${label_name}`,
61+
repo_name: repo_name,
62+
issue_number: issue_number,
63+
event_time: datetime,
64+
label_name: label_name,
65+
action: event.payload.action,
66+
},
67+
});
68+
}
4869
}
4970

5071
async function handleIssueComment(event: Context<"issue_comment">) {
1.74 KB
Binary file not shown.

torchci/test/wehookToDynamoBot.test.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,12 @@ describe("webhookToDynamo tests", () => {
4646
* "workflow_job". This is the X-GitHub-Event header. Files that take the
4747
* form {"name": something, "id": something, "payload": something} should not
4848
* include this.
49+
* @param dynamo_call_count Number of times to call the dynamo client. Defaults to 1.
4950
*/
5051
async function helper(
5152
filename: string,
52-
name: string | undefined = undefined
53+
name: string | undefined = undefined,
54+
dynamo_call_count: number = 1
5355
) {
5456
const event = requireDeepCopy(filename);
5557
const mockedPut = jest.fn();
@@ -61,7 +63,7 @@ describe("webhookToDynamo tests", () => {
6163
} else {
6264
await probot.receive(event);
6365
}
64-
expect(mockedPut.mock.calls.length).toBe(1);
66+
expect(mockedPut.mock.calls.length).toBe(dynamo_call_count);
6567
const body = mockedPut.mock.calls[0];
6668
saveResult(filename, body);
6769
expect(body).toEqual(expectedResults[filename]);
@@ -94,4 +96,9 @@ describe("webhookToDynamo tests", () => {
9496
test("pull_request_comment", async () => {
9597
await helper("./fixtures/pull_request_comment.json");
9698
});
99+
100+
test("issue_labeled", async () => {
101+
// expecting 2 calls, one for updating the issue and one for the labeled event
102+
await helper("./fixtures/issues.labeled.json", "issues", 2);
103+
});
97104
});

0 commit comments

Comments
 (0)