This commit is contained in:
Andras Bacsai
2022-04-12 10:47:53 +02:00
parent a4e7c85184
commit 41bf6b5b86
7 changed files with 63 additions and 25 deletions

View File

@@ -69,7 +69,7 @@ export function del(
export function post(
path: string,
data: Record<string, unknown>,
headers: Record<string, unknown>
headers?: Record<string, unknown>
): Promise<Record<string, unknown>> {
return send({ method: 'POST', path, data, headers });
}

View File

@@ -18,18 +18,10 @@ export async function listSources(
export async function newSource({
name,
teamId,
type,
htmlUrl,
apiUrl,
organization
teamId
}: {
name: string;
teamId: string;
type: string;
htmlUrl: string;
apiUrl: string;
organization: string;
}): Promise<GitSource> {
return await prisma.gitSource.create({
data: {
@@ -74,8 +66,11 @@ export async function getSource({
if (body?.gitlabApp?.appSecret) body.gitlabApp.appSecret = decrypt(body.gitlabApp.appSecret);
return body;
}
export async function addGitHubSource({ id, teamId, type, name, htmlUrl, apiUrl }) {
await prisma.gitSource.update({ where: { id }, data: { type, name, htmlUrl, apiUrl } });
export async function addGitHubSource({ id, teamId, type, name, htmlUrl, apiUrl, organization }) {
await prisma.gitSource.update({
where: { id },
data: { type, name, htmlUrl, apiUrl, organization }
});
return await prisma.githubApp.create({
data: {
teams: { connect: { id: teamId } },
@@ -123,10 +118,14 @@ export async function configureGitsource({
}
export async function updateGitsource({
id,
name
name,
htmlUrl,
apiUrl
}: {
id: string;
name: string;
htmlUrl: string;
apiUrl: string;
}): Promise<GitSource> {
return await prisma.gitSource.update({
where: { id },

View File

@@ -2,7 +2,9 @@ import * as Bullmq from 'bullmq';
import { default as ProdBullmq, QueueScheduler } from 'bullmq';
import { dev } from '$app/env';
import { prisma } from '$lib/database';
import builder from './builder';
import logger from './logger';
import cleanup from './cleanup';
import proxy from './proxy';
import ssl from './ssl';
@@ -142,5 +144,9 @@ buildWorker.on('failed', async (job: Bullmq.Job, failedReason) => {
const buildLogQueueName = 'log_queue';
const buildLogQueue = new Queue(buildLogQueueName, connectionOptions);
const buildLogWorker = new Worker(buildLogQueueName, async (job) => await logger(job), {
concurrency: 1,
...connectionOptions
});
export { buildQueue, buildLogQueue };

View File

@@ -2,6 +2,7 @@
export let source;
import { page, session } from '$app/stores';
import { post } from '$lib/api';
import Explainer from '$lib/components/Explainer.svelte';
import { errorNotification } from '$lib/form';
import { toast } from '@zerodevx/svelte-toast';
const { id } = $page.params;
@@ -51,7 +52,8 @@
type: 'github',
name: source.name,
htmlUrl: source.htmlUrl.replace(/\/$/, ''),
apiUrl: source.apiUrl.replace(/\/$/, '')
apiUrl: source.apiUrl.replace(/\/$/, ''),
organization: source.organization
});
} catch ({ error }) {
return errorNotification(error);
@@ -97,6 +99,22 @@
<label for="apiUrl" class="text-base font-bold text-stone-100">API URL</label>
<input name="apiUrl" id="apiUrl" required bind:value={source.apiUrl} />
</div>
<div class="grid grid-cols-2">
<div class="flex flex-col">
<label for="organization" class="pt-2 text-base font-bold text-stone-100"
>Organization</label
>
<Explainer
text="Fill it if you would like to use an organization's as your Git Source. Otherwise your user will be used."
/>
</div>
<input
name="organization"
id="organization"
placeholder="eg: coollabsio"
bind:value={source.organization}
/>
</div>
</div>
{#if source.apiUrl && source.htmlUrl && source.name}
<div class="text-center">
@@ -135,6 +153,21 @@
<label for="apiUrl" class="text-base font-bold text-stone-100">API URL</label>
<input name="apiUrl" id="apiUrl" required bind:value={source.apiUrl} />
</div>
<div class="grid grid-cols-2">
<div class="flex flex-col">
<label for="organization" class="pt-2 text-base font-bold text-stone-100"
>Organization</label
>
</div>
<input
readonly
disabled
name="organization"
id="organization"
placeholder="eg: coollabsio"
bind:value={source.organization}
/>
</div>
</div>
</form>
{:else}

View File

@@ -9,8 +9,8 @@ export const post: RequestHandler = async (event) => {
const { id } = event.params;
try {
let { type, name, htmlUrl, apiUrl } = await event.request.json();
await db.addGitHubSource({ id, teamId, type, name, htmlUrl, apiUrl });
let { type, name, htmlUrl, apiUrl, organization } = await event.request.json();
await db.addGitHubSource({ id, teamId, type, name, htmlUrl, apiUrl, organization });
return { status: 201 };
} catch (error) {
return ErrorHandler(error);