Skip to content

Commit

Permalink
Merge pull request #24 from checkly/release_model
Browse files Browse the repository at this point in the history
storing releases inside the db
  • Loading branch information
schobele authored Dec 13, 2024
2 parents 463b8f8 + 2b216a7 commit 4f9e118
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -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")
);
14 changes: 14 additions & 0 deletions prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
18 changes: 18 additions & 0 deletions src/routes/githubwebhook.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { PrismaClient } from '@prisma/client';

import crypto, { sign } from "crypto";
import express, { Request, Response, NextFunction } from "express";
import {
Expand All @@ -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";

Expand Down Expand Up @@ -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}`,
Expand Down

0 comments on commit 4f9e118

Please sign in to comment.