Explorar o código

Merge pull request #640 from porter-dev/0.3.0-gha-branch-write

[0.3.0] Fix GHA writing to non-default branch
abelanger5 %!s(int64=5) %!d(string=hai) anos
pai
achega
acbd59f4e3
Modificáronse 1 ficheiros con 10 adicións e 2 borrados
  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"),