Implement new API payload for a Codespace

This commit is contained in:
Jose Garcia 2021-10-14 09:10:15 -04:00
parent a033b85fa2
commit 3544275c2f
5 changed files with 28 additions and 37 deletions

View file

@ -226,17 +226,17 @@ type codespace struct {
// If includeGitStatus is true, the branch will include a star if
// the codespace has unsaved changes.
func (c codespace) displayName(includeName, includeGitStatus bool) string {
branch := c.Branch
branch := c.GitStatus.Ref
if includeGitStatus {
branch = c.branchWithGitStatus()
}
if includeName {
return fmt.Sprintf(
"%s: %s [%s]", c.RepositoryNWO, branch, c.Name,
"%s: %s [%s]", c.Repository.FullName, branch, c.Name,
)
}
return c.RepositoryNWO + ": " + branch
return c.Repository.FullName + ": " + branch
}
// gitStatusDirty represents an unsaved changes status.
@ -246,14 +246,14 @@ const gitStatusDirty = "*"
// if the branch is currently being worked on.
func (c codespace) branchWithGitStatus() string {
if c.hasUnsavedChanges() {
return c.Branch + gitStatusDirty
return c.GitStatus.Ref + gitStatusDirty
}
return c.Branch
return c.GitStatus.Ref
}
// hasUnsavedChanges returns whether the environment has
// unsaved changes.
func (c codespace) hasUnsavedChanges() bool {
return c.Environment.GitStatus.HasUncommitedChanges || c.Environment.GitStatus.HasUnpushedChanges
return c.GitStatus.HasUncommitedChanges || c.GitStatus.HasUnpushedChanges
}

View file

@ -89,7 +89,7 @@ func (a *App) Delete(ctx context.Context, opts deleteOptions) (err error) {
if nameFilter != "" && c.Name != nameFilter {
continue
}
if opts.repoFilter != "" && !strings.EqualFold(c.RepositoryNWO, opts.repoFilter) {
if opts.repoFilter != "" && !strings.EqualFold(c.Repository.FullName, opts.repoFilter) {
continue
}
if opts.keepDays > 0 {

View file

@ -45,9 +45,9 @@ func (a *App) List(ctx context.Context, asJSON bool, limit int) error {
cs := codespace{apiCodespace}
table.Append([]string{
cs.Name,
cs.RepositoryNWO,
cs.Repository.FullName,
cs.branchWithGitStatus(),
cs.Environment.State,
cs.State,
cs.CreatedAt,
})
}