소스 검색

Merge branch 'gitlab-integration' of github.com:porter-dev/porter into gitlab-integration

jnfrati 4 년 전
부모
커밋
b83ae3982a

+ 1 - 9
api/server/handlers/release/create.go

@@ -47,7 +47,6 @@ func NewCreateReleaseHandler(
 
 func (c *CreateReleaseHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
 	user, _ := r.Context().Value(types.UserScope).(*models.User)
-	proj, _ := r.Context().Value(types.ProjectScope).(*models.Project)
 	cluster, _ := r.Context().Value(types.ClusterScope).(*models.Cluster)
 	namespace := r.Context().Value(types.NamespaceScope).(string)
 	operationID := oauth.CreateRandomState()
@@ -167,7 +166,6 @@ func (c *CreateReleaseHandler) ServeHTTP(w http.ResponseWriter, r *http.Request)
 	if request.GitActionConfig != nil {
 		_, _, err := createGitAction(
 			c.Config(),
-			proj,
 			user.ID,
 			cluster.ProjectID,
 			cluster.ID,
@@ -246,7 +244,6 @@ func createReleaseFromHelmRelease(
 
 func createGitAction(
 	config *config.Config,
-	project *models.Project,
 	userID, projectID, clusterID uint,
 	request *types.CreateGitActionConfigRequest,
 	name, namespace string,
@@ -288,7 +285,7 @@ func createGitAction(
 
 	// if this isn't a dry run, generate the token
 	if !isDryRun {
-		encoded, err = getToken(config, project, userID, projectID, clusterID, request)
+		encoded, err = getToken(config, userID, projectID, clusterID, request)
 
 		if err != nil {
 			return nil, nil, err
@@ -394,7 +391,6 @@ func createGitAction(
 
 func getToken(
 	config *config.Config,
-	proj *models.Project,
 	userID, projectID, clusterID uint,
 	request *types.CreateGitActionConfigRequest,
 ) (string, error) {
@@ -480,10 +476,6 @@ func getToken(
 		SecretKey:       hashedToken,
 	}
 
-	if !proj.APITokensEnabled {
-		return "", fmt.Errorf("api tokens are not enabled for this project")
-	}
-
 	apiToken, err = config.Repo.APIToken().CreateAPIToken(apiToken)
 
 	if err != nil {

+ 0 - 2
api/server/handlers/release/get_gha_template.go

@@ -27,7 +27,6 @@ func NewGetGHATemplateHandler(
 
 func (c *GetGHATemplateHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
 	user, _ := r.Context().Value(types.UserScope).(*models.User)
-	proj, _ := r.Context().Value(types.ProjectScope).(*models.Project)
 	cluster, _ := r.Context().Value(types.ClusterScope).(*models.Cluster)
 	namespace := r.Context().Value(types.NamespaceScope).(string)
 
@@ -39,7 +38,6 @@ func (c *GetGHATemplateHandler) ServeHTTP(w http.ResponseWriter, r *http.Request
 
 	_, workflowYAML, err := createGitAction(
 		c.Config(),
-		proj,
 		user.ID,
 		cluster.ProjectID,
 		cluster.ID,

+ 2 - 2
dashboard/src/main/home/WelcomeForm.tsx

@@ -46,10 +46,10 @@ const WelcomeForm: React.FunctionComponent<Props> = ({}) => {
           <Title>Welcome to Porter</Title>
           <Subtitle>Just two things before getting started.</Subtitle>
           <SubtitleAlt>
-            <Num>1</Num> What is your company name? *
+            <Num>1</Num> What is your company website? *
           </SubtitleAlt>
           <Input
-            placeholder="ex: Acme"
+            placeholder="ex: https://porter.run"
             value={company}
             onChange={(e: any) => setCompany(e.target.value)}
           />

+ 132 - 129
internal/integrations/buildpacks/nodejs.go

@@ -440,135 +440,138 @@ func (runtime *nodejsRuntime) DetectGitlab(
 		return nil
 	}
 
-	foundYarn := false
-	foundNPM := false
-	foundStandalone := false
-	for result := range results {
-		if result.string == yarn {
-			foundYarn = true
-		} else if result.string == npm {
-			foundNPM = true
-		} else if result.string == standalone {
-			foundStandalone = true
-		}
-	}
-
-	if foundYarn || foundNPM {
-		// it is safe to assume that the project contains a package.json
-		fileContent, _, err := client.RepositoryFiles.GetRawFile(
-			fmt.Sprintf("%s/%s", owner, name), fmt.Sprintf("%s/package.json", path),
-			&gitlab.GetRawFileOptions{
-				Ref: gitlab.String(ref),
-			},
-		)
-		if err != nil {
-			paketo.Others = append(paketo.Others, paketoBuildpackInfo)
-			heroku.Others = append(heroku.Others, herokuBuildpackInfo)
-			return fmt.Errorf("error fetching contents of package.json: %v", err)
-		}
-		var packageJSON struct {
-			Scripts map[string]string `json:"scripts"`
-			Engines struct {
-				Node string `json:"node"`
-			} `json:"engines"`
-		}
-
-		data := string(fileContent)
-
-		err = json.NewDecoder(strings.NewReader(data)).Decode(&packageJSON)
-		if err != nil {
-			paketo.Others = append(paketo.Others, paketoBuildpackInfo)
-			heroku.Others = append(heroku.Others, herokuBuildpackInfo)
-			return fmt.Errorf("error decoding package.json contents to struct: %v", err)
-		}
-
-		if packageJSON.Engines.Node == "" {
-			// we should now check for the node engine version in .nvmrc and then .node-version
-			nvmrcFound := false
-			nodeVersionFound := false
-			for i := 0; i < len(tree); i++ {
-				name := tree[i].Name
-				if name == ".nvmrc" {
-					nvmrcFound = true
-				} else if name == ".node-version" {
-					nodeVersionFound = true
-				}
-			}
-
-			if nvmrcFound {
-				// copy exact behavior of https://github.com/paketo-buildpacks/node-engine/blob/main/nvmrc_parser.go
-				fileContent, _, err = client.RepositoryFiles.GetRawFile(
-					fmt.Sprintf("%s/%s", owner, name), fmt.Sprintf("%s/.nvmrc", path),
-					&gitlab.GetRawFileOptions{
-						Ref: gitlab.String(ref),
-					},
-				)
-				if err != nil {
-					paketo.Others = append(paketo.Others, paketoBuildpackInfo)
-					heroku.Others = append(heroku.Others, herokuBuildpackInfo)
-					return fmt.Errorf("error fetching contents of .nvmrc: %v", err)
-				}
-				data = string(fileContent)
-
-				nvmrcVersion, err := validateNvmrc(data)
-				if err != nil {
-					paketo.Others = append(paketo.Others, paketoBuildpackInfo)
-					heroku.Others = append(heroku.Others, herokuBuildpackInfo)
-					return fmt.Errorf("error validating .nvmrc: %v", err)
-				}
-				nvmrcVersion = formatNvmrcContent(nvmrcVersion)
-
-				if nvmrcVersion != "*" {
-					packageJSON.Engines.Node = data
-				}
-			}
-
-			if packageJSON.Engines.Node == "" && nodeVersionFound {
-				// copy exact behavior of https://github.com/paketo-buildpacks/node-engine/blob/main/node_version_parser.go
-				fileContent, _, err = client.RepositoryFiles.GetRawFile(
-					fmt.Sprintf("%s/%s", owner, name), fmt.Sprintf("%s/.node-version", path),
-					&gitlab.GetRawFileOptions{
-						Ref: gitlab.String(ref),
-					},
-				)
-				if err != nil {
-					paketo.Others = append(paketo.Others, paketoBuildpackInfo)
-					heroku.Others = append(heroku.Others, herokuBuildpackInfo)
-					return fmt.Errorf("error fetching contents of .node-version: %v", err)
-				}
-
-				data = string(fileContent)
-
-				nodeVersion, err := validateNodeVersion(data)
-				if err != nil {
-					paketo.Others = append(paketo.Others, paketoBuildpackInfo)
-					heroku.Others = append(heroku.Others, herokuBuildpackInfo)
-					return fmt.Errorf("error validating .node-version: %v", err)
-				}
-				if nodeVersion != "" {
-					packageJSON.Engines.Node = nodeVersion
-				}
-			}
-		}
-
-		if packageJSON.Engines.Node == "" {
-			// use the default node engine version from https://github.com/paketo-buildpacks/node-engine/blob/main/buildpack.toml
-			packageJSON.Engines.Node = "16.*.*"
-		}
-
-		paketoBuildpackInfo.Config = make(map[string]interface{})
-		paketoBuildpackInfo.Config["scripts"] = packageJSON.Scripts
-		paketoBuildpackInfo.Config["node_engine"] = packageJSON.Engines.Node
-		paketo.Detected = append(paketo.Detected, paketoBuildpackInfo)
-
-		herokuBuildpackInfo.Config = make(map[string]interface{})
-		herokuBuildpackInfo.Config["scripts"] = packageJSON.Scripts
-		herokuBuildpackInfo.Config["node_engine"] = packageJSON.Engines.Node
-		heroku.Detected = append(heroku.Detected, herokuBuildpackInfo)
-	} else if foundStandalone {
-		paketo.Detected = append(paketo.Detected, paketoBuildpackInfo)
-		heroku.Detected = append(heroku.Detected, herokuBuildpackInfo)
-	}
+	// foundYarn := false
+	// foundNPM := false
+	// foundStandalone := false
+	// for result := range results {
+	// 	if result.string == yarn {
+	// 		foundYarn = true
+	// 	} else if result.string == npm {
+	// 		foundNPM = true
+	// 	} else if result.string == standalone {
+	// 		foundStandalone = true
+	// 	}
+	// }
+
+	paketo.Detected = append(paketo.Detected, paketoBuildpackInfo)
+	heroku.Detected = append(heroku.Detected, herokuBuildpackInfo)
+
+	// if foundYarn || foundNPM {
+	// 	// it is safe to assume that the project contains a package.json
+	// 	fileContent, _, err := client.RepositoryFiles.GetRawFile(
+	// 		fmt.Sprintf("%s/%s", owner, name), fmt.Sprintf("%s/package.json", path),
+	// 		&gitlab.GetRawFileOptions{
+	// 			Ref: gitlab.String(ref),
+	// 		},
+	// 	)
+	// 	if err != nil {
+	// 		paketo.Others = append(paketo.Others, paketoBuildpackInfo)
+	// 		heroku.Others = append(heroku.Others, herokuBuildpackInfo)
+	// 		return fmt.Errorf("error fetching contents of package.json: %v", err)
+	// 	}
+	// 	var packageJSON struct {
+	// 		Scripts map[string]string `json:"scripts"`
+	// 		Engines struct {
+	// 			Node string `json:"node"`
+	// 		} `json:"engines"`
+	// 	}
+
+	// 	data := string(fileContent)
+
+	// 	err = json.NewDecoder(strings.NewReader(data)).Decode(&packageJSON)
+	// 	if err != nil {
+	// 		paketo.Others = append(paketo.Others, paketoBuildpackInfo)
+	// 		heroku.Others = append(heroku.Others, herokuBuildpackInfo)
+	// 		return fmt.Errorf("error decoding package.json contents to struct: %v", err)
+	// 	}
+
+	// 	if packageJSON.Engines.Node == "" {
+	// 		// we should now check for the node engine version in .nvmrc and then .node-version
+	// 		nvmrcFound := false
+	// 		nodeVersionFound := false
+	// 		for i := 0; i < len(tree); i++ {
+	// 			name := tree[i].Name
+	// 			if name == ".nvmrc" {
+	// 				nvmrcFound = true
+	// 			} else if name == ".node-version" {
+	// 				nodeVersionFound = true
+	// 			}
+	// 		}
+
+	// 		if nvmrcFound {
+	// 			// copy exact behavior of https://github.com/paketo-buildpacks/node-engine/blob/main/nvmrc_parser.go
+	// 			fileContent, _, err = client.RepositoryFiles.GetRawFile(
+	// 				fmt.Sprintf("%s/%s", owner, name), fmt.Sprintf("%s/.nvmrc", path),
+	// 				&gitlab.GetRawFileOptions{
+	// 					Ref: gitlab.String(ref),
+	// 				},
+	// 			)
+	// 			if err != nil {
+	// 				paketo.Others = append(paketo.Others, paketoBuildpackInfo)
+	// 				heroku.Others = append(heroku.Others, herokuBuildpackInfo)
+	// 				return fmt.Errorf("error fetching contents of .nvmrc: %v", err)
+	// 			}
+	// 			data = string(fileContent)
+
+	// 			nvmrcVersion, err := validateNvmrc(data)
+	// 			if err != nil {
+	// 				paketo.Others = append(paketo.Others, paketoBuildpackInfo)
+	// 				heroku.Others = append(heroku.Others, herokuBuildpackInfo)
+	// 				return fmt.Errorf("error validating .nvmrc: %v", err)
+	// 			}
+	// 			nvmrcVersion = formatNvmrcContent(nvmrcVersion)
+
+	// 			if nvmrcVersion != "*" {
+	// 				packageJSON.Engines.Node = data
+	// 			}
+	// 		}
+
+	// 		if packageJSON.Engines.Node == "" && nodeVersionFound {
+	// 			// copy exact behavior of https://github.com/paketo-buildpacks/node-engine/blob/main/node_version_parser.go
+	// 			fileContent, _, err = client.RepositoryFiles.GetRawFile(
+	// 				fmt.Sprintf("%s/%s", owner, name), fmt.Sprintf("%s/.node-version", path),
+	// 				&gitlab.GetRawFileOptions{
+	// 					Ref: gitlab.String(ref),
+	// 				},
+	// 			)
+	// 			if err != nil {
+	// 				paketo.Others = append(paketo.Others, paketoBuildpackInfo)
+	// 				heroku.Others = append(heroku.Others, herokuBuildpackInfo)
+	// 				return fmt.Errorf("error fetching contents of .node-version: %v", err)
+	// 			}
+
+	// 			data = string(fileContent)
+
+	// 			nodeVersion, err := validateNodeVersion(data)
+	// 			if err != nil {
+	// 				paketo.Others = append(paketo.Others, paketoBuildpackInfo)
+	// 				heroku.Others = append(heroku.Others, herokuBuildpackInfo)
+	// 				return fmt.Errorf("error validating .node-version: %v", err)
+	// 			}
+	// 			if nodeVersion != "" {
+	// 				packageJSON.Engines.Node = nodeVersion
+	// 			}
+	// 		}
+	// 	}
+
+	// 	if packageJSON.Engines.Node == "" {
+	// 		// use the default node engine version from https://github.com/paketo-buildpacks/node-engine/blob/main/buildpack.toml
+	// 		packageJSON.Engines.Node = "16.*.*"
+	// 	}
+
+	// 	paketoBuildpackInfo.Config = make(map[string]interface{})
+	// 	paketoBuildpackInfo.Config["scripts"] = packageJSON.Scripts
+	// 	paketoBuildpackInfo.Config["node_engine"] = packageJSON.Engines.Node
+	// 	paketo.Detected = append(paketo.Detected, paketoBuildpackInfo)
+
+	// 	herokuBuildpackInfo.Config = make(map[string]interface{})
+	// 	herokuBuildpackInfo.Config["scripts"] = packageJSON.Scripts
+	// 	herokuBuildpackInfo.Config["node_engine"] = packageJSON.Engines.Node
+	// 	heroku.Detected = append(heroku.Detected, herokuBuildpackInfo)
+	// } else if foundStandalone {
+	// 	paketo.Detected = append(paketo.Detected, paketoBuildpackInfo)
+	// 	heroku.Detected = append(heroku.Detected, herokuBuildpackInfo)
+	// }
 
 	return nil
 }

+ 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)