@@ -26,7 +26,11 @@ type BuildModel struct {
2626 build * stainless.BuildObject
2727 branch string
2828 diagnostics []stainless.BuildDiagnosticListResponse
29- view string
29+ downloads map [stainless.Target ]struct {
30+ status string
31+ path string
32+ }
33+ view string
3034
3135 cc * apiCommandContext
3236 ctx context.Context
@@ -38,6 +42,7 @@ type tickMsg time.Time
3842type fetchBuildMsg * stainless.BuildObject
3943type fetchDiagnosticsMsg []stainless.BuildDiagnosticListResponse
4044type errorMsg error
45+ type downloadMsg stainless.Target
4146type triggerNewBuildMsg struct {}
4247
4348func NewBuildModel (cc * apiCommandContext , ctx context.Context , branch string , fn func () (* stainless.BuildObject , error )) BuildModel {
@@ -77,6 +82,11 @@ func (m BuildModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
7782 cmds = append (cmds , tea .Quit )
7883 }
7984
85+ case downloadMsg :
86+ download := m .downloads [stainless .Target (msg )]
87+ download .status = "completed"
88+ m .downloads [stainless .Target (msg )] = download
89+
8090 case tickMsg :
8191 if m .build != nil {
8292 cmds = append (cmds , m .fetchBuildStatus ())
@@ -89,6 +99,19 @@ func (m BuildModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
8999 case fetchBuildMsg :
90100 if m .build == nil {
91101 m .build = msg
102+ m .downloads = make (map [stainless.Target ]struct {
103+ status string
104+ path string
105+ })
106+ for targetName , targetConfig := range m .cc .workspaceConfig .Targets {
107+ m .downloads [stainless .Target (targetName )] = struct {
108+ status string
109+ path string
110+ }{
111+ status : "not started" ,
112+ path : targetConfig .OutputPath ,
113+ }
114+ }
92115 cmds = append (cmds , m .updateView ("header" ))
93116 }
94117
@@ -97,6 +120,25 @@ func (m BuildModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
97120 m .isCompleted = true
98121 cmds = append (cmds , m .fetchDiagnostics ())
99122 }
123+ languages := getBuildLanguages (m .build )
124+ for _ , target := range languages {
125+ buildTarget := getBuildTarget (m .build , target )
126+ if buildTarget == nil {
127+ continue
128+ }
129+ commitUnion := getStepUnion (buildTarget , "commit" )
130+ if commitUnion == nil {
131+ continue
132+ }
133+ status , _ , _ := extractStepInfo (commitUnion )
134+ if status == "completed" {
135+ if download , ok := m .downloads [target ]; ok && download .status == "not started" {
136+ download .status = "started"
137+ cmds = append (cmds , m .downloadTarget (target ))
138+ m .downloads [target ] = download
139+ }
140+ }
141+ }
100142
101143 case fetchDiagnosticsMsg :
102144 if m .diagnostics == nil {
@@ -111,6 +153,32 @@ func (m BuildModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
111153 return m , tea .Sequence (cmds ... )
112154}
113155
156+ func (m BuildModel ) downloadTarget (target stainless.Target ) tea.Cmd {
157+ return func () tea.Msg {
158+ if m .build == nil {
159+ return errorMsg (fmt .Errorf ("no current build to download target from" ))
160+ }
161+ params := stainless.BuildTargetOutputGetParams {
162+ BuildID : m .build .ID ,
163+ Target : stainless .BuildTargetOutputGetParamsTarget (target ),
164+ Type : "source" ,
165+ Output : "git" ,
166+ }
167+ outputRes , err := m .cc .client .Builds .TargetOutputs .Get (
168+ context .TODO (),
169+ params ,
170+ )
171+ if err != nil {
172+ return errorMsg (err )
173+ }
174+ err = pullOutput (outputRes .Output , outputRes .URL , outputRes .Ref , m .downloads [target ].path , & Group {silent : true })
175+ if err != nil {
176+ return errorMsg (err )
177+ }
178+ return downloadMsg (target )
179+ }
180+ }
181+
114182func (m BuildModel ) fetchBuildStatus () tea.Cmd {
115183 return func () tea.Msg {
116184 if m .build == nil {
0 commit comments