From 08a82ba4ff022cddf6556e3a341db3e65c96d202 Mon Sep 17 00:00:00 2001 From: Gianni Carafa Date: Sun, 10 Nov 2024 23:52:42 +0100 Subject: [PATCH 1/2] fix initcontainer args --- server/src/modules/kubectl.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/server/src/modules/kubectl.ts b/server/src/modules/kubectl.ts index 63b7f0d4..cd4311e1 100644 --- a/server/src/modules/kubectl.ts +++ b/server/src/modules/kubectl.ts @@ -1176,7 +1176,7 @@ export class Kubectl { if (buildstrategy === 'buildpacks') { // configure build container - job.spec.template.spec.initContainers[1].args[2] = repository.image+":"+repository.tag+"-"+id; + job.spec.template.spec.initContainers[2].args[1] = repository.image+":"+repository.tag+"-"+id; } if (buildstrategy === 'dockerfile') { // configure push container From 3d179d67f7c8525d645f29093ebf1b709d7e6d90 Mon Sep 17 00:00:00 2001 From: Gianni Carafa Date: Mon, 11 Nov 2024 22:01:58 +0100 Subject: [PATCH 2/2] update pipeline view --- client/src/components/pipelines/form.vue | 195 +++++++++++++++-------- server/src/git/repo.ts | 14 ++ server/src/modules/repositories.ts | 20 +++ server/src/routes/repo.ts | 7 + 4 files changed, 171 insertions(+), 65 deletions(-) diff --git a/client/src/components/pipelines/form.vue b/client/src/components/pipelines/form.vue index 184fce89..40bee646 100644 --- a/client/src/components/pipelines/form.vue +++ b/client/src/components/pipelines/form.vue @@ -58,7 +58,7 @@ - Deployment + Continuous Deployment + + + + +

+ Repository +

+
When connected, webhooks and deployment keys are stored in the repository. This means that the apps configured in this project can be automatically redeployed with a 'git push' and opening a PR starts a new instance in the "review" phase.
+
+
- + + Webhook created + + Deploy keys added + + {{repository_status.statusTxt}} + + + + + + + {{repository_status.statusTxt}} + + + + + + + + Connect + Reconnect + + + Disconnect + + +
+
+ + + Build + + + @@ -236,51 +332,6 @@ > - - - - Webhook created - - Deploy keys added - - - - - - - - {{repository_status.statusTxt}} - - Connect - - @@ -326,11 +377,7 @@ md="4" class="mt-8" > - + Create Update @@ -496,10 +544,13 @@ export default defineComponent({ (v: any) => /^(?:[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?\.)+[a-z0-9][a-z0-9-]{0,61}[a-z0-9]$|^localhost$|^$/.test(v) || 'Not a domain', ], repositoryRules: [ - (v: any) => !!v || 'Repository is required', - (v: any) => v.length <= 120 || 'Repository must be less than 120 characters', - // ((git|ssh|http(s)?)|(git@[\w\.]+))(:(//)?)([\w\.@\:/\-~]+)(\.git)(/)? - (v: any) => /((git|ssh|http(s)?)|(git@[\w.]+))(:(\/\/)?)([\w.@:/\-~]+)(\.git)(\/)?/.test(v) || 'Format "owner/repository"', + //(v: any) => !!v || 'Repository is required', + //(v: any) => v.length <= 120 || 'Repository must be less than 120 characters', + // ((git|ssh|http(s)?)|(git@[\w\.]+))(:(//)?)([\w\.@\:/\-~]+)(\.git)(/)? + // ((git|ssh|http(s)?)|(git@[\w.]+))(:(\/\/)?)([\w.@:\/\-~]+)(\.git) + // (git@[\w.]+:\/\/)([\w.\/\-~]+)(\.git) // not working + // ((git|ssh|http(s)?)|(git@[\w\.-]+))(:(//)?)([\w\.@\:/\-~]+)(\.git)(/)? + (v: any) => /^((git|ssh|http(s)?)|(git@[\w\.-]+))(:(\/\/)?)([\w\.@\:\/\-~]+)(\.git)(\/)?/.test(v) || 'Format "git@github.com:organisation/repository.git"', ], }}, computed: { @@ -551,6 +602,20 @@ export default defineComponent({ this.buildpack = response.data[0]; }); }, + disconnectRepo(){ + const repo = this.repotab; + axios.post(`/api/repo/${repo}/disconnect`, { + gitrepo: this.gitrepo + }).then(response => { + this.repository_status.connected = false; + }).catch(error => { + console.log(error); + }); + }, + reconnectRepo(){ + this.repository_status.connected = false; + this.connectRepo(); + }, connectRepo() { //console.log(this.gitrepo); //console.log(this.repotab); diff --git a/server/src/git/repo.ts b/server/src/git/repo.ts index 8a20d4e2..10b9dbf7 100644 --- a/server/src/git/repo.ts +++ b/server/src/git/repo.ts @@ -106,6 +106,18 @@ export abstract class Repo { } + public async disconnectRepo(gitrepo: string): Promise { + debug.log('disconnectPipeline: '+gitrepo); + + const {owner, repo} = this.parseRepo(gitrepo); + + // TODO: implement remove deploy key and webhook for all providers + //this.removeDeployKey(owner, repo, 0); + //this.removeWebhook(owner, repo, 0); + + return true; + } + protected parseRepo(gitrepo: string): {owner: string, repo: string} { let owner = gitrepo.match(/^git@.*:(.*)\/.*$/)?.[1] as string; let repo = gitrepo.match(/^git@.*:.*\/(.*).git$/)?.[1] as string; @@ -113,9 +125,11 @@ export abstract class Repo { } protected abstract addDeployKey(owner: string, repo: string): Promise + //protected abstract removeDeployKey(owner: string, repo: string, id: number): Promise protected abstract getRepository(gitrepo: string): Promise; protected abstract addWebhook(owner: string, repo: string, url: string, secret: string): Promise; protected abstract getWebhook(event: string, delivery: string, signature: string, body: any): IWebhook | boolean; + //protected abstract removeWebhook(owner: string, repo: string, id: number): Promise; protected abstract getBranches(repo: string): Promise | undefined; protected abstract getReferences(repo: string): Promise | undefined; protected abstract getPullrequests(repo: string): Promise | undefined; diff --git a/server/src/modules/repositories.ts b/server/src/modules/repositories.ts index 77330c1a..f1f90b92 100644 --- a/server/src/modules/repositories.ts +++ b/server/src/modules/repositories.ts @@ -93,6 +93,26 @@ export class Repositories { } } + public async disconnectRepo(repoProvider: string, repoAddress: string) { + debug.log('disconnectRepo: '+repoProvider+' '+repoAddress); + + switch (repoProvider) { + case 'github': + return this.githubApi.disconnectRepo(repoAddress); + case 'gitea': + return this.giteaApi.disconnectRepo(repoAddress); + case 'gogs': + return this.gogsApi.disconnectRepo(repoAddress); + case 'gitlab': + return this.gitlabApi.disconnectRepo(repoAddress); + case 'bitbucket': + return this.bitbucketApi.disconnectRepo(repoAddress); + case 'onedev': + default: + return {'error': 'unknown repo provider'}; + } + } + public async listRepoBranches(repoProvider: string, repoB64: string ): Promise { //return this.git.listRepoBranches(repo, repoProvider); let branches: Promise = new Promise((resolve, reject) => { diff --git a/server/src/routes/repo.ts b/server/src/routes/repo.ts index b61f30dc..e1eb0f5b 100644 --- a/server/src/routes/repo.ts +++ b/server/src/routes/repo.ts @@ -14,6 +14,13 @@ Router.get('/repo/:repoprovider/list', async function (req: Request, res: Respon res.send(repolist); }); +Router.post('/repo/:repoprovider/disconnect', async function (req: Request, res: Response) { + // #swagger.tags = ['UI'] + // #swagger.summary = 'Disconnect a repository from a pipeline by removing the webhook and deployment key' + let con = await req.app.locals.repositories.disconnectRepo(req.params.repoprovider, req.body.gitrepo); + res.send(con); +}); + Router.post('/repo/:repoprovider/connect', async function (req: Request, res: Response) { // #swagger.tags = ['UI'] // #swagger.summary = 'Connect a repository to a pipeline'