Просмотр исходного кода

Merge branch 'gitlab-integration' into dev

Mohammed Nafees 4 лет назад
Родитель
Сommit
4e716ea0b8

+ 17 - 2
api/server/handlers/project_integration/get_gitlab_repo_buildpack.go

@@ -4,6 +4,8 @@ import (
 	"errors"
 	"fmt"
 	"net/http"
+	"net/url"
+	"strings"
 	"sync"
 
 	"github.com/porter-dev/porter/api/server/handlers"
@@ -115,8 +117,21 @@ func (p *GetGitlabRepoBuildpackHandler) ServeHTTP(w http.ResponseWriter, r *http
 		return
 	}
 
+	dir, err := url.QueryUnescape(request.Dir)
+
+	if err != nil {
+		p.HandleAPIError(w, r, apierrors.NewErrForbidden(fmt.Errorf("malformed query param dir")))
+		return
+	}
+
+	dir = strings.TrimPrefix(dir, "./")
+
+	if len(dir) == 0 {
+		dir = "."
+	}
+
 	tree, resp, err := client.Repositories.ListTree(fmt.Sprintf("%s/%s", owner, name), &gitlab.ListTreeOptions{
-		Path: gitlab.String(request.Dir),
+		Path: gitlab.String(dir),
 		Ref:  gitlab.String(branch),
 	})
 
@@ -145,7 +160,7 @@ func (p *GetGitlabRepoBuildpackHandler) ServeHTTP(w http.ResponseWriter, r *http
 				}
 			}()
 			buildpacks.Runtimes[idx].DetectGitlab(
-				client, tree, owner, name, request.Dir, branch,
+				client, tree, owner, name, dir, branch,
 				builderInfoMap[buildpacks.PaketoBuilder], builderInfoMap[buildpacks.HerokuBuilder],
 			)
 			wg.Done()

+ 22 - 11
dashboard/src/components/repo-selector/ContentsList.tsx

@@ -68,17 +68,28 @@ export default class ContentsList extends Component<PropsType, StateType> {
     const { actionConfig, branch } = this.props;
 
     if (actionConfig.kind === "gitlab") {
-      return api.getGitlabFolderContent(
-        "<token>",
-        { dir: this.state.currentDir || "./" },
-        {
-          project_id: currentProject.id,
-          integration_id: actionConfig.gitlab_integration_id,
-          repo_owner: actionConfig.git_repo.split("/")[0],
-          repo_name: actionConfig.git_repo.split("/")[1],
-          branch: branch,
-        }
-      );
+      return api
+        .getGitlabFolderContent(
+          "<token>",
+          { dir: this.state.currentDir || "./" },
+          {
+            project_id: currentProject.id,
+            integration_id: actionConfig.gitlab_integration_id,
+            repo_owner: actionConfig.git_repo.split("/")[0],
+            repo_name: actionConfig.git_repo.split("/")[1],
+            branch: branch,
+          }
+        )
+        .then((res) => {
+          const { data } = res;
+
+          return {
+            data: data.map((x: FileType) => ({
+              ...x,
+              type: x.type === "tree" ? "dir" : "file",
+            })),
+          };
+        });
     }
     return api.getBranchContents(
       "<token>",

+ 9 - 4
internal/integrations/ci/gitlab/ci.go

@@ -102,16 +102,21 @@ func (g *GitlabCI) Setup() error {
 			return fmt.Errorf("error unmarshalling existing .gitlab-ci.yml: %w", err)
 		}
 
-		stages, ok := ciFileContentsMap["stages"].([]string)
+		stages, ok := ciFileContentsMap["stages"].([]interface{})
 
 		if !ok {
-			return fmt.Errorf("error converting stages to string slice")
+			return fmt.Errorf("error converting stages to interface slice")
 		}
 
 		stageExists := false
 
 		for _, stage := range stages {
-			if stage == jobName {
+			stageStr, ok := stage.(string)
+			if !ok {
+				return fmt.Errorf("error converting from interface to string")
+			}
+
+			if stageStr == jobName {
 				stageExists = true
 				break
 			}
@@ -209,7 +214,7 @@ func (g *GitlabCI) Cleanup() error {
 		}
 	}
 
-	ciFileContentsMap["stage"] = newStages
+	ciFileContentsMap["stages"] = newStages
 
 	delete(ciFileContentsMap, jobName)