Skip to content

Commit cef342e

Browse files
authored
add Render API types (#3)
1 parent 5111232 commit cef342e

File tree

2 files changed

+55
-17
lines changed

2 files changed

+55
-17
lines changed

app.ts

Lines changed: 7 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import express, {NextFunction, Request, Response} from "express";
22
import {Webhook, WebhookUnbrandedRequiredHeaders, WebhookVerificationError} from "standardwebhooks"
3+
import {RenderDeploy, RenderEvent, RenderKeyValue, RenderPostgres, RenderService, WebhookPayload} from "./render";
34

45
const app = express();
56
const port = process.env.PORT || 3001;
@@ -10,17 +11,6 @@ const renderAPIURL = process.env.RENDER_API_URL || "https://api.render.com/v1"
1011
// To create a Render API token, follow instructions here: https://render.com/docs/api#1-create-an-api-key
1112
const renderAPIToken = process.env.RENDER_API_TOKEN || '';
1213

13-
interface WebhookData {
14-
id: string
15-
serviceId: string
16-
}
17-
18-
interface WebhookPayload {
19-
type: string
20-
timestamp: Date
21-
data: WebhookData
22-
}
23-
2414
app.post("/webhook", express.raw({type: 'application/json'}), (req: Request, res: Response, next: NextFunction) => {
2515
try {
2616
validateWebhook(req);
@@ -68,7 +58,7 @@ async function handleWebhook(payload: WebhookPayload) {
6858

6959
if (deploy.commit) {
7060
console.log(`deploy started for service ${service.name} with commit "${deploy.commit.message}"`)
71-
} else {
61+
} else if (deploy.image) {
7262
console.log(`deploy started for service ${service.name} with image sha "${deploy.image.sha}"`)
7363
}
7464
return
@@ -91,7 +81,7 @@ async function handleWebhook(payload: WebhookPayload) {
9181
// fetchEventInfo fetches the event that triggered the webhook
9282
// some events have additional information that isn't in the webhook payload
9383
// for example, deploy events have the deploy id
94-
async function fetchEventInfo(payload: WebhookPayload) {
84+
async function fetchEventInfo(payload: WebhookPayload): Promise<RenderEvent> {
9585
const res = await fetch(
9686
`${renderAPIURL}/events/${payload.data.id}`,
9787
{
@@ -110,7 +100,7 @@ async function fetchEventInfo(payload: WebhookPayload) {
110100
}
111101
}
112102

113-
async function fetchDeployInfo(serviceId: string, deployId: string) {
103+
async function fetchDeployInfo(serviceId: string, deployId: string): Promise<RenderDeploy> {
114104
const res = await fetch(
115105
`${renderAPIURL}/services/${serviceId}/deploys/${deployId}`,
116106
{
@@ -129,7 +119,7 @@ async function fetchDeployInfo(serviceId: string, deployId: string) {
129119
}
130120
}
131121

132-
async function fetchServiceInfo(payload: WebhookPayload) {
122+
async function fetchServiceInfo(payload: WebhookPayload): Promise<RenderService> {
133123
const res = await fetch(
134124
`${renderAPIURL}/services/${payload.data.serviceId}`,
135125
{
@@ -149,7 +139,7 @@ async function fetchServiceInfo(payload: WebhookPayload) {
149139
}
150140

151141

152-
async function fetchPostgresInfo(payload: WebhookPayload) {
142+
async function fetchPostgresInfo(payload: WebhookPayload): Promise<RenderPostgres> {
153143
const res = await fetch(
154144
`${renderAPIURL}/postgres/${payload.data.serviceId}`,
155145
{
@@ -169,7 +159,7 @@ async function fetchPostgresInfo(payload: WebhookPayload) {
169159
}
170160

171161

172-
async function fetchKeyValueInfo(payload: WebhookPayload) {
162+
async function fetchKeyValueInfo(payload: WebhookPayload): Promise<RenderKeyValue> {
173163
const res = await fetch(
174164
`${renderAPIURL}/key-value/${payload.data.serviceId}`,
175165
{

render.ts

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
interface WebhookData {
2+
id: string
3+
serviceId: string
4+
}
5+
6+
export interface WebhookPayload {
7+
type: string
8+
timestamp: Date
9+
data: WebhookData
10+
}
11+
12+
export interface RenderService {
13+
id: string
14+
name: string
15+
repo: string
16+
branch: string
17+
}
18+
19+
export interface RenderPostgres {
20+
id: string
21+
name: string
22+
}
23+
24+
export interface RenderKeyValue {
25+
id: string
26+
name: string
27+
}
28+
29+
interface Commit {
30+
id: string
31+
message: string
32+
}
33+
34+
interface Image {
35+
sha: string
36+
}
37+
38+
export interface RenderDeploy {
39+
id: string
40+
commit?: Commit
41+
image?: Image
42+
}
43+
44+
export interface RenderEvent {
45+
id: string
46+
type: string
47+
details: any
48+
}

0 commit comments

Comments
 (0)