Kaynağa Gözat

make GH environments API creation a non-fatal operation

Alexander Belanger 4 yıl önce
ebeveyn
işleme
945637f98d
1 değiştirilmiş dosya ile 5 ekleme ve 9 silme
  1. 5 9
      internal/integrations/ci/actions/preview.go

+ 5 - 9
internal/integrations/ci/actions/preview.go

@@ -21,7 +21,9 @@ type EnvOpts struct {
 }
 
 func SetupEnv(opts *EnvOpts) error {
-	// create Github environment if it does not exist
+	// make a best-effort to create a Github environment. this is a non-fatal operation,
+	// as the environments API is not enabled for private repositories that don't have
+	// github enterprise.
 	_, resp, err := opts.Client.Repositories.GetEnvironment(
 		context.Background(),
 		opts.GitRepoOwner,
@@ -29,20 +31,14 @@ func SetupEnv(opts *EnvOpts) error {
 		opts.EnvironmentName,
 	)
 
-	if resp.StatusCode == http.StatusNotFound {
-		_, _, err := opts.Client.Repositories.CreateUpdateEnvironment(
+	if resp != nil && resp.StatusCode == http.StatusNotFound {
+		opts.Client.Repositories.CreateUpdateEnvironment(
 			context.Background(),
 			opts.GitRepoOwner,
 			opts.GitRepoName,
 			opts.EnvironmentName,
 			nil,
 		)
-
-		if err != nil {
-			return err
-		}
-	} else if err != nil {
-		return err
 	}
 
 	// create porter token secret