Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions internal/librarian/generate_command.go
Original file line number Diff line number Diff line change
Expand Up @@ -176,10 +176,14 @@ func (r *generateRunner) run(ctx context.Context) error {
return fmt.Errorf("unexpected prType %s", prType)
}

commitMessage := "feat: generate libraries"
if prType == pullRequestOnboard {
commitMessage = "feat: onboard a new library"
}
commitInfo := &commitInfo{
branch: r.branch,
commit: r.commit,
commitMessage: "feat: generate libraries",
commitMessage: commitMessage,
ghClient: r.ghClient,
prType: prType,
push: r.push,
Expand Down Expand Up @@ -221,7 +225,7 @@ func (r *generateRunner) generateSingleLibrary(ctx context.Context, libraryID, o
return nil, err
}

prType = pullRequestGenerate
prType = pullRequestOnboard
libraryID = configuredLibraryID
}

Expand Down
34 changes: 32 additions & 2 deletions internal/librarian/generate_command_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -837,7 +837,21 @@ func TestGenerateScenarios(t *testing.T) {
},
} {
t.Run(test.name, func(t *testing.T) {
repo := newTestGitRepoWithState(t, test.state, true)
var repo gitrepo.Repository
useMockRepo := test.name == "generate_single_library_including_initial_configuration" || test.name == "generate single existing library by library id"
if useMockRepo {
repo = &MockRepository{
Dir: t.TempDir(),
RemotesValue: []*gitrepo.Remote{
{
Name: "origin",
URLs: []string{"https://github.com/googleapis/librarian.git"},
},
},
}
} else {
repo = newTestGitRepoWithState(t, test.state, true)
}

r := &generateRunner{
api: test.api,
Expand All @@ -848,9 +862,13 @@ func TestGenerateScenarios(t *testing.T) {
state: test.state,
librarianConfig: test.librarianConfig,
containerClient: test.container,
ghClient: test.ghClient,
ghClient: &mockGitHubClient{},
workRoot: t.TempDir(),
}
if useMockRepo {
r.commit = true
r.push = true
}

// Create a service config in api path.
if err := os.MkdirAll(filepath.Join(r.sourceRepo.GetDir(), test.api), 0755); err != nil {
Expand Down Expand Up @@ -906,6 +924,18 @@ func TestGenerateScenarios(t *testing.T) {
if diff := cmp.Diff(test.wantConfigureCalls, test.container.configureCalls); diff != "" {
t.Errorf("%s: run() configureCalls mismatch (-want +got):%s", test.name, diff)
}
if test.name == "generate_single_library_including_initial_configuration" {
mockRepo := repo.(*MockRepository)
if mockRepo.LastCommitMessage != "feat: onboard a new library" {
t.Errorf("want commit message %q, got %q", "feat: onboard a new library", mockRepo.LastCommitMessage)
}
}
if test.name == "generate single existing library by library id" {
mockRepo := repo.(*MockRepository)
if mockRepo.LastCommitMessage != "feat: generate libraries" {
t.Errorf("want commit message %q, got %q", "feat: generate libraries", mockRepo.LastCommitMessage)
}
}
})
}
}
Expand Down
2 changes: 2 additions & 0 deletions internal/librarian/mocks_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,7 @@ type MockRepository struct {
RemotesValue []*gitrepo.Remote
RemotesError error
CommitCalls int
LastCommitMessage string
GetCommitError error
GetLatestCommitError error
GetCommitByHash map[string]*gitrepo.Commit
Expand Down Expand Up @@ -355,6 +356,7 @@ func (m *MockRepository) AddAll() error {

func (m *MockRepository) Commit(msg string) error {
m.CommitCalls++
m.LastCommitMessage = msg
return m.CommitError
}

Expand Down
Loading