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

write to correct github branch

Alexander Belanger 5 лет назад
Родитель
Сommit
8bae3931bf
1 измененных файлов с 10 добавлено и 2 удалено
  1. 10 2
      internal/integrations/ci/actions/actions.go

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

@@ -324,13 +324,21 @@ func (g *GithubActions) commitGithubFile(
 	filepath := ".github/workflows/" + filename
 	sha := ""
 
+	branch := g.GitBranch
+
+	if branch == "" {
+		branch = g.defaultBranch
+	}
+
 	// 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,
+		},
 	)
 
 	if fileData != nil {
@@ -340,7 +348,7 @@ func (g *GithubActions) commitGithubFile(
 	opts := &github.RepositoryContentFileOptions{
 		Message: github.String(fmt.Sprintf("Create %s file", filename)),
 		Content: contents,
-		Branch:  github.String(g.defaultBranch),
+		Branch:  github.String(branch),
 		SHA:     &sha,
 		Committer: &github.CommitAuthor{
 			Name:  github.String("Porter Bot"),