From 9f72f6822402bf7968ec092bb729b86f22cc38c2 Mon Sep 17 00:00:00 2001 From: Catherine Lee Date: Mon, 28 Oct 2024 15:00:40 -0700 Subject: [PATCH] tc --- torchci/lib/bot/webhookToDynamo.ts | 43 ++++++++++------------------ torchci/package.json | 4 +-- torchci/yarn.lock | 46 +++++++++++++++++++++++++++--- 3 files changed, 59 insertions(+), 34 deletions(-) diff --git a/torchci/lib/bot/webhookToDynamo.ts b/torchci/lib/bot/webhookToDynamo.ts index d2f8e7e5fb..d17f7b338e 100644 --- a/torchci/lib/bot/webhookToDynamo.ts +++ b/torchci/lib/bot/webhookToDynamo.ts @@ -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( - event: E, - context: WebhookEvent -): context is WebhookEvent { - 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"; } @@ -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(); @@ -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(); @@ -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(); @@ -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(); @@ -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(); @@ -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(); diff --git a/torchci/package.json b/torchci/package.json index 54ef9f3289..ed6d10e785 100644 --- a/torchci/package.json +++ b/torchci/package.json @@ -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", diff --git a/torchci/yarn.lock b/torchci/yarn.lock index b46d03398e..4114fa664d 100644 --- a/torchci/yarn.lock +++ b/torchci/yarn.lock @@ -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/openapi-webhooks-types@8.3.0": + 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" @@ -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" @@ -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" @@ -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/webhooks-types@5.8.0": 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"