Skip to content

Commit 99b337f

Browse files
committed
feat: handle merge conflicts better
1 parent 0ed321b commit 99b337f

File tree

4 files changed

+34
-13
lines changed

4 files changed

+34
-13
lines changed

pkg/cmd/build.go

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,15 @@ import (
77
"fmt"
88
"os"
99
"path"
10-
"slices"
1110
"strings"
1211

1312
tea "github.com/charmbracelet/bubbletea"
1413
cbuild "github.com/stainless-api/stainless-api-cli/pkg/components/build"
1514
"github.com/stainless-api/stainless-api-cli/pkg/console"
1615
"github.com/stainless-api/stainless-api-cli/pkg/stainlessutils"
17-
1816
"github.com/stainless-api/stainless-api-go"
1917
"github.com/stainless-api/stainless-api-go/option"
2018
"github.com/stainless-api/stainless-api-go/shared"
21-
2219
"github.com/tidwall/gjson"
2320
"github.com/urfave/cli/v3"
2421
)
@@ -253,15 +250,13 @@ func (c buildCompletionModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
253250
return c, cmd
254251
}
255252

256-
var GOOD_COMMIT_CONCLUSIONS = []string{"error", "warning", "note", "success"}
257-
258253
func (c buildCompletionModel) IsCompleted() bool {
259254
b := stainlessutils.NewBuild(c.Build.Build)
260255
for _, target := range b.Languages() {
261256
buildTarget := b.BuildTarget(target)
262257

263258
var downloadIsCompleted = true
264-
if buildTarget.IsCommitCompleted() && slices.Contains(GOOD_COMMIT_CONCLUSIONS, buildTarget.Commit.Completed.Conclusion) {
259+
if buildTarget.IsCommitCompleted() && stainlessutils.IsGoodCommitConclusion(buildTarget.Commit.Completed.Conclusion) {
265260
if download, ok := c.Build.Downloads[target]; ok {
266261
if download.Status != "completed" {
267262
downloadIsCompleted = false

pkg/components/build/model.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,8 +111,7 @@ func (m Model) Update(msg tea.Msg) (Model, tea.Cmd) {
111111
}
112112

113113
// Start download when the commit step is done, and m.Downloads[target] is specified
114-
status, _, conclusion := buildTarget.StepInfo("commit")
115-
downloadable := status == "completed" && conclusion != "fatal"
114+
downloadable := buildTarget.IsCommitCompleted() && buildTarget.IsGoodCommitConclusion()
116115
if download, ok := m.Downloads[target]; ok && downloadable && download.Status == "not_started" {
117116
download.Status = "in_progress"
118117
cmds = append(cmds, m.downloadTarget(target))

pkg/components/build/view.go

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -100,14 +100,18 @@ func ViewStepSymbol(status, conclusion string) string {
100100
return yellowStyle.Render("●")
101101
case "completed":
102102
switch conclusion {
103-
case "success":
103+
case "success", "note":
104104
return greenStyle.Render("✓")
105-
case "failure":
106-
return redStyle.Render("✗")
107105
case "warning":
108106
return yellowStyle.Render("⚠")
107+
case "error":
108+
return redStyle.Render("⚠")
109+
case "fatal":
110+
return redStyle.Render("✗")
111+
case "merge_conflict", "upstream_merge_conflict":
112+
return yellowStyle.Render("m")
109113
default:
110-
return greenStyle.Render("✓")
114+
return grayStyle.Render(conclusion)
111115
}
112116
default:
113117
return grayStyle.Render("○")

pkg/stainlessutils/stainlessutils.go

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package stainlessutils
22

33
import (
44
"fmt"
5+
"slices"
56

67
"github.com/stainless-api/stainless-api-go"
78
"github.com/tidwall/gjson"
@@ -12,6 +13,12 @@ type Build struct {
1213
stainless.Build
1314
}
1415

16+
var GOOD_COMMIT_CONCLUSIONS = []string{"error", "warning", "note", "success"}
17+
18+
func IsGoodCommitConclusion(conclusion string) bool {
19+
return slices.Contains(GOOD_COMMIT_CONCLUSIONS, conclusion)
20+
}
21+
1522
// NewBuild creates a new Build wrapper
1623
func NewBuild(build stainless.Build) *Build {
1724
return &Build{Build: build}
@@ -182,7 +189,18 @@ func (bt *BuildTarget) StepInfo(step string) (status, url, conclusion string) {
182189
status = u.Status
183190
if u.Status == "completed" {
184191
conclusion = u.Completed.Conclusion
185-
url = fmt.Sprintf("https://github.com/%s/%s/commit/%s", u.Completed.Commit.Repo.Owner, u.Completed.Commit.Repo.Name, u.Completed.Commit.Sha)
192+
// Use merge conflict PR URL if available, otherwise use commit URL
193+
if u.Completed.JSON.MergeConflictPr.Valid() {
194+
url = fmt.Sprintf("https://github.com/%s/%s/pull/%.0f",
195+
u.Completed.MergeConflictPr.Repo.Owner,
196+
u.Completed.MergeConflictPr.Repo.Name,
197+
u.Completed.MergeConflictPr.Number)
198+
} else if u.Completed.JSON.Commit.Valid() {
199+
url = fmt.Sprintf("https://github.com/%s/%s/commit/%s",
200+
u.Completed.Commit.Repo.Owner,
201+
u.Completed.Commit.Repo.Name,
202+
u.Completed.Commit.Sha)
203+
}
186204
}
187205
}
188206
if u, ok := stepUnion.(stainless.CheckStepUnion); ok {
@@ -232,6 +250,11 @@ func (bt *BuildTarget) IsCommitCompleted() bool {
232250
return status == "completed"
233251
}
234252

253+
func (bt *BuildTarget) IsGoodCommitConclusion() bool {
254+
_, _, conclusion := bt.StepInfo("commit")
255+
return IsGoodCommitConclusion(conclusion)
256+
}
257+
235258
func (bt *BuildTarget) IsCommitFailed() bool {
236259
status, _, conclusion := bt.StepInfo("commit")
237260
return status == "completed" && conclusion == "fatal"

0 commit comments

Comments
 (0)