@@ -21,19 +21,13 @@ import (
2121 "os"
2222 "path/filepath"
2323
24- "github.com/googleapis/librarian/internal/conventionalcommits"
25-
2624 "github.com/googleapis/librarian/internal/docker"
2725
2826 "github.com/googleapis/librarian/internal/cli"
2927 "github.com/googleapis/librarian/internal/config"
3028 "github.com/googleapis/librarian/internal/gitrepo"
3129)
3230
33- const (
34- KeyClNum = "PiperOrigin-RevId"
35- )
36-
3731// cmdInit is the command for the `release init` subcommand.
3832var cmdInit = & cli.Command {
3933 Short : "init initiates a release by creating a release pull request." ,
@@ -84,14 +78,14 @@ func newInitRunner(cfg *config.Config) (*initRunner, error) {
8478 }
8579 return & initRunner {
8680 cfg : runner .cfg ,
87- workRoot : runner .workRoot ,
8881 repo : runner .repo ,
89- partialRepo : filepath .Join (runner .workRoot , "release-init" ),
9082 state : runner .state ,
9183 librarianConfig : runner .librarianConfig ,
92- image : runner .image ,
9384 ghClient : runner .ghClient ,
9485 containerClient : runner .containerClient ,
86+ workRoot : runner .workRoot ,
87+ partialRepo : filepath .Join (runner .workRoot , "release-init" ),
88+ image : runner .image ,
9589 }, nil
9690}
9791
@@ -113,7 +107,7 @@ func (r *initRunner) run(ctx context.Context) error {
113107 commitMessage : "chore: create a release" ,
114108 prType : release ,
115109 // Newly created PRs from the `release init` command should have a
116- // `release:pending` Github tab to be tracked for release.
110+ // `release:pending` GitHub tab to be tracked for release.
117111 pullRequestLabels : []string {"release:pending" },
118112 }
119113 if err := commitAndPush (ctx , commitInfo ); err != nil {
@@ -128,15 +122,16 @@ func (r *initRunner) runInitCommand(ctx context.Context, outputDir string) error
128122 if err := os .MkdirAll (dst , 0755 ); err != nil {
129123 return fmt .Errorf ("failed to make directory: %w" , err )
130124 }
131- src := r .repo .GetDir ()
132125
126+ src := r .repo .GetDir ()
133127 for _ , library := range r .state .Libraries {
134128 if r .cfg .Library != "" {
135129 if r .cfg .Library != library .ID {
136130 continue
137131 }
132+
138133 // Only update one library with the given library ID.
139- if err := updateLibrary ( r . repo , library , r . cfg . LibraryVersion ); err != nil {
134+ if err := r . updateLibrary ( library ); err != nil {
140135 return err
141136 }
142137 if err := copyLibrary (dst , src , library ); err != nil {
@@ -147,7 +142,7 @@ func (r *initRunner) runInitCommand(ctx context.Context, outputDir string) error
147142 }
148143
149144 // Update all libraries.
150- if err := updateLibrary ( r . repo , library , r . cfg . LibraryVersion ); err != nil {
145+ if err := r . updateLibrary ( library ); err != nil {
151146 return err
152147 }
153148 if err := copyLibrary (dst , src , library ); err != nil {
@@ -201,24 +196,28 @@ func (r *initRunner) runInitCommand(ctx context.Context, outputDir string) error
201196
202197// updateLibrary updates the given library in the following way:
203198//
204- // 1. Get the library's commit history in the given git repository .
199+ // 1. Update the library's previous version .
205200//
206- // 2. Override the library version if libraryVersion is not empty .
201+ // 2. Get the library's commit history in the given git repository .
207202//
208- // 3. Set the library's release trigger to true.
209- func updateLibrary (repo gitrepo.Repository , library * config.LibraryState , libraryVersion string ) error {
210- commits , err := GetConventionalCommitsSinceLastRelease (repo , library )
203+ // 3. Override the library version if libraryVersion is not empty.
204+ //
205+ // 4. Set the library's release trigger to true.
206+ func (r * initRunner ) updateLibrary (library * config.LibraryState ) error {
207+ // Update the previous version, we need this value when creating release note.
208+ library .PreviousVersion = library .Version
209+ commits , err := GetConventionalCommitsSinceLastRelease (r .repo , library )
211210 if err != nil {
212211 return fmt .Errorf ("failed to fetch conventional commits for library, %s: %w" , library .ID , err )
213212 }
214213
215- library .Changes = coerceLibraryChanges ( commits )
214+ library .Changes = commits
216215 if len (library .Changes ) == 0 {
217216 slog .Info ("Skip releasing library since no eligible change is found" , "library" , library .ID )
218217 return nil
219218 }
220219
221- nextVersion , err := NextVersion (commits , library .Version , libraryVersion )
220+ nextVersion , err := NextVersion (commits , library .Version , r . cfg . LibraryVersion )
222221 if err != nil {
223222 return err
224223 }
@@ -229,38 +228,6 @@ func updateLibrary(repo gitrepo.Repository, library *config.LibraryState, librar
229228 return nil
230229}
231230
232- func coerceLibraryChanges (commits []* conventionalcommits.ConventionalCommit ) []* config.Change {
233- changes := make ([]* config.Change , 0 )
234- for _ , commit := range commits {
235- clNum := ""
236- if cl , ok := commit .Footers [KeyClNum ]; ok {
237- clNum = cl
238- }
239-
240- changeType := getChangeType (commit )
241- changes = append (changes , & config.Change {
242- Type : changeType ,
243- Subject : commit .Description ,
244- Body : commit .Body ,
245- ClNum : clNum ,
246- CommitHash : commit .SHA ,
247- })
248- }
249-
250- return changes
251- }
252-
253- // getChangeType gets the type of the commit, adding an escalation mark (!) if
254- // it is a breaking change.
255- func getChangeType (commit * conventionalcommits.ConventionalCommit ) string {
256- changeType := commit .Type
257- if commit .IsBreaking {
258- changeType = changeType + "!"
259- }
260-
261- return changeType
262- }
263-
264231// copyGlobalAllowlist copies files in the global file allowlist excluding
265232//
266233// read-only files and copies global files from src.
0 commit comments