Skip to content

Commit

Permalink
Refactor pipeline creation endpoint to use a separate gitLink object…
Browse files Browse the repository at this point in the history
… for storing git related information.
  • Loading branch information
mms-gianni committed Sep 5, 2023
1 parent 9340bc0 commit b3bf1d3
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 14 deletions.
36 changes: 27 additions & 9 deletions src/routes/pipelines.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -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,
};
Expand Down
16 changes: 11 additions & 5 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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[],
}
Expand Down

0 comments on commit b3bf1d3

Please sign in to comment.