-
Notifications
You must be signed in to change notification settings - Fork 260
Expand file tree
/
Copy pathgithubConnectionCreationForm.tsx
More file actions
48 lines (41 loc) · 1.69 KB
/
githubConnectionCreationForm.tsx
File metadata and controls
48 lines (41 loc) · 1.69 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
'use client';
import { GithubConnectionConfig } from "@sourcebot/schemas/v3/github.type";
import { githubSchema } from "@sourcebot/schemas/v3/github.schema";
import { githubQuickActions } from "../../connections/quickActions";
import SharedConnectionCreationForm from "./sharedConnectionCreationForm";
interface GitHubConnectionCreationFormProps {
onCreated?: (id: number) => void;
}
const additionalConfigValidation = (config: GithubConnectionConfig): { message: string, isValid: boolean } => {
const hasRepos = config.repos && config.repos.length > 0 && config.repos.some(r => r.trim().length > 0);
const hasOrgs = config.orgs && config.orgs.length > 0 && config.orgs.some(o => o.trim().length > 0);
const hasUsers = config.users && config.users.length > 0 && config.users.some(u => u.trim().length > 0);
if (!hasRepos && !hasOrgs && !hasUsers) {
return {
message: "At least one repository, organization, or user must be specified",
isValid: false,
}
}
return {
message: "Valid",
isValid: true,
}
};
export const GitHubConnectionCreationForm = ({ onCreated }: GitHubConnectionCreationFormProps) => {
const defaultConfig: GithubConnectionConfig = {
type: 'github',
}
return (
<SharedConnectionCreationForm<GithubConnectionConfig>
type="github"
title="Create a GitHub connection"
defaultValues={{
config: JSON.stringify(defaultConfig, null, 2),
}}
schema={githubSchema}
additionalConfigValidation={additionalConfigValidation}
quickActions={githubQuickActions}
onCreated={onCreated}
/>
)
}