@@ -50,20 +50,22 @@ type commandRunner struct {
5050 image string
5151}
5252
53+ const defaultAPISourceBranch = "master"
54+
5355func newCommandRunner (cfg * config.Config ) (* commandRunner , error ) {
5456 if cfg .APISource == "" {
5557 cfg .APISource = "https://github.com/googleapis/googleapis"
5658 }
5759
58- languageRepo , err := cloneOrOpenRepo (cfg .WorkRoot , cfg .Repo , cfg .CI , cfg .GitHubToken )
60+ languageRepo , err := cloneOrOpenRepo (cfg .WorkRoot , cfg .Repo , cfg .Branch , cfg . CI , cfg .GitHubToken )
5961 if err != nil {
6062 return nil , err
6163 }
6264
6365 var sourceRepo gitrepo.Repository
6466 var sourceRepoDir string
6567 if cfg .CommandName == generateCmdName {
66- sourceRepo , err = cloneOrOpenRepo (cfg .WorkRoot , cfg .APISource , cfg .CI , cfg .GitHubToken )
68+ sourceRepo , err = cloneOrOpenRepo (cfg .WorkRoot , cfg .APISource , defaultAPISourceBranch , cfg .CI , cfg .GitHubToken )
6769 if err != nil {
6870 return nil , err
6971 }
@@ -115,7 +117,7 @@ func newCommandRunner(cfg *config.Config) (*commandRunner, error) {
115117 }, nil
116118}
117119
118- func cloneOrOpenRepo (workRoot , repo , ci string , gitPassword string ) (* gitrepo.LocalRepository , error ) {
120+ func cloneOrOpenRepo (workRoot , repo , branch , ci string , gitPassword string ) (* gitrepo.LocalRepository , error ) {
119121 if repo == "" {
120122 return nil , errors .New ("repo must be specified" )
121123 }
@@ -127,11 +129,12 @@ func cloneOrOpenRepo(workRoot, repo, ci string, gitPassword string) (*gitrepo.Lo
127129 repoName := path .Base (strings .TrimSuffix (repo , "/" ))
128130 repoPath := filepath .Join (workRoot , repoName )
129131 return gitrepo .NewRepository (& gitrepo.RepositoryOptions {
130- Dir : repoPath ,
131- MaybeClone : true ,
132- RemoteURL : repo ,
133- CI : ci ,
134- GitPassword : gitPassword ,
132+ Dir : repoPath ,
133+ MaybeClone : true ,
134+ RemoteURL : repo ,
135+ RemoteBranch : branch ,
136+ CI : ci ,
137+ GitPassword : gitPassword ,
135138 })
136139 }
137140 // repo is a directory
@@ -364,7 +367,7 @@ func commitAndPush(ctx context.Context, cfg *config.Config, repo gitrepo.Reposit
364367 titlePrefix := "Librarian pull request"
365368 title := fmt .Sprintf ("%s: %s" , titlePrefix , datetimeNow )
366369 slog .Info ("Creating pull request" , slog .String ("branch" , branch ), slog .String ("title" , title ))
367- if _ , err = ghClient .CreatePullRequest (ctx , gitHubRepo , branch , title , commitMessage ); err != nil {
370+ if _ , err = ghClient .CreatePullRequest (ctx , gitHubRepo , branch , cfg . Branch , title , commitMessage ); err != nil {
368371 return fmt .Errorf ("failed to create pull request: %w" , err )
369372 }
370373 return nil
0 commit comments