Skip to content

Commit

Permalink
🎯 working on my github stats
Browse files Browse the repository at this point in the history
  • Loading branch information
thibaultleouay committed Jun 13, 2024
1 parent 256487e commit db081e2
Show file tree
Hide file tree
Showing 111 changed files with 451 additions and 456 deletions.
9 changes: 4 additions & 5 deletions apps/screenshot-service/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ const receiver = new Receiver({
const app = new Hono();

app.get("/ping", (c) =>
c.json({ ping: "pong", region: process.env.FLY_REGION }, 200)
c.json({ ping: "pong", region: process.env.FLY_REGION }, 200),
);

app.post(
Expand All @@ -38,7 +38,7 @@ app.post(
url: z.string().url(),
incidentId: z.number(),
kind: z.enum(["incident", "recovery"]),
})
}),
),
async (c) => {
const signature = c.req.header("Upstash-Signature");
Expand All @@ -53,7 +53,6 @@ app.post(
body: JSON.stringify(data),
});
if (!isValid) {

console.error("Unauthorized");
return c.text("Unauthorized", 401);
}
Expand All @@ -75,7 +74,7 @@ app.post(
Bucket: "incident-screenshot",
Key: id,
ContentType: "image/png",
})
}),
);

if (data.kind === "incident") {
Expand Down Expand Up @@ -109,7 +108,7 @@ app.post(
}

return c.text("Screenshot saved");
}
},
);

export default app;
18 changes: 9 additions & 9 deletions apps/server/src/checker/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Client } from "@upstash/qstash";
import { Hono } from "hono";
import { z } from "zod";
import { Client } from "@upstash/qstash";

import { and, db, eq, isNull, schema } from "@openstatus/db";
import { incidentTable } from "@openstatus/db/src/schema";
Expand Down Expand Up @@ -59,8 +59,8 @@ checkerRoute.post("/updateStatus", async (c) => {
and(
eq(incidentTable.monitorId, Number(monitorId)),
isNull(incidentTable.resolvedAt),
isNull(incidentTable.acknowledgedAt)
)
isNull(incidentTable.acknowledgedAt),
),
)
.get();

Expand Down Expand Up @@ -100,7 +100,7 @@ checkerRoute.post("/updateStatus", async (c) => {
const numberOfRegions = monitor.regions.length;

console.log(
`🤓 MonitorID ${monitorId} incident current affected ${nbAffectedRegion} total region ${numberOfRegions}`
`🤓 MonitorID ${monitorId} incident current affected ${nbAffectedRegion} total region ${numberOfRegions}`,
);
// If the number of affected regions is greater than half of the total region, we trigger the alerting
// 4 of 6 monitor need to fail to trigger an alerting
Expand All @@ -114,8 +114,8 @@ checkerRoute.post("/updateStatus", async (c) => {
eq(incidentTable.monitorId, Number(monitorId)),
isNull(incidentTable.resolvedAt),
isNull(incidentTable.acknowledgedAt),
eq(incidentTable.startedAt, new Date(cronTimestamp))
)
eq(incidentTable.startedAt, new Date(cronTimestamp)),
),
)
.get();

Expand Down Expand Up @@ -192,7 +192,7 @@ checkerRoute.post("/updateStatus", async (c) => {
const numberOfRegions = monitor.regions.length;

console.log(
`🤓 MonitorId ${monitorId} recovering incident current ${nbAffectedRegion} total region ${numberOfRegions}`
`🤓 MonitorId ${monitorId} recovering incident current ${nbAffectedRegion} total region ${numberOfRegions}`,
);
// // If the number of affected regions is greater than half of the total region, we trigger the alerting
// // 4 of 6 monitor need to fail to trigger an alerting
Expand All @@ -204,8 +204,8 @@ checkerRoute.post("/updateStatus", async (c) => {
and(
eq(incidentTable.monitorId, Number(monitorId)),
isNull(incidentTable.resolvedAt),
isNull(incidentTable.acknowledgedAt)
)
isNull(incidentTable.acknowledgedAt),
),
)
.get();
if (incident) {
Expand Down
2 changes: 1 addition & 1 deletion apps/server/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ import { logger } from "hono/logger";

import { checkerRoute } from "./checker";
import { env } from "./env";
import { handleError } from "./libs/errors";
import { publicRoute } from "./public";
import { api } from "./v1";
import { handleError } from "./libs/errors";

const app = new Hono({ strict: false });
app.use("*", sentry({ dsn: process.env.SENTRY_DSN }));
Expand Down
2 changes: 1 addition & 1 deletion apps/server/src/libs/errors/openapi-error-responses.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ export const openApiErrorResponses = {
content: {
"application/json": {
schema: createErrorSchema("INTERNAL_SERVER_ERROR").openapi(
"ErrInternalServerError"
"ErrInternalServerError",
),
},
},
Expand Down
10 changes: 5 additions & 5 deletions apps/server/src/libs/errors/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export function handleError(err: Error, c: Context): Response {
message: error.message,
docs: "https://docs.openstatus.dev/api-references/errors/code/BAD_REQUEST",
},
{ status: 400 }
{ status: 400 },
);
}
if (err instanceof HTTPException) {
Expand All @@ -30,7 +30,7 @@ export function handleError(err: Error, c: Context): Response {
message: err.message,
docs: `https://docs.openstatus.dev/api-references/errors/code/${code}`,
},
{ status: err.status }
{ status: err.status },
);
}
return c.json<ErrorSchema>(
Expand All @@ -40,7 +40,7 @@ export function handleError(err: Error, c: Context): Response {
docs: "https://docs.openstatus.dev/api-references/errors/code/INTERNAL_SERVER_ERROR",
},

{ status: 500 }
{ status: 500 },
);
}

Expand All @@ -54,7 +54,7 @@ export function handleZodError(
success: false;
error: ZodError;
},
c: Context
c: Context,
) {
if (!result.success) {
const error = SchemaError.fromZod(result.error, c);
Expand All @@ -64,7 +64,7 @@ export function handleZodError(
docs: "https://docs.openstatus.dev/api-references/errors/code/BAD_REQUEST",
message: error.message,
},
{ status: 400 }
{ status: 400 },
);
}
}
Expand Down
18 changes: 9 additions & 9 deletions apps/server/src/public/status.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,8 @@ async function getStatusPageData(pageId: number) {
and(
eq(monitorsToPages.monitorId, monitor.id),
eq(monitor.active, true),
eq(monitorsToPages.pageId, pageId)
)
eq(monitorsToPages.pageId, pageId),
),
)

