Skip to content

Commit

Permalink
tc
Browse files Browse the repository at this point in the history
  • Loading branch information
clee2000 committed Nov 6, 2024
1 parent c0730af commit 9f72f68
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 34 deletions.
43 changes: 15 additions & 28 deletions torchci/lib/bot/webhookToDynamo.ts
Original file line number Diff line number Diff line change
@@ -1,35 +1,24 @@
import {
EmitterWebhookEvent as WebhookEvent,
EmitterWebhookEventName as WebhookEvents,
} from "@octokit/webhooks";
import { getDynamoClient } from "lib/dynamo";
import { Probot } from "probot";
import { Context, Probot } from "probot";
import { v4 as uuidv4 } from "uuid";

function narrowType<E extends WebhookEvents>(
event: E,
context: WebhookEvent
): context is WebhookEvent<E> {
return context.name === event;
}

async function handleWorkflowJob(
event: WebhookEvent<"workflow_run" | "workflow_job">
event: Context<"workflow_run" | "workflow_job">
) {
// Thre is the chance that job ids from different repos could collide. To
// prevent this, prefix the object key with the repo that they come from.
const key_prefix = event.payload.repository.full_name + "/";

let key;
let payload;
let table;
if (narrowType("workflow_job", event)) {
key = `${key_prefix}${event.payload.workflow_job.id}`;
payload = event.payload.workflow_job;
let payload;
if (event.name === "workflow_job") {
payload = (event as unknown as Context<"workflow_job">).payload.workflow_job;
key = `${key_prefix}${payload.id}`;
table = "torchci-workflow-job";
} else if (narrowType("workflow_run", event)) {
key = `${key_prefix}${event.payload.workflow_run.id}`;
payload = event.payload.workflow_run;
} else if (event.name === "workflow_run") {
payload = (event as unknown as Context<"workflow_run">).payload.workflow_run;
key = `${key_prefix}${payload.id}`;
table = "torchci-workflow-run";
}

Expand All @@ -43,7 +32,7 @@ async function handleWorkflowJob(
});
}

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

Expand All @@ -56,7 +45,7 @@ async function handleIssues(event: WebhookEvent<"issues">) {
});
}

async function handleIssueComment(event: WebhookEvent<"issue_comment">) {
async function handleIssueComment(event: Context<"issue_comment">) {
const key_prefix = event.payload.repository.full_name;
const client = getDynamoClient();

Expand All @@ -69,7 +58,7 @@ async function handleIssueComment(event: WebhookEvent<"issue_comment">) {
});
}

async function handlePullRequest(event: WebhookEvent<"pull_request">) {
async function handlePullRequest(event: Context<"pull_request">) {
const key_prefix = event.payload.repository.full_name + "/";
const client = getDynamoClient();

Expand All @@ -82,7 +71,7 @@ async function handlePullRequest(event: WebhookEvent<"pull_request">) {
});
}

async function handlePush(event: WebhookEvent<"push">) {
async function handlePush(event: Context<"push">) {
const key_prefix = event.payload.repository.full_name + "/";
const client = getDynamoClient();

Expand All @@ -95,9 +84,7 @@ async function handlePush(event: WebhookEvent<"push">) {
});
}

