Show * after branch name if codespace working directory is dirty

Append a `*` to the end of a branch name in `ghcs list` if the working
directory of the codespace is dirty (has uncommited or unpushed
changes).

Closes: #104
This commit is contained in:
Christian Gregg 2021-09-09 12:37:05 +01:00 committed by Christian Gregg
parent 6b0510f81a
commit 09a6609050
2 changed files with 26 additions and 1 deletions

View file

@ -124,6 +124,16 @@ type Codespace struct {
type CodespaceEnvironment struct {
State string `json:"state"`
Connection CodespaceEnvironmentConnection `json:"connection"`
GitStatus CodespaceEnvironmentGitStatus `json:"gitStatus"`
}
type CodespaceEnvironmentGitStatus struct {
Ahead int `json:"ahead"`
Behind int `json:"behind"`
Branch string `json:"branch"`
Commit string `json:"commit"`
HasUnpushedChanges bool `json:"hasUnpushedChanges"`
HasUncommitedChanges bool `json:"hasUncommitedChanges"`
}
const (

View file

@ -53,10 +53,25 @@ func list(opts *listOptions) error {
table.SetHeader([]string{"Name", "Repository", "Branch", "State", "Created At"})
for _, codespace := range codespaces {
table.Append([]string{
codespace.Name, codespace.RepositoryNWO, codespace.Branch, codespace.Environment.State, codespace.CreatedAt,
codespace.Name,
codespace.RepositoryNWO,
branch(codespace),
codespace.Environment.State,
codespace.CreatedAt,
})
}
table.Render()
return nil
}
func branch(codespace *api.Codespace) string {
name := codespace.Branch
gitStatus := codespace.Environment.GitStatus
if gitStatus.HasUncommitedChanges || gitStatus.HasUnpushedChanges {
name += "*"
}
return name
}