Skip to content

Commit 8b3c743

Browse files
authored
fix: skip fetching commits if last generated commit is empty (#1870)
Fixes #1869
1 parent 40e7bc3 commit 8b3c743

2 files changed

Lines changed: 44 additions & 1 deletion

File tree

internal/librarian/generate_test.go

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1571,14 +1571,52 @@ func TestUpdateChangesSinceLastGeneration(t *testing.T) {
15711571
},
15721572
},
15731573
{
1574-
name: "failed to get conventional commits",
1574+
name: "empty last generated commit",
15751575
libraryID: "another-id",
15761576
libraries: []*config.LibraryState{
15771577
{
15781578
ID: "example-d",
15791579
},
15801580
{
15811581
ID: "another-id",
1582+
APIs: []*config.API{
1583+
{
1584+
Path: "api/one/path",
1585+
},
1586+
{
1587+
Path: "api/another/path",
1588+
},
1589+
},
1590+
},
1591+
},
1592+
repo: &MockRepository{
1593+
// Set this error to verify the function under test will not
1594+
// fetch the commits.
1595+
GetCommitsForPathsSinceLastGenError: errors.New("simulated error"),
1596+
},
1597+
want: &config.LibraryState{
1598+
ID: "another-id",
1599+
APIs: []*config.API{
1600+
{
1601+
Path: "api/one/path",
1602+
},
1603+
{
1604+
Path: "api/another/path",
1605+
},
1606+
},
1607+
Changes: []*config.Change{},
1608+
},
1609+
},
1610+
{
1611+
name: "failed to get conventional commits",
1612+
libraryID: "another-id",
1613+
libraries: []*config.LibraryState{
1614+
{
1615+
ID: "example-d",
1616+
},
1617+
{
1618+
ID: "another-id",
1619+
LastGeneratedCommit: "fake-sha",
15821620
},
15831621
},
15841622
repo: &MockRepository{

internal/librarian/release_please_lite.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ package librarian
1616

1717
import (
1818
"fmt"
19+
"log/slog"
1920
"strings"
2021

2122
"github.com/googleapis/librarian/internal/config"
@@ -41,6 +42,10 @@ func GetConventionalCommitsSinceLastRelease(repo gitrepo.Repository, library *co
4142
// GetConventionalCommitsSinceLastGeneration returns all conventional commits for
4243
// all API paths in given library since the last generation.
4344
func GetConventionalCommitsSinceLastGeneration(repo gitrepo.Repository, library *config.LibraryState) ([]*conventionalcommits.ConventionalCommit, error) {
45+
if library.LastGeneratedCommit == "" {
46+
slog.Info("the last generation commit is empty, skip fetching conventional commits", "library", library.ID)
47+
return make([]*conventionalcommits.ConventionalCommit, 0), nil
48+
}
4449
apiPaths := make([]string, 0)
4550
for _, oneAPI := range library.APIs {
4651
apiPaths = append(apiPaths, oneAPI.Path)

0 commit comments

Comments
 (0)