Переглянути джерело

add rules to gitlab ci job

Mohammed Nafees 4 роки тому
батько
коміт
5f351399d1

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

@@ -297,6 +297,7 @@ func createGitAction(
 			ServerURL:        config.ServerConf.ServerURL,
 			GitRepoOwner:     repoSplit[0],
 			GitRepoName:      repoSplit[1],
+			GitBranch:        request.GitBranch,
 			Repo:             config.Repo,
 			ProjectID:        projectID,
 			ClusterID:        clusterID,

+ 6 - 0
internal/integrations/ci/gitlab/ci.go

@@ -17,6 +17,7 @@ type GitlabCI struct {
 	ServerURL    string
 	GitRepoName  string
 	GitRepoOwner string
+	GitBranch    string
 
 	Repo repository.Repository
 
@@ -261,6 +262,11 @@ func (g *GitlabCI) getCIJob(jobName string) map[string]interface{} {
 		"variables": map[string]string{
 			"GIT_STRATEGY": "clone",
 		},
+		"rules": []map[string]string{
+			{
+				"if": fmt.Sprintf("$CI_COMMIT_BRANCH == \"%s\" && $CI_PIPELINE_SOURCE == \"push\"", g.GitBranch),
+			},
+		},
 		"script": []string{
 			fmt.Sprintf("export PORTER_HOST=\"%s\"", g.ServerURL),
 			fmt.Sprintf("export PORTER_PROJECT=\"%d\"", g.ProjectID),

+ 8 - 2
internal/repository/gorm/auth.go

@@ -1666,7 +1666,7 @@ func (repo *GitlabIntegrationRepository) ReadGitlabIntegration(projectID, id uin
 func (repo *GitlabIntegrationRepository) ListGitlabIntegrationsByProjectID(projectID uint) ([]*ints.GitlabIntegration, error) {
 	gi := []*ints.GitlabIntegration{}
 
-	if err := repo.db.Where("project_id = ?", projectID).Find(&gi).Error; err != nil {
+	if err := repo.db.Where("project_id = ? AND deleted_at IS NULL", projectID).Find(&gi).Error; err != nil {
 		return nil, err
 	}
 
@@ -1780,7 +1780,13 @@ func (repo *GitlabAppOAuthIntegrationRepository) ReadGitlabAppOAuthIntegration(
 ) (*ints.GitlabAppOAuthIntegration, error) {
 	gi := &ints.GitlabAppOAuthIntegration{}
 
-	if err := repo.db.Where("user_id = ? AND project_id = ? AND integration_id = ?", userID, projectID, integrationID).First(&gi).Error; err != nil {
+	if err := repo.db.
+		Order("gitlab_app_o_auth_integrations.id desc").
+		Joins("INNER JOIN gitlab_integrations ON gitlab_integrations.id = gitlab_app_o_auth_integrations.integration_id").
+		Where("gitlab_app_o_auth_integrations.user_id = ? AND gitlab_app_o_auth_integrations.project_id = ? AND"+
+			" gitlab_integrations.integration_id = ? AND gitlab_integrations.deleted_at IS NULL AND"+
+			" gitlab_app_o_auth_integrations.deleted_at IS NULL",
+			userID, projectID, integrationID).First(&gi).Error; err != nil {
 		return nil, err
 	}