From 2b216a7e04f3325df7f710666d65619e12ee2a79 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andreas=20L=C3=BCdeke?= Date: Fri, 13 Dec 2024 11:45:24 +0100 Subject: [PATCH] storing releases inside the db --- .../migration.sql | 16 ++++++++++++++++ prisma/schema.prisma | 14 ++++++++++++++ src/routes/githubwebhook.ts | 18 ++++++++++++++++++ 3 files changed, 48 insertions(+) create mode 100644 prisma/migrations/20241213104042_create_release_model/migration.sql diff --git a/prisma/migrations/20241213104042_create_release_model/migration.sql b/prisma/migrations/20241213104042_create_release_model/migration.sql new file mode 100644 index 0000000..cb183d5 --- /dev/null +++ b/prisma/migrations/20241213104042_create_release_model/migration.sql @@ -0,0 +1,16 @@ +-- CreateTable +CREATE TABLE "Release" ( + "id" TEXT NOT NULL, + "name" TEXT NOT NULL, + "org" TEXT NOT NULL, + "repo" TEXT NOT NULL, + "repoUrl" TEXT NOT NULL, + "tag" TEXT NOT NULL, + "releaseUrl" TEXT NOT NULL, + "diffUrl" TEXT NOT NULL, + "publishedAt" TIMESTAMP(3) NOT NULL, + "authors" TEXT[], + "summary" TEXT NOT NULL, + + CONSTRAINT "Release_pkey" PRIMARY KEY ("id") +); diff --git a/prisma/schema.prisma b/prisma/schema.prisma index 0d2f9bc..6226d76 100644 --- a/prisma/schema.prisma +++ b/prisma/schema.prisma @@ -23,6 +23,20 @@ model Alert { updatedAt DateTime @updatedAt } +model Release { + id String @id @default(cuid()) + name String + org String + repo String + repoUrl String + tag String + releaseUrl String + diffUrl String + publishedAt DateTime + authors String[] + summary String +} + enum Source { custom checkly diff --git a/src/routes/githubwebhook.ts b/src/routes/githubwebhook.ts index 5284602..73d7323 100644 --- a/src/routes/githubwebhook.ts +++ b/src/routes/githubwebhook.ts @@ -1,3 +1,5 @@ +import { PrismaClient } from '@prisma/client'; + import crypto, { sign } from "crypto"; import express, { Request, Response, NextFunction } from "express"; import { @@ -11,6 +13,7 @@ import GitHubAPI from "../github/github"; import { GithubAgent } from "../github/agent"; import { createReleaseBlock, releaseHeader } from "../github/slackBlock"; import moment from "moment"; +import { prisma } from 'src/prisma'; const GH_WEBHOOK_SECRET = process.env.GH_WEBHOOK_SECRET || "your_secret"; @@ -108,6 +111,21 @@ router.post( summary: release.summary, }).blocks; + prisma.release.create({ + data: { + name: releaseName, + releaseUrl: releaseEvent.release.html_url, + publishedAt: releaseEvent.release.published_at, + org: releaseEvent.repository.owner.login, + repo: releaseEvent.repository.name, + repoUrl: releaseEvent.repository.html_url, + tag: releaseEvent.release.tag_name, + diffUrl: release.diff.html_url, + authors, + summary: release.summary, + } + }); + await app.client.chat.postMessage({ channel: process.env.SLACK_RELEASE_CHANNEL_ID as string, text: `New release: ${releaseEvent.release.name} in ${releaseEvent.repository.owner.login}/${releaseEvent.repository.name}`,