.all();
Expand All @@ -105,7 +105,7 @@ async function getStatusPageData(pageId: number) {
.from(monitorsToStatusReport)
.innerJoin(
statusReport,
eq(monitorsToStatusReport.statusReportId, statusReport.id)
eq(monitorsToStatusReport.statusReportId, statusReport.id),
)
.where(inArray(monitorsToStatusReport.monitorId, monitorIds))
.all();
Expand All @@ -117,8 +117,8 @@ async function getStatusPageData(pageId: number) {
statusReport,
and(
eq(pagesToStatusReports.statusReportId, statusReport.id),
eq(pagesToStatusReports.pageId, pageId)
)
eq(pagesToStatusReports.pageId, pageId),
),
)
.all();

Expand All @@ -128,8 +128,8 @@ async function getStatusPageData(pageId: number) {
.where(
and(
isNull(incidentTable.resolvedAt),
inArray(incidentTable.monitorId, monitorIds)
)
inArray(incidentTable.monitorId, monitorIds),
),
)
.all();

Expand All @@ -140,8 +140,8 @@ async function getStatusPageData(pageId: number) {
and(
eq(maintenance.pageId, pageId),
lte(maintenance.from, new Date()),
gte(maintenance.to, new Date())
)
gte(maintenance.to, new Date()),
),
);

