Browse Source

Integrated last steps for launch flow with gitlab

jnfrati 4 years ago
parent
commit
2d4d606717

+ 1 - 0
dashboard/src/components/repo-selector/ActionConfEditor.tsx

@@ -32,6 +32,7 @@ const defaultActionConfig: ActionConfigType = {
   image_repo_uri: "",
   git_branch: "",
   git_repo_id: 0,
+  kind: "github",
 };
 
 const ActionConfEditor: React.FC<Props> = (props) => {

+ 63 - 37
dashboard/src/components/repo-selector/ContentsList.tsx

@@ -66,7 +66,8 @@ export default class ContentsList extends Component<PropsType, StateType> {
   fetchContents = () => {
     let { currentProject } = this.context;
     const { actionConfig, branch } = this.props;
-    if (actionConfig.gitlab_integration_id > 0) {
+
+    if (actionConfig.kind === "gitlab") {
       return api.getGitlabFolderContent(
         "<token>",
         { dir: this.state.currentDir || "./" },
@@ -78,10 +79,31 @@ export default class ContentsList extends Component<PropsType, StateType> {
           branch: branch,
         }
       );
-    } else {
-      return api.getBranchContents(
+    }
+    return api.getBranchContents(
+      "<token>",
+      { dir: this.state.currentDir || "./" },
+      {
+        project_id: currentProject.id,
+        git_repo_id: actionConfig.git_repo_id,
+        kind: "github",
+        owner: actionConfig.git_repo.split("/")[0],
+        name: actionConfig.git_repo.split("/")[1],
+        branch: branch,
+      }
+    );
+  };
+
+  detectBuildpacks = () => {
+    let { currentProject } = this.context;
+    let { actionConfig, branch } = this.props;
+
+    if (actionConfig.kind === "github") {
+      return api.detectBuildpack(
         "<token>",
-        { dir: this.state.currentDir || "./" },
+        {
+          dir: this.state.currentDir || ".",
+        },
         {
           project_id: currentProject.id,
           git_repo_id: actionConfig.git_repo_id,
@@ -92,12 +114,44 @@ export default class ContentsList extends Component<PropsType, StateType> {
         }
       );
     }
+
+    return new Promise((_res, reject) => reject(new Error("Not implemented")));
   };
 
-  updateContents = () => {
+  fetchProcfileContent = (procfilePath: string) => {
     let { currentProject } = this.context;
     let { actionConfig, branch } = this.props;
+    if (actionConfig.kind === "github") {
+      return api.getProcfileContents(
+        "<token>",
+        {
+          path: procfilePath,
+        },
+        {
+          project_id: currentProject.id,
+          git_repo_id: actionConfig.git_repo_id,
+          kind: "github",
+          owner: actionConfig.git_repo.split("/")[0],
+          name: actionConfig.git_repo.split("/")[1],
+          branch: branch,
+        }
+      );
+    }
 
+    return api.getGitlabProcfileContents(
+      "<token>",
+      { path: procfilePath },
+      {
+        project_id: currentProject.id,
+        integration_id: actionConfig.gitlab_integration_id,
+        owner: actionConfig.git_repo.split("/")[0],
+        name: actionConfig.git_repo.split("/")[1],
+        branch: branch,
+      }
+    );
+  };
+
+  updateContents = () => {
     // Get branch contents
     this.fetchContents()
       .then((res) => {
@@ -123,21 +177,7 @@ export default class ContentsList extends Component<PropsType, StateType> {
         this.setState({ loading: false, error: true });
       });
 
-    api
-      .detectBuildpack(
-        "<token>",
-        {
-          dir: this.state.currentDir || ".",
-        },
-        {
-          project_id: currentProject.id,
-          git_repo_id: actionConfig.git_repo_id,
-          kind: "github",
-          owner: actionConfig.git_repo.split("/")[0],
-          name: actionConfig.git_repo.split("/")[1],
-          branch: branch,
-        }
-      )
+    this.detectBuildpacks()
       .then(({ data }) => {
         this.setState({
           autoBuildpack: data,
@@ -155,23 +195,9 @@ export default class ContentsList extends Component<PropsType, StateType> {
     let ppath =
       this.props.procfilePath ||
       `${this.state.currentDir ? this.state.currentDir : "."}/Procfile`;
-    api
-      .getProcfileContents(
-        "<token>",
-        {
-          path: ppath,
-        },
-        {
-          project_id: currentProject.id,
-          git_repo_id: actionConfig.git_repo_id,
-          kind: "github",
-          owner: actionConfig.git_repo.split("/")[0],
-          name: actionConfig.git_repo.split("/")[1],
-          branch: branch,
-        }
-      )
-      .then((res) => {
-        this.setState({ processes: res.data });
+    this.fetchProcfileContent(ppath)
+      .then(({ data }) => {
+        this.setState({ processes: data });
       })
       .catch((err) => {
         console.log(err);

+ 23 - 6
dashboard/src/components/repo-selector/RepoList.tsx

@@ -198,19 +198,32 @@ const RepoList: React.FC<Props> = ({
       image_repo_uri: null,
       git_branch: null,
       git_repo_id: 0,
-      gitlab_integration_id: 0,
+      kind: "github",
     });
     setSelectedRepo(null);
   }, [searchFilter]);
 
   const setRepo = (x: RepoType) => {
-    let updatedConfig = actionConfig;
-    updatedConfig.git_repo = x.FullName;
+    let repoConfig: any;
     if (x.Kind === "gitlab") {
-      updatedConfig.gitlab_integration_id = x.GitIntegrationId;
+      repoConfig = {
+        kind: "gitlab",
+        git_repo: x.FullName,
+        gitlab_integration_id: x.GitIntegrationId,
+      };
     } else {
-      updatedConfig.git_repo_id = x.GHRepoID;
+      repoConfig = {
+        kind: "github",
+        git_repo: x.FullName,
+        git_repo_id: x.GHRepoID,
+      };
     }
+
+    const updatedConfig = {
+      ...actionConfig,
+      ...repoConfig,
+    };
+
     setActionConfig(updatedConfig);
     setSelectedRepo(x.FullName);
   };
@@ -277,7 +290,11 @@ const RepoList: React.FC<Props> = ({
             readOnly={readOnly}
             disabled={shouldDisable}
           >
-            <img src={github} alt={"github icon"} />
+            {repo.Kind === "github" ? (
+              <img src={github} alt={"github icon"} />
+            ) : (
+              <i className="devicon-gitlab-plain colored" />
+            )}
             {repo.FullName}
             {shouldDisable && ` - This repo was already added`}
           </RepoName>

+ 26 - 10
dashboard/src/main/home/launch/launch-flow/LaunchFlow.tsx

@@ -34,6 +34,7 @@ const defaultActionConfig: ActionConfigType = {
   image_repo_uri: "",
   git_branch: "",
   git_repo_id: 0,
+  kind: "github",
 };
 
 const LaunchFlow: React.FC<PropsType> = (props) => {
@@ -77,16 +78,31 @@ const LaunchFlow: React.FC<PropsType> = (props) => {
       imageRepoUri = selectedRegistry?.url;
     }
 
-    return {
-      git_repo: actionConfig.git_repo,
-      git_branch: branch,
-      registry_id: selectedRegistry?.id,
-      dockerfile_path: dockerfilePath,
-      folder_path: folderPath,
-      image_repo_uri: imageRepoUri,
-      git_repo_id: actionConfig.git_repo_id,
-      should_create_workflow: shouldCreateWorkflow,
-    };
+    if (actionConfig.kind === "github") {
+      return {
+        kind: "github",
+        git_repo: actionConfig.git_repo,
+        git_branch: branch,
+        registry_id: selectedRegistry?.id,
+        dockerfile_path: dockerfilePath,
+        folder_path: folderPath,
+        image_repo_uri: imageRepoUri,
+        git_repo_id: actionConfig.git_repo_id,
+        should_create_workflow: shouldCreateWorkflow,
+      };
+    } else {
+      return {
+        kind: "gitlab",
+        git_repo: actionConfig.git_repo,
+        git_branch: branch,
+        registry_id: selectedRegistry?.id,
+        dockerfile_path: dockerfilePath,
+        folder_path: folderPath,
+        image_repo_uri: imageRepoUri,
+        gitlab_integration_id: actionConfig.gitlab_integration_id,
+        should_create_workflow: shouldCreateWorkflow,
+      };
+    }
   };
 
   const handleSubmitAddon = async (wildcard?: any) => {

+ 12 - 8
dashboard/src/main/home/launch/launch-flow/SettingsPage.tsx

@@ -156,7 +156,10 @@ class SettingsPage extends Component<PropsType, StateType> {
               // console.log(val);
               onSubmit(val);
             }}
-            hideBottomSpacer={!!this.props.fullActionConfig?.git_repo}
+            hideBottomSpacer={
+              !!this.props.fullActionConfig?.git_repo &&
+              this.props.fullActionConfig?.kind === "github"
+            }
           />
         </FadeWrapper>
       );
@@ -291,13 +294,14 @@ class SettingsPage extends Component<PropsType, StateType> {
             />
           </ClusterSection>
           {this.renderSettingsRegion()}
-          {this.props.fullActionConfig?.git_repo && (
-            <WorkflowPage
-              fullActionConfig={this.props.fullActionConfig}
-              name={this.props.templateName}
-              namespace={this.props.selectedNamespace}
-            />
-          )}
+          {this.props.fullActionConfig?.git_repo &&
+            this.props.fullActionConfig?.kind === "github" && (
+              <WorkflowPage
+                fullActionConfig={this.props.fullActionConfig}
+                name={this.props.templateName}
+                namespace={this.props.selectedNamespace}
+              />
+            )}
         </StyledSettingsPage>
       </PaddingWrapper>
     );

+ 21 - 1
dashboard/src/shared/api.tsx

@@ -444,7 +444,7 @@ const deployTemplate = baseApi<
     image_url?: string;
     values?: any;
     name: string;
-    github_action_config?: FullActionConfigType;
+    git_action_config?: FullActionConfigType;
     build_config?: any;
     synced_env_groups?: string[];
   },
@@ -540,6 +540,25 @@ const getProcfileContents = baseApi<
   }/${encodeURIComponent(pathParams.branch)}/procfile`;
 });
 
+const getGitlabProcfileContents = baseApi<
+  {
+    path: string;
+  },
+  {
+    project_id: number;
+    integration_id: number;
+    owner: string;
+    name: string;
+    branch: string;
+  }
+>(
+  "GET",
+  ({ project_id, integration_id, owner, name, branch }) =>
+    `/projects/${project_id}/integrations/gitlab/${integration_id}/${owner}/${name}/${encodeURIComponent(
+      branch
+    )}/procfile`
+);
+
 const getBranches = baseApi<
   {},
   {
@@ -1955,6 +1974,7 @@ export default {
   getOAuthIds,
   getPodEvents,
   getProcfileContents,
+  getGitlabProcfileContents,
   getProjectClusters,
   getProjectRegistries,
   getProjectRepos,

+ 10 - 3
dashboard/src/shared/types.tsx

@@ -286,9 +286,16 @@ export type ActionConfigType = {
   git_repo: string;
   git_branch: string;
   image_repo_uri: string;
-  git_repo_id?: number;
-  gitlab_integration_id?: number;
-};
+} & (
+  | {
+      kind: "gitlab";
+      gitlab_integration_id: number;
+    }
+  | {
+      kind: "github";
+      git_repo_id: number;
+    }
+);
 
 export type FullActionConfigType = ActionConfigType & {
   dockerfile_path: string;