async function handlePullRequestReview(
event: WebhookEvent<"pull_request_review">
) {
async function handlePullRequestReview(event: Context<"pull_request_review">) {
const key_prefix = event.payload.repository.full_name;
const client = getDynamoClient();

Expand All @@ -111,7 +98,7 @@ async function handlePullRequestReview(
}

async function handlePullRequestReviewComment(
event: WebhookEvent<"pull_request_review_comment">
event: Context<"pull_request_review_comment">
) {
const key_prefix = event.payload.repository.full_name;
const client = getDynamoClient();
Expand Down
4 changes: 2 additions & 2 deletions torchci/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@
"@mui/material": "^5.14.1",
"@mui/x-data-grid": "^5.9.0",
"@mui/x-date-pickers": "^5.0.0-alpha.1",
"@octokit/webhooks": "^9.26.3",
"@octokit/webhooks-types": "^6.5.0",
"@octokit/webhooks": "^13.3.0",
"@octokit/webhooks-types": "^7.6.1",
"@opensearch-project/opensearch": "^2.3.1",
"@rockset/client": "^0.8.9",
"@types/minimist": "^1.2.2",
Expand Down
46 changes: 42 additions & 4 deletions torchci/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2362,6 +2362,16 @@
resolved "https://registry.npmjs.org/@octokit/openapi-types/-/openapi-types-16.0.0.tgz"
integrity sha512-JbFWOqTJVLHZSUUoF4FzAZKYtqdxWu9Z5m2QQnOyEa04fOFljvyh7D3GYKbfuaSWisqehImiVIMG4eyJeP5VEA==

"@octokit/openapi-types@^22.2.0":
version "22.2.0"
resolved "https://registry.yarnpkg.com/@octokit/openapi-types/-/openapi-types-22.2.0.tgz#75aa7dcd440821d99def6a60b5f014207ae4968e"
integrity sha512-QBhVjcUa9W7Wwhm6DBFu6ZZ+1/t/oYxqc2tp81Pi41YNuJinbFRx8B133qVOrAaBbF7D/m0Et6f9/pZt9Rc+tg==

"@octokit/[email protected]":
version "8.3.0"
resolved "https://registry.yarnpkg.com/@octokit/openapi-webhooks-types/-/openapi-webhooks-types-8.3.0.tgz#a7a4da00c0f27f7f5708eb3fcebefa08f8d51125"
integrity sha512-vKLsoR4xQxg4Z+6rU/F65ItTUz/EXbD+j/d4mlq2GW8TsA4Tc8Kdma2JTAAJ5hrKWUQzkR/Esn2fjsqiVRYaQg==

"@octokit/plugin-enterprise-compatibility@^1.2.8":
version "1.3.0"
resolved "https://registry.npmjs.org/@octokit/plugin-enterprise-compatibility/-/plugin-enterprise-compatibility-1.3.0.tgz"
Expand Down Expand Up @@ -2419,6 +2429,13 @@
deprecation "^2.0.0"
once "^1.4.0"

"@octokit/request-error@^6.0.1":
version "6.1.5"
resolved "https://registry.yarnpkg.com/@octokit/request-error/-/request-error-6.1.5.tgz#907099e341c4e6179db623a0328d678024f54653"
integrity sha512-IlBTfGX8Yn/oFPMwSfvugfncK2EwRLjzbrpifNaMY8o/HTEAFqCA1FZxjD9cWvSKBHgrIhc4CSBIzMxiLsbzFQ==
dependencies:
"@octokit/types" "^13.0.0"

"@octokit/request@^5.4.14", "@octokit/request@^5.6.0", "@octokit/request@^5.6.3":
version "5.6.3"
resolved "https://registry.npmjs.org/@octokit/request/-/request-5.6.3.tgz"
Expand All @@ -2443,6 +2460,13 @@
node-fetch "^2.6.7"
universal-user-agent "^6.0.0"

"@octokit/types@^13.0.0":
version "13.6.1"
resolved "https://registry.yarnpkg.com/@octokit/types/-/types-13.6.1.tgz#432fc6c0aaae54318e5b2d3e15c22ac97fc9b15f"
integrity sha512-PHZE9Z+kWXb23Ndik8MKPirBPziOc0D2/3KH1P+6jK5nGWe96kadZuE4jev2/Jq7FvIfTlT2Ltg8Fv2x1v0a5g==
dependencies:
"@octokit/openapi-types" "^22.2.0"

"@octokit/types@^6.0.1", "@octokit/types@^6.0.3", "@octokit/types@^6.1.1", "@octokit/types@^6.10.0", "@octokit/types@^6.12.2", "@octokit/types@^6.16.1", "@octokit/types@^6.27.1", "@octokit/types@^6.35.0", "@octokit/types@^6.39.0", "@octokit/types@^6.40.0":
version "6.41.0"
resolved "https://registry.npmjs.org/@octokit/types/-/types-6.41.0.tgz"
Expand Down Expand Up @@ -2476,15 +2500,29 @@
resolved "https://registry.npmjs.org/@octokit/webhooks-methods/-/webhooks-methods-2.0.0.tgz"
integrity sha512-35cfQ4YWlnZnmZKmIxlGPUPLtbkF8lr/A/1Sk1eC0ddLMwQN06dOuLc+dI3YLQS+T+MoNt3DIQ0NynwgKPilig==

"@octokit/webhooks-methods@^5.0.0":
version "5.1.0"
resolved "https://registry.yarnpkg.com/@octokit/webhooks-methods/-/webhooks-methods-5.1.0.tgz#13b6c08f89902c1ab0ddf31c6eeeec9c2772cfe6"
integrity sha512-yFZa3UH11VIxYnnoOYCVoJ3q4ChuSOk2IVBBQ0O3xtKX4x9bmKb/1t+Mxixv2iUhzMdOl1qeWJqEhouXXzB3rQ==

"@octokit/[email protected]":
version "5.8.0"
resolved "https://registry.npmjs.org/@octokit/webhooks-types/-/webhooks-types-5.8.0.tgz"
integrity sha512-8adktjIb76A7viIdayQSFuBEwOzwhDC+9yxZpKNHjfzrlostHCw0/N7JWpWMObfElwvJMk2fY2l1noENCk9wmw==

"@octokit/webhooks-types@^6.5.0":
version "6.5.0"
resolved "https://registry.npmjs.org/@octokit/webhooks-types/-/webhooks-types-6.5.0.tgz"
integrity sha512-SNx1YKBvi9IQvXo/SQ0p+9OKO2HMdzpCWcKsYxpGW1tlkE9TojYiGnFfxcXddyrsK4mC1UiyXY8+NYjWjtkVmA==
"@octokit/webhooks-types@^7.6.1":
version "7.6.1"
resolved "https://registry.yarnpkg.com/@octokit/webhooks-types/-/webhooks-types-7.6.1.tgz#bc96371057c2d54c982c9f8f642655b26cd588eb"
integrity sha512-S8u2cJzklBC0FgTwWVLaM8tMrDuDMVE4xiTK4EYXM9GntyvrdbSoxqDQa+Fh57CCNApyIpyeqPhhFEmHPfrXgw==

"@octokit/webhooks@^13.3.0":
version "13.3.0"
resolved "https://registry.yarnpkg.com/@octokit/webhooks/-/webhooks-13.3.0.tgz#fd5d54d47c789c75d60a00eb04e982152d7c654a"
integrity sha512-TUkJLtI163Bz5+JK0O+zDkQpn4gKwN+BovclUvCj6pI/6RXrFqQvUMRS2M+Rt8Rv0qR3wjoMoOPmpJKeOh0nBg==
dependencies:
"@octokit/openapi-webhooks-types" "8.3.0"
"@octokit/request-error" "^6.0.1"
"@octokit/webhooks-methods" "^5.0.0"

"@octokit/webhooks@^9.0.1", "@octokit/webhooks@^9.26.3":
version "9.26.3"
Expand Down

0 comments on commit 9f72f68

Please sign in to comment.