From b3bf1d33995338e8a31344cf2343e68639d5c441 Mon Sep 17 00:00:00 2001 From: Gianni Carafa Date: Tue, 5 Sep 2023 21:57:01 +0200 Subject: [PATCH] Refactor pipeline creation endpoint to use a separate gitLink object for storing git related information. --- src/routes/pipelines.ts | 36 +++++++++++++++++++++++++++--------- src/types.ts | 16 +++++++++++----- 2 files changed, 38 insertions(+), 14 deletions(-) diff --git a/src/routes/pipelines.ts b/src/routes/pipelines.ts index 8e8265a1..53a0b35a 100644 --- a/src/routes/pipelines.ts +++ b/src/routes/pipelines.ts @@ -1,5 +1,6 @@ import express, { Request, Response } from 'express'; import { Auth } from '../modules/auth'; +import { gitLink } from '../types'; import { IApp, IPipeline } from '../types'; import { App } from '../modules/application'; import { Webhooks } from '@octokit/webhooks'; @@ -23,25 +24,42 @@ Router.post('/cli/pipelines',bearerMiddleware, async function (req: Request, res } }] */ - let con = await req.app.locals.kubero.connectRepo( - req.body.git.repository.provider.toLowerCase(), - req.body.git.repository.ssh_url); + const con = await req.app.locals.kubero.connectRepo( + req.body.git.repository.provider.toLowerCase(), + req.body.git.repository.ssh_url); + + let git: gitLink = { + keys: { + priv: "Zm9v", + pub: "YmFy" + }, + repository: { + admin: false, + clone_url: "", + ssh_url: "", + }, + webhook: {} + }; + + if (con.error) { + console.log("ERROR: connecting Gitrepository", con.error); + } else { + git.keys = con.keys.data, + git.webhook = con.webhook.data, + git.repository = con.repository.data + } const buildpackList = req.app.locals.kubero.getBuildpacks() const selectedBuildpack = buildpackList.find((element: { name: any; }) => element.name == req.body.buildpack.name); - let pipeline: IPipeline = { + const pipeline: IPipeline = { name: req.body.pipelineName, domain: req.body.domain, phases: req.body.phases, buildpack: selectedBuildpack, reviewapps: req.body.reviewapps, - git: { - keys: con.keys.data, - webhook: con.webhook.data, - repository: con.repository.data - }, + git: git, dockerimage: req.body.dockerimage, deploymentstrategy: req.body.deploymentstrategy, }; diff --git a/src/types.ts b/src/types.ts index baee8c31..eae4e8a6 100644 --- a/src/types.ts +++ b/src/types.ts @@ -157,16 +157,22 @@ export interface IPipeline { reviewapps: boolean; phases: IPipelinePhase[]; buildpack: IBuildpack - git: { - keys: object, - repository?: IGithubRepository - webhook: object; - }; + git: gitLink; dockerimage: string; deploymentstrategy: 'git' | 'docker', resourceVersion?: string; // required to update resource, not part of spec } +export interface gitLink { + keys: { + priv: string, + pub: string, + }, + provider?: string, + repository?: IGithubRepository + webhook: object; +} + export interface IPipelineList { items: IPipeline[], }