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:
parent
6b0510f81a
commit
09a6609050
2 changed files with 26 additions and 1 deletions
10
api/api.go
10
api/api.go
|
|
@ -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 (
|
||||
|
|
|
|||
|
|
@ -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
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue