@@ -27,7 +27,6 @@ import (
2727
2828 "github.com/googleapis/librarian/internal/config"
2929 "github.com/googleapis/librarian/internal/github"
30- "github.com/googleapis/librarian/internal/gitrepo"
3130)
3231
3332const (
@@ -45,23 +44,20 @@ var (
4544type tagAndReleaseRunner struct {
4645 ghClient GitHubClient
4746 pullRequest string
48- repo gitrepo.Repository
49- state * config.LibrarianState
5047}
5148
5249func newTagAndReleaseRunner (cfg * config.Config ) (* tagAndReleaseRunner , error ) {
53- runner , err := newCommandRunner (cfg )
54- if err != nil {
55- return nil , err
56- }
5750 if cfg .GitHubToken == "" {
5851 return nil , fmt .Errorf ("`LIBRARIAN_GITHUB_TOKEN` must be set" )
5952 }
53+ repo , err := github .ParseRemote (cfg .Repo )
54+ if err != nil {
55+ return nil , err
56+ }
57+ ghClient := github .NewClient (cfg .GitHubToken , repo )
6058 return & tagAndReleaseRunner {
61- ghClient : runner . ghClient ,
59+ ghClient : ghClient ,
6260 pullRequest : cfg .PullRequest ,
63- repo : runner .repo ,
64- state : runner .state ,
6561 }, nil
6662}
6763
@@ -130,24 +126,30 @@ func (r *tagAndReleaseRunner) processPullRequest(ctx context.Context, p *github.
130126 return nil
131127 }
132128
129+ // Load library state from remote repo
130+ libraryState , err := loadRepoStateFromGitHub (ctx , r .ghClient , * p .Base .Ref )
131+ if err != nil {
132+ return err
133+ }
134+
133135 // Add a tag to the release commit to trigger louhi flow: "release-please-{pr number}"
134- //TODO: remove this logic as part of https://github.com/googleapis/librarian/issues/2044
136+ // TODO: remove this logic as part of https://github.com/googleapis/librarian/issues/2044
135137 commitSha := p .GetMergeCommitSHA ()
136138 tagName := fmt .Sprintf ("release-please-%d" , p .GetNumber ())
137139 if err := r .ghClient .CreateTag (ctx , tagName , commitSha ); err != nil {
138140 return fmt .Errorf ("failed to create tag %s: %w" , tagName , err )
139141 }
140-
141142 for _ , release := range releases {
142143 slog .Info ("creating release" , "library" , release .Library , "version" , release .Version )
143144
144- lib := r .state .LibraryByID (release .Library )
145- if lib == nil {
146- return fmt .Errorf ("library %s not found" , release .Library )
145+ tagFormat , err := determineTagFormat (release .Library , libraryState )
146+ if err != nil {
147+ slog .Warn ("could not determine tag format" , "library" , release .Library )
148+ return err
147149 }
148150
149151 // Create the release.
150- tagName := formatTag (lib , release .Version )
152+ tagName := formatTag (tagFormat , release . Library , release .Version )
151153 releaseName := fmt .Sprintf ("%s %s" , release .Library , release .Version )
152154 if _ , err := r .ghClient .CreateRelease (ctx , tagName , releaseName , release .Body , commitSha ); err != nil {
153155 return fmt .Errorf ("failed to create release: %w" , err )
@@ -157,6 +159,18 @@ func (r *tagAndReleaseRunner) processPullRequest(ctx context.Context, p *github.
157159 return r .replacePendingLabel (ctx , p )
158160}
159161
162+ func determineTagFormat (libraryID string , librarianState * config.LibrarianState ) (string , error ) {
163+ // TODO(#2177): read from LibrarianConfig
164+ libraryState := librarianState .LibraryByID (libraryID )
165+ if libraryState == nil {
166+ return "" , fmt .Errorf ("library %s not found" , libraryID )
167+ }
168+ if libraryState .TagFormat != "" {
169+ return libraryState .TagFormat , nil
170+ }
171+ return "" , fmt .Errorf ("library %s did not configure tag_format" , libraryID )
172+ }
173+
160174// libraryRelease holds the parsed information from a pull request body.
161175type libraryRelease struct {
162176 // Body contains the release notes.
0 commit comments