Răsfoiți Sursa

Merge pull request #1335 from porter-dev/belanger/por-130-save-gha-on-error

[POR-130] Save GitActionConfig, even when there's a Github error, and query latest release
abelanger5 4 ani în urmă
părinte
comite
1ad7017b17
2 a modificat fișierele cu 18 adăugiri și 11 ștergeri
  1. 17 10
      api/server/handlers/release/create.go
  2. 1 1
      internal/repository/gorm/release.go

+ 17 - 10
api/server/handlers/release/create.go

@@ -259,23 +259,26 @@ func createGitAction(
 		DryRun:                 release == nil,
 	}
 
-	workflowYAML, err := gaRunner.Setup()
-
-	if err != nil {
-		return nil, nil, err
-	}
+	// Save the github err for after creating the git action config. However, we
+	// need to call Setup() in order to get the workflow file before writing the
+	// action config, in the case of a dry run, since the dry run does not create
+	// a git action config.
+	workflowYAML, githubErr := gaRunner.Setup()
 
 	if gaRunner.DryRun {
+		if githubErr != nil {
+			return nil, nil, githubErr
+		}
+
 		return nil, workflowYAML, nil
 	}
 
 	// handle write to the database
 	ga, err := config.Repo.GitActionConfig().CreateGitActionConfig(&models.GitActionConfig{
-		ReleaseID:    release.ID,
-		GitRepo:      request.GitRepo,
-		GitBranch:    request.GitBranch,
-		ImageRepoURI: request.ImageRepoURI,
-		// TODO: github installation id here?
+		ReleaseID:      release.ID,
+		GitRepo:        request.GitRepo,
+		GitBranch:      request.GitBranch,
+		ImageRepoURI:   request.ImageRepoURI,
 		GitRepoID:      request.GitRepoID,
 		DockerfilePath: request.DockerfilePath,
 		FolderPath:     request.FolderPath,
@@ -296,6 +299,10 @@ func createGitAction(
 		return nil, nil, err
 	}
 
+	if githubErr != nil {
+		return nil, nil, githubErr
+	}
+
 	return ga.ToGitActionConfigType(), workflowYAML, nil
 }
 

+ 1 - 1
internal/repository/gorm/release.go

@@ -28,7 +28,7 @@ func (repo *ReleaseRepository) CreateRelease(release *models.Release) (*models.R
 // ReadRelease finds a single release based on their unique name and namespace pair.
 func (repo *ReleaseRepository) ReadRelease(clusterID uint, name, namespace string) (*models.Release, error) {
 	release := &models.Release{}
-	if err := repo.db.Preload("GitActionConfig").Where("cluster_id = ?", clusterID).Where("name = ?", name).Where("namespace = ?", namespace).First(&release).Error; err != nil {
+	if err := repo.db.Preload("GitActionConfig").Order("id desc").Where("cluster_id = ? AND name = ? AND namespace = ?", clusterID, name, namespace).First(&release).Error; err != nil {
 		return nil, err
 	}
 	return release, nil