diff --git a/internal/cmd/branch_list.go b/internal/cmd/branch_list.go index 4c9e8dfb..4c5bd0bc 100644 --- a/internal/cmd/branch_list.go +++ b/internal/cmd/branch_list.go @@ -88,13 +88,18 @@ func outputBranches(cmd *cobra.Command, cfg *config.Config, service api.Service, // outputBranchesTable outputs branches in a formatted table. func outputBranchesTable(output io.Writer, branches []OutputBranch) error { table := tablewriter.NewWriter(output) - table.Header("BRANCH ID", "NAME", "STATUS", "CREATED") + table.Header("BRANCH ID", "NAME", "STATUS", "CREATED BY", "CREATED") for _, branch := range branches { + var createdBy string + if branch.Creator != nil { + createdBy = string(branch.Creator.Email) + } table.Append( branch.ID, branch.Name, string(branch.Status), + createdBy, branch.Created.Format("2006-01-02 15:04"), ) } diff --git a/internal/cmd/branch_list_test.go b/internal/cmd/branch_list_test.go index ba0a759d..61ee96c2 100644 --- a/internal/cmd/branch_list_test.go +++ b/internal/cmd/branch_list_test.go @@ -93,12 +93,12 @@ func TestBranchListCmd(t *testing.T) { args: []string{"branch", "list", "svc-12345"}, opts: []runOption{withExperimental()}, mock: expectList(sampleBranch(), paused), - wantStdout: `┌───────────┬───────────────────┬────────┬──────────────────┐ -│ BRANCH ID │ NAME │ STATUS │ CREATED │ -├───────────┼───────────────────┼────────┼──────────────────┤ -│ br-12345 │ test-branch │ READY │ 2025-01-16 09:00 │ -│ br-67890 │ feature/user-auth │ PAUSED │ 2025-01-16 09:00 │ -└───────────┴───────────────────┴────────┴──────────────────┘ + wantStdout: `┌───────────┬───────────────────┬────────┬──────────────────────┬──────────────────┐ +│ BRANCH ID │ NAME │ STATUS │ CREATED BY │ CREATED │ +├───────────┼───────────────────┼────────┼──────────────────────┼──────────────────┤ +│ br-12345 │ test-branch │ READY │ jane.doe@example.com │ 2025-01-16 09:00 │ +│ br-67890 │ feature/user-auth │ PAUSED │ jane.doe@example.com │ 2025-01-16 09:00 │ +└───────────┴───────────────────┴────────┴──────────────────────┴──────────────────┘ `, }, { @@ -106,11 +106,11 @@ func TestBranchListCmd(t *testing.T) { args: []string{"branch", "list"}, opts: []runOption{withExperimental(), withConfig(map[string]any{"service_id": "svc-12345"})}, mock: expectList(sampleBranch()), - wantStdout: `┌───────────┬─────────────┬────────┬──────────────────┐ -│ BRANCH ID │ NAME │ STATUS │ CREATED │ -├───────────┼─────────────┼────────┼──────────────────┤ -│ br-12345 │ test-branch │ READY │ 2025-01-16 09:00 │ -└───────────┴─────────────┴────────┴──────────────────┘ + wantStdout: `┌───────────┬─────────────┬────────┬──────────────────────┬──────────────────┐ +│ BRANCH ID │ NAME │ STATUS │ CREATED BY │ CREATED │ +├───────────┼─────────────┼────────┼──────────────────────┼──────────────────┤ +│ br-12345 │ test-branch │ READY │ jane.doe@example.com │ 2025-01-16 09:00 │ +└───────────┴─────────────┴────────┴──────────────────────┴──────────────────┘ `, }, { @@ -120,6 +120,20 @@ func TestBranchListCmd(t *testing.T) { mock: expectList(), wantStderr: "No branches found for service 'test-service' (svc-12345).\n", }, + { + // The API leaves the creator out when the user is no longer known, + // e.g. after being deleted. + name: "table without a creator", + args: []string{"branch", "list", "svc-12345"}, + opts: []runOption{withExperimental()}, + mock: expectList(sampleBranch(noCreator)), + wantStdout: `┌───────────┬─────────────┬────────┬────────────┬──────────────────┐ +│ BRANCH ID │ NAME │ STATUS │ CREATED BY │ CREATED │ +├───────────┼─────────────┼────────┼────────────┼──────────────────┤ +│ br-12345 │ test-branch │ READY │ │ 2025-01-16 09:00 │ +└───────────┴─────────────┴────────┴────────────┴──────────────────┘ +`, + }, { name: "json", args: []string{"branch", "list", "svc-12345", "-o", "json"},