@@ -29,8 +29,6 @@ import (
2929 "strings"
3030 "time"
3131
32- "github.com/googleapis/librarian/internal/conventionalcommits"
33-
3432 "github.com/googleapis/librarian/internal/docker"
3533
3634 "github.com/googleapis/librarian/internal/config"
@@ -44,13 +42,14 @@ const (
4442)
4543
4644type commitInfo struct {
47- cfg * config.Config
48- state * config.LibrarianState
49- repo gitrepo.Repository
50- ghClient GitHubClient
51- additionalMessage string
52- commitMessage string
53- prType string
45+ cfg * config.Config
46+ state * config.LibrarianState
47+ repo gitrepo.Repository
48+ ghClient GitHubClient
49+ idToCommits map [string ]string
50+ failedLibraries []string
51+ commitMessage string
52+ prType string
5453}
5554
5655type commandRunner struct {
@@ -251,7 +250,7 @@ func copyLibraryFiles(state *config.LibrarianState, dest, libraryID, src string)
251250 for _ , srcRoot := range library .SourceRoots {
252251 dstPath := filepath .Join (dest , srcRoot )
253252 srcPath := filepath .Join (src , srcRoot )
254- files , err := getDirectoryFilesnames (srcPath )
253+ files , err := getDirectoryFilenames (srcPath )
255254 if err != nil {
256255 return err
257256 }
@@ -267,7 +266,7 @@ func copyLibraryFiles(state *config.LibrarianState, dest, libraryID, src string)
267266 return nil
268267}
269268
270- func getDirectoryFilesnames (dir string ) ([]string , error ) {
269+ func getDirectoryFilenames (dir string ) ([]string , error ) {
271270 if _ , err := os .Stat (dir ); err != nil {
272271 // Skip dirs that don't exist
273272 if os .IsNotExist (err ) {
@@ -310,27 +309,6 @@ func copyLibrary(dst, src string, library *config.LibraryState) error {
310309 return nil
311310}
312311
313- func coerceLibraryChanges (commits []* conventionalcommits.ConventionalCommit ) []* config.Change {
314- changes := make ([]* config.Change , 0 )
315- for _ , commit := range commits {
316- clNum := ""
317- if cl , ok := commit .Footers [KeyClNum ]; ok {
318- clNum = cl
319- }
320-
321- changeType := getChangeType (commit )
322- changes = append (changes , & config.Change {
323- Type : changeType ,
324- Subject : commit .Description ,
325- Body : commit .Body ,
326- ClNum : clNum ,
327- CommitHash : commit .SHA ,
328- })
329- }
330-
331- return changes
332- }
333-
334312// commitAndPush creates a commit and push request to GitHub for the generated
335313// changes.
336314// It uses the GitHub client to create a PR with the specified branch, title, and
@@ -354,15 +332,11 @@ func commitAndPush(ctx context.Context, info *commitInfo) error {
354332
355333 datetimeNow := formatTimestamp (time .Now ())
356334 branch := fmt .Sprintf ("librarian-%s" , datetimeNow )
357- slog .Info ("Creating branch" , slog .String ("branch" , branch ))
358335 if err := repo .CreateBranchAndCheckout (branch ); err != nil {
359336 return err
360337 }
361338
362- // TODO: get correct language for message (https://github.com/googleapis/librarian/issues/885)
363- commitMessage := info .commitMessage
364- slog .Info ("Committing" , "message" , commitMessage )
365- if err := repo .Commit (commitMessage ); err != nil {
339+ if err := repo .Commit (info .commitMessage ); err != nil {
366340 return err
367341 }
368342
@@ -382,14 +356,29 @@ func commitAndPush(ctx context.Context, info *commitInfo) error {
382356 }
383357
384358 title := fmt .Sprintf ("Librarian %s pull request: %s" , info .prType , datetimeNow )
385- slog .Info ("Creating pull request" , slog .String ("branch" , branch ), slog .String ("title" , title ))
386- if _ , err = info .ghClient .CreatePullRequest (ctx , gitHubRepo , branch , cfg .Branch , title , commitMessage ); err != nil {
359+ prBody , err := createPRBody (info )
360+ if err != nil {
361+ return fmt .Errorf ("failed to create pull request body: %w" , err )
362+ }
363+
364+ if _ , err = info .ghClient .CreatePullRequest (ctx , gitHubRepo , branch , cfg .Branch , title , prBody ); err != nil {
387365 return fmt .Errorf ("failed to create pull request: %w" , err )
388366 }
389367
390368 return nil
391369}
392370
371+ func createPRBody (info * commitInfo ) (string , error ) {
372+ switch info .prType {
373+ case generate :
374+ return formatGenerationPRBody (info .repo , info .state , info .idToCommits , info .failedLibraries )
375+ case release :
376+ return formatReleaseNotes (info .repo , info .state )
377+ default :
378+ return "" , fmt .Errorf ("unrecognized pull request type: %s" , info .prType )
379+ }
380+ }
381+
393382func copyFile (dst , src string ) (err error ) {
394383 sourceFile , err := os .Open (src )
395384 if err != nil {
0 commit comments