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

Merge branch 'nafees/preview-env-improvements' into dev

Mohammed Nafees 3 лет назад
Родитель
Сommit
1a2bf3507f

+ 0 - 3
api/server/handlers/environment/list_deployments_by_cluster.go

@@ -238,12 +238,9 @@ func fetchOpenPullRequests(
 	branchesMap := make(map[string]bool)
 
 	for _, br := range env.ToEnvironmentType().GitRepoBranches {
-		fmt.Printf("branch: %s\n", br)
 		branchesMap[br] = true
 	}
 
-	fmt.Printf("branchesMap: %v\n", branchesMap)
-
 	openPRs, resp, err := client.PullRequests.List(ctx, env.GitRepoOwner, env.GitRepoName,
 		&github.PullRequestListOptions{
 			ListOptions: github.ListOptions{

+ 19 - 1
internal/models/environment.go

@@ -31,6 +31,24 @@ type Environment struct {
 	GithubWebhookID int64
 }
 
+func getGitRepoBranches(branches string) []string {
+	var branchesArr []string
+
+	if branches != "" {
+		supposedBranches := strings.Split(branches, ",")
+
+		for _, br := range supposedBranches {
+			name := strings.TrimSpace(br)
+
+			if len(name) > 0 {
+				branchesArr = append(branchesArr, name)
+			}
+		}
+	}
+
+	return branchesArr
+}
+
 func (e *Environment) ToEnvironmentType() *types.Environment {
 	return &types.Environment{
 		ID:                e.Model.ID,
@@ -39,7 +57,7 @@ func (e *Environment) ToEnvironmentType() *types.Environment {
 		GitInstallationID: e.GitInstallationID,
 		GitRepoOwner:      e.GitRepoOwner,
 		GitRepoName:       e.GitRepoName,
-		GitRepoBranches:   strings.Split(e.GitRepoBranches, ","),
+		GitRepoBranches:   getGitRepoBranches(e.GitRepoBranches),
 
 		NewCommentsDisabled: e.NewCommentsDisabled,