Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/minor frontend improvements #487

Merged
merged 2 commits into from
Nov 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
195 changes: 130 additions & 65 deletions client/src/components/pipelines/form.vue
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@
</v-row>

<v-card elevation="2" color="cardBackground" v-if="gitops" style="margin-bottom: 20px">
<v-card-title>Deployment</v-card-title>
<v-card-title>Continuous Deployment</v-card-title>
<v-card-text>
<v-row>
<v-col
Expand All @@ -84,19 +84,115 @@
<v-combobox
v-model="gitrepo"
:rules="repositoryRules"
:counter="60"
:items="gitrepoItems"
label="Repository *"
:disabled="repository_status.connected || !newPipeline"
required
></v-combobox>
</v-col>

<v-col
cols="12"
md="6"
>

<v-alert variant="tonal" color="#8560a9" border="start">
<h3>
Repository
</h3>
<div>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.</div>
</v-alert>
</v-col>
</v-row>

<v-row>
<v-row
v-if="repository_status.connected"
>
<v-col
cols="12"
md="4"
>
<v-alert class="alert mb-5"
type="success"
elevation="6"
transition="scale-transition"
>Webhook created
</v-alert>
<v-alert class="alert"
type="success"
elevation="6"
transition="scale-transition"
>Deploy keys added
</v-alert>
<v-alert
v-show="repository_status.error"
outlined
type="warning"
prominent
border="start"
>{{repository_status.statusTxt}}
</v-alert>
</v-col>
</v-row>

<v-row
v-if="repository_status.error"
>
<v-col
cols="12"
md="4"
>
<v-alert
outlined
type="warning"
prominent
border="start"
>{{repository_status.statusTxt}}
</v-alert>
</v-col>
</v-row>


<v-row>
<v-col
cols="12"
md="2"
>
<v-btn
color="primary"
elevation="2"
v-if="!repository_status.connected"
@click="connectRepo()"
>Connect</v-btn>
<v-btn
color="secondary"
elevation="2"
v-if="repository_status.connected"
@click="reconnectRepo()"
>Reconnect</v-btn>
</v-col>
<v-col
cols="12"
md="2"
>
<v-btn
color="warning"
elevation="2"
v-if="repository_status.connected"
@click="disconnectRepo()"
>Disconnect</v-btn>
</v-col>
</v-row>
</v-card-text>
</v-card>

<v-card elevation="2" color="cardBackground" v-if="gitops" style="margin-bottom: 20px">
<v-card-title>Build</v-card-title>
<v-card-text>
<v-row>
<v-col
cols="12"
md="6"
>
<v-radio-group v-model="buildstrategy">
<v-radio
Expand Down Expand Up @@ -128,7 +224,7 @@
</v-col>
<v-col
cols="12"
md="8"
md="6"
>

<v-alert variant="tonal" color="#8560a9" border="start" v-if="buildstrategy == 'plain'">
Expand Down Expand Up @@ -236,51 +332,6 @@
></v-text-field>
</v-col>
</v-row>

<v-row
v-if="repository_status.connected && repository_status.statusTxt == 'Repository Connected' && repotab && repotab!='docker'"
>
<v-col
cols="12"
md="4"
>
<v-alert class="alert mb-5"
type="success"
elevation="6"
transition="scale-transition"
>Webhook created
</v-alert>
<v-alert class="alert"
type="success"
elevation="6"
transition="scale-transition"
>Deploy keys added
</v-alert>
</v-col>
</v-row>


<v-row>
<v-col
cols="12"
md="6"
>
<v-alert
v-show="repository_status.error"
outlined
type="warning"
prominent
border="start"
>{{repository_status.statusTxt}}
</v-alert>
<v-btn
color="primary"
elevation="2"
:disabled="!repotab"
@click="connectRepo()"
>Connect</v-btn>
</v-col>
</v-row>
</v-card-text>
</v-card>

Expand Down Expand Up @@ -326,31 +377,28 @@
md="4"
class="mt-8"
>
<v-btn
color="primary"
v-if="newPipeline"
elevation="2"
@click="createPipeline()"
<!--
:disabled="!valid ||
(gitops &&
!(
gitrepo &&
buildpack
)
)"
-->
<v-btn
color="primary"
v-if="newPipeline"
elevation="2"
@click="createPipeline()"
:disabled="!valid"
>Create</v-btn>
<v-btn
color="primary"
v-if="!newPipeline"
elevation="2"
@click="updatePipeline()"
:disabled="!valid ||
(gitops &&
!(
gitrepo &&
buildpack
)
)"
:disabled="!valid"
>Update</v-btn>
</v-col>
</v-row>
Expand Down Expand Up @@ -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 "[email protected]:organisation/repository.git"',
],
}},
computed: {
Expand Down Expand Up @@ -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);
Expand Down
14 changes: 14 additions & 0 deletions server/src/git/repo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,16 +106,30 @@ export abstract class Repo {

}

public async disconnectRepo(gitrepo: string): Promise<boolean> {
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;
return { owner: owner, repo: repo };
}

protected abstract addDeployKey(owner: string, repo: string): Promise<IDeploykeyR>
//protected abstract removeDeployKey(owner: string, repo: string, id: number): Promise<boolean>
protected abstract getRepository(gitrepo: string): Promise<IRepository>;
protected abstract addWebhook(owner: string, repo: string, url: string, secret: string): Promise<IWebhookR>;
protected abstract getWebhook(event: string, delivery: string, signature: string, body: any): IWebhook | boolean;
//protected abstract removeWebhook(owner: string, repo: string, id: number): Promise<boolean>;
protected abstract getBranches(repo: string): Promise<string[]> | undefined;
protected abstract getReferences(repo: string): Promise<string[]> | undefined;
protected abstract getPullrequests(repo: string): Promise<IPullrequest[]> | undefined;
Expand Down
2 changes: 1 addition & 1 deletion server/src/modules/kubectl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
20 changes: 20 additions & 0 deletions server/src/modules/repositories.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<string[]> {
//return this.git.listRepoBranches(repo, repoProvider);
let branches: Promise<string[]> = new Promise((resolve, reject) => {
Expand Down
7 changes: 7 additions & 0 deletions server/src/routes/repo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
Loading