@@ -105,7 +105,7 @@ func processRepo(ctx context.Context, repoName, repoDir, librarianBin string, ve
105105 err = cerr
106106 }
107107 }()
108- if err := cloneRepo (ctx , repoDir , repoName ); err != nil {
108+ if err := cloneRepoInDir (ctx , repoName , repoDir ); err != nil {
109109 return err
110110 }
111111 }
@@ -117,8 +117,7 @@ func processRepo(ctx context.Context, repoName, repoDir, librarianBin string, ve
117117 return fmt .Errorf ("failed to change directory to %q: %w" , repoDir , err )
118118 }
119119 defer os .Chdir (originalWD )
120-
121- if err := createBranch (ctx , time .Now ()); err != nil {
120+ if err := createBranch (ctx , generateBranchName (branchPrefix , time .Now ())); err != nil {
122121 return err
123122 }
124123 cfg , err := yaml.Read [config.Config ]("librarian.yaml" )
@@ -157,48 +156,33 @@ func processRepo(ctx context.Context, repoName, repoDir, librarianBin string, ve
157156 return err
158157 }
159158 }
160- if err := commitChanges (ctx ); err != nil {
159+ if err := commitChanges (ctx , commitTitle ); err != nil {
161160 return err
162161 }
163162 if repoName != repoFake {
164- if err := pushBranch (ctx ); err != nil {
163+ if err := pushChanges (ctx ); err != nil {
165164 return err
166165 }
167- if err := createPR (ctx , repoName ); err != nil {
166+ if err := createPR (ctx , createGithubDetails ( repoName ) ); err != nil {
168167 return err
169168 }
170169 }
171170 return nil
172171}
173172
174- func cloneRepo (ctx context.Context , repoDir , repoName string ) error {
175- return command .Run (ctx , "gh" , "repo" , "clone" , fmt .Sprintf ("googleapis/%s" , repoName ), repoDir )
176- }
177-
178- func createBranch (ctx context.Context , now time.Time ) error {
179- branchName := fmt .Sprintf ("%s%s" , branchPrefix , now .UTC ().Format ("20060102T150405Z" ))
180- return command .Run (ctx , "git" , "checkout" , "-b" , branchName )
181- }
182-
183- func commitChanges (ctx context.Context ) error {
184- if err := command .Run (ctx , "git" , "add" , "." ); err != nil {
185- return err
186- }
187- return command .Run (ctx , "git" , "commit" , "-m" , commitTitle )
188- }
189-
190- func pushBranch (ctx context.Context ) error {
191- return command .Run (ctx , "git" , "push" , "-u" , "origin" , "HEAD" )
192- }
193-
194- func createPR (ctx context.Context , repoName string ) error {
173+ func createGithubDetails (repoName string ) GithubDetails {
195174 sources := "googleapis"
196175 if repoName == repoRust {
197176 sources = "googleapis and discovery-artifact-manager"
198177 }
199178 title := fmt .Sprintf ("chore: update %s and regenerate" , sources )
200- body := fmt .Sprintf ("Update %s to the latest commit and regenerate all client libraries." , sources )
201- return command .Run (ctx , "gh" , "pr" , "create" , "--title" , title , "--body" , body )
179+ body := fmt .Sprintf (`
180+ Update %s to the latest commit and regenerate all client libraries.` , sources )
181+ return GithubDetails {
182+ PrTitle : title ,
183+ PrBody : body ,
184+ BranchName : generateBranchName (branchPrefix , time .Now ()),
185+ }
202186}
203187
204188func runCargoUpdate (ctx context.Context ) error {
0 commit comments