Skip to content

Commit 45652c0

Browse files
authored
fix(librarian): resolve issue where commits cannot be fetched for new library (#2631)
Fixes #2628
1 parent 59fe178 commit 45652c0

File tree

3 files changed

+18
-2
lines changed

3 files changed

+18
-2
lines changed

internal/librarian/mocks_test.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -333,6 +333,7 @@ type MockRepository struct {
333333
GetCommitsForPathsSinceTagValue []*gitrepo.Commit
334334
GetCommitsForPathsSinceTagValueByTag map[string][]*gitrepo.Commit
335335
GetCommitsForPathsSinceTagError error
336+
GetCommitsForPathsSinceTagLastTagName string
336337
GetCommitsForPathsSinceLastGenValue []*gitrepo.Commit
337338
GetCommitsForPathsSinceLastGenByCommit map[string][]*gitrepo.Commit
338339
GetCommitsForPathsSinceLastGenByPath map[string][]*gitrepo.Commit
@@ -420,6 +421,7 @@ func (m *MockRepository) GetLatestCommit(path string) (*gitrepo.Commit, error) {
420421
}
421422

422423
func (m *MockRepository) GetCommitsForPathsSinceTag(paths []string, tagName string) ([]*gitrepo.Commit, error) {
424+
m.GetCommitsForPathsSinceTagLastTagName = tagName
423425
if m.GetCommitsForPathsSinceTagError != nil {
424426
return nil, m.GetCommitsForPathsSinceTagError
425427
}

internal/librarian/release_init.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -202,8 +202,11 @@ func (r *initRunner) runInitCommand(ctx context.Context, outputDir string) error
202202
// processLibrary wrapper to process the library for release. Helps retrieve latest commits
203203
// since the last release and passing the changes to updateLibrary.
204204
func (r *initRunner) processLibrary(library *config.LibraryState) error {
205-
tagFormat := config.DetermineTagFormat(library.ID, library, r.librarianConfig)
206-
tagName := config.FormatTag(tagFormat, library.ID, library.Version)
205+
var tagName string
206+
if library.Version != "0.0.0" {
207+
tagFormat := config.DetermineTagFormat(library.ID, library, r.librarianConfig)
208+
tagName = config.FormatTag(tagFormat, library.ID, library.Version)
209+
}
207210
commits, err := getConventionalCommitsSinceLastRelease(r.repo, library, tagName)
208211
if err != nil {
209212
return fmt.Errorf("failed to fetch conventional commits for library, %s: %w", library.ID, err)

internal/librarian/release_init_test.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1322,6 +1322,14 @@ func TestProcessLibrary(t *testing.T) {
13221322
wantErr: true,
13231323
wantErrMsg: "failed to fetch conventional commits for library",
13241324
},
1325+
{
1326+
name: "does not search for git tag for 0.0.0 version",
1327+
libraryState: &config.LibraryState{
1328+
ID: "one-id",
1329+
Version: "0.0.0",
1330+
},
1331+
repo: &MockRepository{},
1332+
},
13251333
} {
13261334
state := &config.LibrarianState{
13271335
Libraries: []*config.LibraryState{
@@ -1345,6 +1353,9 @@ func TestProcessLibrary(t *testing.T) {
13451353
if err != nil {
13461354
t.Errorf("failed to run processLibrary(): %q", err.Error())
13471355
}
1356+
if test.libraryState.Version == "0.0.0" && test.repo.(*MockRepository).GetCommitsForPathsSinceTagLastTagName != "" {
1357+
t.Errorf("GetCommitsForPathsSinceTag should be called with an empty tag name for version 0.0.0, got %q", test.repo.(*MockRepository).GetCommitsForPathsSinceTagLastTagName)
1358+
}
13481359
}
13491360
}
13501361

0 commit comments

Comments
 (0)