Ver Fonte

use branch to also get filedata

Anukul Sangwan há 4 anos atrás
pai
commit
d34db0db46
1 ficheiros alterados com 9 adições e 9 exclusões
  1. 9 9
      internal/integrations/ci/actions/actions.go

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

@@ -415,28 +415,28 @@ func (g *GithubActions) deleteGithubFile(
 	client *github.Client,
 	filename string,
 ) error {
-	filepath := ".github/workflows/" + filename
-	sha := ""
+	branch := g.GitBranch
+	if branch == "" {
+		branch = g.defaultBranch
+	}
 
+	filepath := ".github/workflows/" + filename
 	// get contents of a file if it exists
 	fileData, _, _, _ := client.Repositories.GetContents(
 		context.TODO(),
 		g.GitRepoOwner,
 		g.GitRepoName,
 		filepath,
-		&github.RepositoryContentGetOptions{},
+		&github.RepositoryContentGetOptions{
+			Ref: branch,
+		},
 	)
 
+	sha := ""
 	if fileData != nil {
 		sha = *fileData.SHA
 	}
 
-	branch := g.GitBranch
-
-	if branch == "" {
-		branch = g.defaultBranch
-	}
-
 	opts := &github.RepositoryContentFileOptions{
 		Message: github.String(fmt.Sprintf("Delete %s file", filename)),
 		Branch:  &branch,