Skip to content

Commit fd28d4f

Browse files
committed
fix: handle edge cases in build view component better
1 parent a658215 commit fd28d4f

File tree

4 files changed

+20
-31
lines changed

4 files changed

+20
-31
lines changed

pkg/cmd/build.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"fmt"
88
"os"
99
"path"
10+
"slices"
1011
"strings"
1112

1213
tea "github.com/charmbracelet/bubbletea"
@@ -252,13 +253,15 @@ func (c buildCompletionModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
252253
return c, cmd
253254
}
254255

256+
var GOOD_COMMIT_CONCLUSIONS = []string{"error", "warning", "note", "success"}
257+
255258
func (c buildCompletionModel) IsCompleted() bool {
256259
b := stainlessutils.NewBuild(c.Build.Build)
257260
for _, target := range b.Languages() {
258261
buildTarget := b.BuildTarget(target)
259262

260-
downloadIsCompleted := true
261-
if buildTarget.IsCompleted() {
263+
var downloadIsCompleted = true
264+
if buildTarget.IsCommitCompleted() && slices.Contains(GOOD_COMMIT_CONCLUSIONS, buildTarget.Commit.Completed.Conclusion) {
262265
if download, ok := c.Build.Downloads[target]; ok {
263266
if download.Status != "completed" {
264267
downloadIsCompleted = false

pkg/components/build/model.go

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,15 +32,20 @@ type Model struct {
3232
}
3333

3434
type DownloadStatus struct {
35-
Status string // one of "not_started" "in_progress" "completed"
35+
Status string // one of "not_started" "in_progress" "completed"
36+
// One of "success", "failure', or empty if Status not "completed"
3637
Conclusion string
3738
Path string
3839
}
3940

4041
type TickMsg time.Time
4142
type FetchBuildMsg stainless.Build
4243
type ErrorMsg error
43-
type DownloadMsg stainless.Target
44+
type DownloadMsg struct {
45+
Target stainless.Target
46+
// One of "success", "failure',
47+
Conclusion string
48+
}
4449

4550
func NewModel(client stainless.Client, ctx context.Context, build stainless.Build, downloadPaths map[stainless.Target]string) Model {
4651
downloads := map[stainless.Target]DownloadStatus{}
@@ -84,9 +89,10 @@ func (m Model) Update(msg tea.Msg) (Model, tea.Cmd) {
8489
}))
8590

8691
case DownloadMsg:
87-
download := m.Downloads[stainless.Target(msg)]
92+
download := m.Downloads[msg.Target]
8893
download.Status = "completed"
89-
m.Downloads[stainless.Target(msg)] = download
94+
download.Conclusion = msg.Conclusion
95+
m.Downloads[msg.Target] = download
9096

9197
case FetchBuildMsg:
9298
m.Build = stainless.Build(msg)
@@ -132,9 +138,9 @@ func (m Model) downloadTarget(target stainless.Target) tea.Cmd {
132138
}
133139
err = PullOutput(outputRes.Output, outputRes.URL, outputRes.Ref, m.Downloads[target].Path, console.NewGroup(true))
134140
if err != nil {
135-
return ErrorMsg(err)
141+
return DownloadMsg{target, "failure"}
136142
}
137-
return DownloadMsg(target)
143+
return DownloadMsg{target, "success"}
138144
}
139145
}
140146

pkg/components/build/view.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ func ViewBuildPipeline(build stainless.Build, target stainless.Target, downloads
6868
if pipeline.Len() > 0 {
6969
pipeline.WriteString(" ")
7070
}
71-
// align our naming of the commit step with the
71+
// align our naming of the commit step with the version in the Studio
7272
if step == "commit" {
7373
step = "codegen"
7474
}

pkg/stainlessutils/stainlessutils.go

Lines changed: 2 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -220,31 +220,11 @@ func (bt *BuildTarget) Steps() []string {
220220
}
221221

222222
func (bt *BuildTarget) IsCompleted() bool {
223-
steps := []string{"commit", "lint", "build", "test"}
224-
for _, step := range steps {
225-
if !gjson.Get(bt.RawJSON(), step).Exists() {
226-
continue
227-
}
228-
status, _, conclusion := bt.StepInfo(step)
229-
if conclusion == "merge_conflict" {
230-
return true
231-
}
232-
if status != "completed" {
233-
return false
234-
}
235-
}
236-
return true
223+
return bt.Status == "completed"
237224
}
238225

239226
func (bt *BuildTarget) IsInProgress() bool {
240-
steps := []string{"commit", "lint", "build", "test", "upload"}
241-
for _, step := range steps {
242-
status, _, _ := bt.StepInfo(step)
243-
if status == "in_progress" {
244-
return true
245-
}
246-
}
247-
return false
227+
return bt.Status != "completed"
248228
}
249229

250230
func (bt *BuildTarget) IsCommitCompleted() bool {

0 commit comments

Comments
 (0)