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

Merge pull request #1139 from porter-dev/delete-nondefaultbranch-hotfix

[0.9.0] fix error on trying to delete charts on non-default github branches
abelanger5 4 лет назад
Родитель
Сommit
4f68898601
1 измененных файлов с 10 добавлено и 4 удалено
  1. 10 4
      internal/integrations/ci/actions/actions.go

+ 10 - 4
internal/integrations/ci/actions/actions.go

@@ -415,25 +415,31 @@ 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
 	}
 
 	opts := &github.RepositoryContentFileOptions{
 		Message: github.String(fmt.Sprintf("Delete %s file", filename)),
-		Branch:  github.String(g.defaultBranch),
+		Branch:  &branch,
 		SHA:     &sha,
 	}