const [
Expand Down
4 changes: 2 additions & 2 deletions apps/server/src/v1/incidents/get.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ import { createRoute } from "@hono/zod-openapi";
import { and, db, eq } from "@openstatus/db";
import { incidentTable } from "@openstatus/db/src/schema/incidents";

import { IncidentSchema, ParamsSchema } from "./schema";
import { HTTPException } from "hono/http-exception";
import { openApiErrorResponses } from "../../libs/errors/openapi-error-responses";
import type { incidentsApi } from "./index";
import { HTTPException } from "hono/http-exception";
import { IncidentSchema, ParamsSchema } from "./schema";

const getRoute = createRoute({
method: "get",
Expand Down
6 changes: 3 additions & 3 deletions apps/server/src/v1/incidents/get_all.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ import { createRoute, z } from "@hono/zod-openapi";
import { db, eq } from "@openstatus/db";
import { incidentTable } from "@openstatus/db/src/schema/incidents";

import { IncidentSchema } from "./schema";
import type { incidentsApi } from "./index";
import { openApiErrorResponses } from "../../libs/errors/openapi-error-responses";
import { HTTPException } from "hono/http-exception";
import { openApiErrorResponses } from "../../libs/errors/openapi-error-responses";
import type { incidentsApi } from "./index";
import { IncidentSchema } from "./schema";

const getAllRoute = createRoute({
method: "get",
Expand Down
4 changes: 2 additions & 2 deletions apps/server/src/v1/incidents/index.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { OpenAPIHono } from "@hono/zod-openapi";

import { handleZodError } from "../../libs/errors";
import type { Variables } from "../index";
import { registerGetAllIncidents } from "./get_all";
import { registerGetIncident } from "./get";
import { registerGetAllIncidents } from "./get_all";
import { registerPutIncident } from "./put";
import { handleZodError } from "../../libs/errors";

const incidentsApi = new OpenAPIHono<{ Variables: Variables }>({
defaultHook: handleZodError,
Expand Down
8 changes: 4 additions & 4 deletions apps/server/src/v1/incidents/put.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ import { createRoute, z } from "@hono/zod-openapi";
import { and, db, eq } from "@openstatus/db";
import { incidentTable } from "@openstatus/db/src/schema/incidents";

import { IncidentSchema, ParamsSchema } from "./schema";
import { HTTPException } from "hono/http-exception";
import { openApiErrorResponses } from "../../libs/errors/openapi-error-responses";
import type { incidentsApi } from "./index";
import { HTTPException } from "hono/http-exception";
import { IncidentSchema, ParamsSchema } from "./schema";

const putRoute = createRoute({
method: "put",
Expand Down Expand Up @@ -59,8 +59,8 @@ export function registerPutIncident(app: typeof incidentsApi) {
.where(
and(
eq(incidentTable.id, Number(id)),
eq(incidentTable.workspaceId, Number(workspaceId))
)
eq(incidentTable.workspaceId, Number(workspaceId)),
),
)
.get();

Expand Down
6 changes: 3 additions & 3 deletions apps/server/src/v1/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@ import { logger } from "hono/logger";

import type { Limits } from "@openstatus/plans/src/types";

import { handleError, handleZodError } from "../libs/errors";
import { incidentsApi } from "./incidents";
import { middleware } from "./middleware";
import { monitorsApi } from "./monitors";
import { notificationsApi } from "./notifications";
import { pagesApi } from "./pages";
import { pageSubscribersApi } from "./pageSubscribers";
import { statusReportsApi } from "./statusReports";
import { pagesApi } from "./pages";
import { statusReportUpdatesApi } from "./statusReportUpdates";
import { handleError, handleZodError } from "../libs/errors";
import { statusReportsApi } from "./statusReports";

export type Variables = {
workspaceId: string;
Expand Down
6 changes: 3 additions & 3 deletions apps/server/src/v1/middleware.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import { verifyKey } from "@unkey/api";
import type { Context, Next } from "hono";

import type { Variables } from "./index";
import { workspace } from "@openstatus/db/src/schema";
import { db, eq } from "@openstatus/db";
import { workspace } from "@openstatus/db/src/schema";
import { getPlanConfig } from "@openstatus/plans";
import type { Variables } from "./index";

export async function middleware(
c: Context<{ Variables: Variables }, "/*">,
next: Next
next: Next,
) {
const key = c.req.header("x-openstatus-key");
if (!key) return c.text("Unauthorized", 401);
Expand Down
4 changes: 2 additions & 2 deletions apps/server/src/v1/monitors/delete.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ import { createRoute, z } from "@hono/zod-openapi";
import { db, eq } from "@openstatus/db";
import { monitor } from "@openstatus/db/src/schema";

import { ParamsSchema } from "./schema";
import { HTTPException } from "hono/http-exception";
import { openApiErrorResponses } from "../../libs/errors/openapi-error-responses";
import type { monitorsApi } from "./index";
import { HTTPException } from "hono/http-exception";
import { ParamsSchema } from "./schema";

const deleteRoute = createRoute({
method: "delete",
Expand Down
8 changes: 4 additions & 4 deletions apps/server/src/v1/monitors/get.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ import { createRoute, z } from "@hono/zod-openapi";
import { and, db, eq, isNull } from "@openstatus/db";
import { monitor } from "@openstatus/db/src/schema";

import { HTTPException } from "hono/http-exception";
import { openApiErrorResponses } from "../../libs/errors/openapi-error-responses";
import type { monitorsApi } from "./index";
import { MonitorSchema, ParamsSchema } from "./schema";
import { openApiErrorResponses } from "../../libs/errors/openapi-error-responses";
import { HTTPException } from "hono/http-exception";

const getRoute = createRoute({
method: "get",
Expand Down Expand Up @@ -41,8 +41,8 @@ export function registerGetMonitor(api: typeof monitorsApi) {
and(
eq(monitor.id, Number(id)),
eq(monitor.workspaceId, Number(workspaceId)),
isNull(monitor.deletedAt)
)
isNull(monitor.deletedAt),
),
)
.get();

Expand Down
8 changes: 4 additions & 4 deletions apps/server/src/v1/monitors/get_all.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ import { createRoute, z } from "@hono/zod-openapi";
import { and, db, eq, isNull } from "@openstatus/db";
import { monitor } from "@openstatus/db/src/schema";

import { HTTPException } from "hono/http-exception";
import { openApiErrorResponses } from "../../libs/errors/openapi-error-responses";
import type { monitorsApi } from "./index";
import { MonitorSchema } from "./schema";
import { openApiErrorResponses } from "../../libs/errors/openapi-error-responses";
import { HTTPException } from "hono/http-exception";

const getAllRoute = createRoute({
method: "get",
Expand Down Expand Up @@ -37,8 +37,8 @@ export function registerGetAllMonitors(app: typeof monitorsApi) {
.where(
and(
eq(monitor.workspaceId, Number(workspaceId)),
isNull(monitor.deletedAt)
)
isNull(monitor.deletedAt),
),
)
.all();

Expand Down
Loading

0 comments on commit db081e2

Please sign in to comment.