fix: more types for API
This commit is contained in:
@@ -1,13 +1,15 @@
|
||||
import axios from "axios";
|
||||
import cuid from "cuid";
|
||||
import crypto from "crypto";
|
||||
import type { FastifyReply, FastifyRequest } from "fastify";
|
||||
import { encrypt, errorHandler, getAPIUrl, getUIUrl, isDev, prisma } from "../../../lib/common";
|
||||
import { encrypt, errorHandler, getUIUrl, isDev, prisma } from "../../../lib/common";
|
||||
import { checkContainer, removeContainer } from "../../../lib/docker";
|
||||
import { scheduler } from "../../../lib/scheduler";
|
||||
import { getApplicationFromDB, getApplicationFromDBWebhook } from "../../api/v1/applications/handlers";
|
||||
import { getApplicationFromDBWebhook } from "../../api/v1/applications/handlers";
|
||||
|
||||
export async function installGithub(request: FastifyRequest, reply: FastifyReply): Promise<any> {
|
||||
import type { FastifyReply, FastifyRequest } from "fastify";
|
||||
import type { GitHubEvents, InstallGithub } from "./types";
|
||||
|
||||
export async function installGithub(request: FastifyRequest<InstallGithub>, reply: FastifyReply): Promise<any> {
|
||||
try {
|
||||
const { gitSourceId, installation_id } = request.query;
|
||||
const source = await prisma.gitSource.findUnique({
|
||||
@@ -63,7 +65,7 @@ export async function configureGitHubApp(request, reply) {
|
||||
return errorHandler({ status, message })
|
||||
}
|
||||
}
|
||||
export async function gitHubEvents(request: FastifyRequest, reply: FastifyReply): Promise<any> {
|
||||
export async function gitHubEvents(request: FastifyRequest<GitHubEvents>): Promise<any> {
|
||||
try {
|
||||
const buildId = cuid();
|
||||
const allowedGithubEvents = ['push', 'pull_request'];
|
||||
|
||||
@@ -1,10 +1,12 @@
|
||||
import { FastifyPluginAsync } from 'fastify';
|
||||
import { configureGitHubApp, gitHubEvents, installGithub } from './handlers';
|
||||
|
||||
const root: FastifyPluginAsync = async (fastify, opts): Promise<void> => {
|
||||
import type { GitHubEvents, InstallGithub } from './types';
|
||||
|
||||
const root: FastifyPluginAsync = async (fastify): Promise<void> => {
|
||||
fastify.get('/', async (request, reply) => configureGitHubApp(request, reply));
|
||||
fastify.get('/install', async (request, reply) => installGithub(request, reply));
|
||||
fastify.post('/events', async (request, reply) => gitHubEvents(request, reply));
|
||||
fastify.get<InstallGithub>('/install', async (request, reply) => installGithub(request, reply));
|
||||
fastify.post<GitHubEvents>('/events', async (request, reply) => gitHubEvents(request));
|
||||
};
|
||||
|
||||
export default root;
|
||||
|
||||
20
apps/api/src/routes/webhooks/github/types.ts
Normal file
20
apps/api/src/routes/webhooks/github/types.ts
Normal file
@@ -0,0 +1,20 @@
|
||||
export interface InstallGithub {
|
||||
Querystring: {
|
||||
gitSourceId: string,
|
||||
installation_id: string
|
||||
}
|
||||
}
|
||||
export interface GitHubEvents {
|
||||
Body: {
|
||||
number: string,
|
||||
action: string,
|
||||
repository: string,
|
||||
ref: string,
|
||||
pull_request: {
|
||||
head: {
|
||||
ref: string,
|
||||
repo: string
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user