Skip to content

Commit

Permalink
fix: optional git status
Browse files Browse the repository at this point in the history
Signed-off-by: Toma Puljak <[email protected]>
  • Loading branch information
Tpuljak committed Dec 13, 2024
1 parent 934854b commit ba751d3
Show file tree
Hide file tree
Showing 9 changed files with 43 additions and 26 deletions.
6 changes: 5 additions & 1 deletion internal/util/apiclient/conversion/project.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,11 @@ func ToProject(projectDTO *apiclient.Project) *project.Project {
return project
}

func ToGitStatus(gitStatusDTO apiclient.GitStatus) *project.GitStatus {
func ToGitStatus(gitStatusDTO *apiclient.GitStatus) *project.GitStatus {
if gitStatusDTO == nil {
return nil
}

files := []*project.FileStatus{}
for _, fileDTO := range gitStatusDTO.FileStatus {
staging := project.Status(string(fileDTO.Staging))
Expand Down
1 change: 0 additions & 1 deletion pkg/api/docs/docs.go
Original file line number Diff line number Diff line change
Expand Up @@ -4533,7 +4533,6 @@ const docTemplate = `{
"ProjectState": {
"type": "object",
"required": [
"gitStatus",
"updatedAt",
"uptime"
],
Expand Down
1 change: 0 additions & 1 deletion pkg/api/docs/swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -4530,7 +4530,6 @@
"ProjectState": {
"type": "object",
"required": [
"gitStatus",
"updatedAt",
"uptime"
],
Expand Down
1 change: 0 additions & 1 deletion pkg/api/docs/swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -895,7 +895,6 @@ definitions:
uptime:
type: integer
required:
- gitStatus
- updatedAt
- uptime
type: object
Expand Down
1 change: 0 additions & 1 deletion pkg/apiclient/api/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3779,7 +3779,6 @@ components:
uptime:
type: integer
required:
- gitStatus
- updatedAt
- uptime
type: object
Expand Down
9 changes: 7 additions & 2 deletions pkg/apiclient/docs/ProjectState.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@

Name | Type | Description | Notes
------------ | ------------- | ------------- | -------------
**GitStatus** | [**GitStatus**](GitStatus.md) | |
**GitStatus** | Pointer to [**GitStatus**](GitStatus.md) | | [optional]
**UpdatedAt** | **string** | |
**Uptime** | **int32** | |

## Methods

### NewProjectState

`func NewProjectState(gitStatus GitStatus, updatedAt string, uptime int32, ) *ProjectState`
`func NewProjectState(updatedAt string, uptime int32, ) *ProjectState`

NewProjectState instantiates a new ProjectState object
This constructor will assign default values to properties that have it defined,
Expand Down Expand Up @@ -46,6 +46,11 @@ and a boolean to check if the value has been set.

SetGitStatus sets GitStatus field to given value.

### HasGitStatus

`func (o *ProjectState) HasGitStatus() bool`

HasGitStatus returns a boolean if a field has been set.

### GetUpdatedAt

Expand Down
40 changes: 24 additions & 16 deletions pkg/apiclient/model_project_state.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 6 additions & 2 deletions pkg/views/workspace/info/view.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ func getSingleProjectOutput(project *apiclient.Project, isCreationView bool) str

if project.State != nil {
output += getInfoLineState("State", project.State) + "\n"
output += getInfoLineGitStatus("Branch", &project.State.GitStatus) + "\n"
output += getInfoLineGitStatus("Branch", project.State.GitStatus) + "\n"
}

output += getInfoLinePrNumber(project.Repository.PrNumber, project.Repository, project.State)
Expand All @@ -120,7 +120,7 @@ func getProjectsOutputs(projects []apiclient.Project, isCreationView bool) strin
output += getInfoLine(fmt.Sprintf("Project #%d", i+1), project.Name)
output += getInfoLineState("State", project.State)
if project.State != nil {
output += getInfoLineGitStatus("Branch", &project.State.GitStatus)
output += getInfoLineGitStatus("Branch", project.State.GitStatus)
}
output += getInfoLinePrNumber(project.Repository.PrNumber, project.Repository, project.State)

Expand Down Expand Up @@ -159,6 +159,10 @@ func getInfoLineState(key string, state *apiclient.ProjectState) string {
}

func getInfoLineGitStatus(key string, status *apiclient.GitStatus) string {
if status == nil {
return ""
}

output := propertyNameStyle.Render(fmt.Sprintf("%-*s", propertyNameWidth, key))
output += propertyNameStyle.Foreground(views.Gray).Render(fmt.Sprintf("%-*s", propertyNameWidth, status.CurrentBranch))

Expand Down
2 changes: 1 addition & 1 deletion pkg/workspace/project/project.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ type ProjectInfo struct {
type ProjectState struct {
UpdatedAt string `json:"updatedAt" validate:"required"`
Uptime uint64 `json:"uptime" validate:"required"`
GitStatus *GitStatus `json:"gitStatus" validate:"required"`
GitStatus *GitStatus `json:"gitStatus" validate:"optional"`
} // @name ProjectState

type GitStatus struct {
Expand Down

0 comments on commit ba751d3

Please sign in to comment.