Skip to content

Commit 1d07b34

Browse files
committed
feat: use getAvailableTargetInfo for preselected builds
1 parent 6c118e0 commit 1d07b34

File tree

7 files changed

+105
-143
lines changed

7 files changed

+105
-143
lines changed

pkg/cmd/build.go

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ import (
2323
"github.com/urfave/cli/v3"
2424
)
2525

26-
// targetInfo holds information about a build target
27-
type targetInfo struct {
26+
// BuildTargetInfo holds information about a build target
27+
type BuildTargetInfo struct {
2828
name string
2929
status stainless.BuildTargetStatus
3030
}
@@ -107,61 +107,61 @@ func processSingleTarget(target string) (string, string) {
107107
return targetName, targetPath
108108
}
109109

110-
// getTargetInfo extracts completed targets from a build response
111-
func getTargetInfo(buildRes stainless.BuildObject) []targetInfo {
112-
targets := []targetInfo{}
110+
// getBuildTargetInfo extracts completed targets from a build response
111+
func getBuildTargetInfo(buildRes stainless.BuildObject) []BuildTargetInfo {
112+
targets := []BuildTargetInfo{}
113113

114114
// Check each target and add it to the list if it's completed or in postgen
115115
if buildRes.Targets.JSON.Node.Valid() {
116-
targets = append(targets, targetInfo{
116+
targets = append(targets, BuildTargetInfo{
117117
name: "node",
118118
status: buildRes.Targets.Node.Status,
119119
})
120120
}
121121
if buildRes.Targets.JSON.Typescript.Valid() {
122-
targets = append(targets, targetInfo{
122+
targets = append(targets, BuildTargetInfo{
123123
name: "typescript",
124124
status: buildRes.Targets.Typescript.Status,
125125
})
126126
}
127127
if buildRes.Targets.JSON.Python.Valid() {
128-
targets = append(targets, targetInfo{
128+
targets = append(targets, BuildTargetInfo{
129129
name: "python",
130130
status: buildRes.Targets.Python.Status,
131131
})
132132
}
133133
if buildRes.Targets.JSON.Go.Valid() {
134-
targets = append(targets, targetInfo{
134+
targets = append(targets, BuildTargetInfo{
135135
name: "go",
136136
status: buildRes.Targets.Go.Status,
137137
})
138138
}
139139
if buildRes.Targets.JSON.Cli.Valid() {
140-
targets = append(targets, targetInfo{
140+
targets = append(targets, BuildTargetInfo{
141141
name: "cli",
142142
status: buildRes.Targets.Cli.Status,
143143
})
144144
}
145145
if buildRes.Targets.JSON.Kotlin.Valid() {
146-
targets = append(targets, targetInfo{
146+
targets = append(targets, BuildTargetInfo{
147147
name: "kotlin",
148148
status: buildRes.Targets.Kotlin.Status,
149149
})
150150
}
151151
if buildRes.Targets.JSON.Java.Valid() {
152-
targets = append(targets, targetInfo{
152+
targets = append(targets, BuildTargetInfo{
153153
name: "java",
154154
status: buildRes.Targets.Java.Status,
155155
})
156156
}
157157
if buildRes.Targets.JSON.Ruby.Valid() {
158-
targets = append(targets, targetInfo{
158+
targets = append(targets, BuildTargetInfo{
159159
name: "ruby",
160160
status: buildRes.Targets.Ruby.Status,
161161
})
162162
}
163163
if buildRes.Targets.JSON.Terraform.Valid() {
164-
targets = append(targets, targetInfo{
164+
targets = append(targets, BuildTargetInfo{
165165
name: "terraform",
166166
status: buildRes.Targets.Terraform.Status,
167167
})
@@ -191,7 +191,7 @@ func waitForBuildCompletion(ctx context.Context, client stainless.Client, buildI
191191
return nil, fmt.Errorf("build polling failed: %v", err)
192192
}
193193

194-
targets := getTargetInfo(*buildRes)
194+
targets := getBuildTargetInfo(*buildRes)
195195
allCompleted := true
196196

197197
for _, target := range targets {
@@ -505,7 +505,7 @@ func handleBuildsRetrieve(ctx context.Context, cmd *cli.Command) error {
505505
// pullBuildOutputs pulls the outputs for a completed build
506506
func pullBuildOutputs(ctx context.Context, client stainless.Client, res stainless.BuildObject, targetPaths map[string]string, pullGroup *Group) error {
507507
// Get all targets
508-
allTargets := getTargetInfo(res)
508+
allTargets := getBuildTargetInfo(res)
509509

510510
// Filter to only completed targets
511511
var targets []string

pkg/cmd/buildtargetoutput.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -66,11 +66,11 @@ func handleBuildsTargetOutputsRetrieve(ctx context.Context, cmd *cli.Command) er
6666

6767
buildID := cmd.String("build-id")
6868
if buildID == "" {
69-
latestBuildID, err := getLatestBuildID(ctx, cc.client, cmd.String("project"), cmd.String("branch"))
69+
latestBuild, err := getLatestBuild(ctx, cc.client, cmd.String("project"), cmd.String("branch"))
7070
if err != nil {
7171
return fmt.Errorf("failed to get latest build: %v", err)
7272
}
73-
buildID = latestBuildID
73+
buildID = latestBuild.ID
7474
}
7575

7676
params := stainless.BuildTargetOutputGetParams{
@@ -95,9 +95,9 @@ func handleBuildsTargetOutputsRetrieve(ctx context.Context, cmd *cli.Command) er
9595
return nil
9696
}
9797

98-
func getLatestBuildID(ctx context.Context, client stainless.Client, project, branch string) (string, error) {
98+
func getLatestBuild(ctx context.Context, client stainless.Client, project, branch string) (*stainless.BuildObject, error) {
9999
if project == "" {
100-
return "", fmt.Errorf("project is required when build-id is not provided")
100+
return nil, fmt.Errorf("project is required when build-id is not provided")
101101
}
102102

103103
params := stainless.BuildListParams{
@@ -113,12 +113,12 @@ func getLatestBuildID(ctx context.Context, client stainless.Client, project, bra
113113
params,
114114
)
115115
if err != nil {
116-
return "", err
116+
return nil, err
117117
}
118118

119119
if len(res.Data) == 0 {
120-
return "", fmt.Errorf("no builds found for project %s", project)
120+
return nil, fmt.Errorf("no builds found for project %s", project)
121121
}
122122

123-
return res.Data[0].ID, nil
123+
return &res.Data[0], nil
124124
}

pkg/cmd/dev.go

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -175,9 +175,9 @@ func runDevMode(ctx context.Context, cmd *cli.Command) error {
175175
return fmt.Errorf("project name is required")
176176
}
177177

178-
configuredTargets := []stainless.Target{
179-
"typescript", "python", "go", "java", "kotlin",
180-
"ruby", "terraform", "cli", "php", "csharp", "node",
178+
cc, err := getAPICommandContextWithWorkspaceDefaults(cmd)
179+
if err != nil {
180+
return err
181181
}
182182

183183
gitUser, err := getGitUsername()
@@ -210,7 +210,13 @@ func runDevMode(ctx context.Context, cmd *cli.Command) error {
210210

211211
// Phase 2: Language selection
212212
var selectedTargets []string
213-
targetOptions := buildTargetOptions(configuredTargets)
213+
214+
// Try to find workspace config for intelligent defaults
215+
var config WorkspaceConfig
216+
config.Find()
217+
218+
targetInfo := getAvailableTargetInfo(ctx, cc.client, projectName, config)
219+
targetOptions := targetInfoToOptions(targetInfo)
214220

215221
targetForm := huh.NewForm(
216222
huh.NewGroup(
@@ -238,12 +244,6 @@ func runDevMode(ctx context.Context, cmd *cli.Command) error {
238244
targets[i] = stainless.Target(target)
239245
}
240246

241-
// Get API command context for the build
242-
cc, err := getAPICommandContextWithWorkspaceDefaults(cmd)
243-
if err != nil {
244-
return err
245-
}
246-
247247
// Phase 3: Start build and monitor progress in a loop
248248
for {
249249
err := runDevBuild(ctx, cc, projectName, selectedBranch, targets)

pkg/cmd/dev_view.go

Lines changed: 0 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import (
77

88
"github.com/charmbracelet/bubbletea"
99
"github.com/charmbracelet/glamour"
10-
"github.com/charmbracelet/huh"
1110
"github.com/charmbracelet/lipgloss"
1211
"github.com/stainless-api/stainless-api-go"
1312
)
@@ -265,34 +264,6 @@ func ViewHelpMenu() string {
265264
return strings.Join(parts, sepStyle.Render(" • "))
266265
}
267266

268-
// buildTargetOptions creates huh options from the list of configured targets
269-
func buildTargetOptions(configuredTargets []stainless.Target) []huh.Option[string] {
270-
var options []huh.Option[string]
271-
272-
targetDisplayNames := map[stainless.Target]string{
273-
"typescript": "TypeScript",
274-
"python": "Python",
275-
"go": "Go",
276-
"java": "Java",
277-
"kotlin": "Kotlin",
278-
"ruby": "Ruby",
279-
"terraform": "Terraform",
280-
"cli": "CLI",
281-
"php": "PHP",
282-
"csharp": "C#",
283-
"node": "Node.js",
284-
}
285-
286-
for _, target := range configuredTargets {
287-
displayName := targetDisplayNames[target]
288-
if displayName == "" {
289-
displayName = string(target)
290-
}
291-
options = append(options, huh.NewOption(displayName, string(target)))
292-
}
293-
294-
return options
295-
}
296267

297268
// renderMarkdown renders markdown content using glamour
298269
func renderMarkdown(content string) string {

0 commit comments

Comments
 (0)