22package runsummary
33
44import (
5+ "context"
56 "encoding/json"
67 "fmt"
78 "path/filepath"
@@ -11,6 +12,7 @@ import (
1112 "github.com/mitchellh/cli"
1213 "github.com/segmentio/ksuid"
1314 "github.com/vercel/turbo/cli/internal/client"
15+ "github.com/vercel/turbo/cli/internal/spinner"
1416 "github.com/vercel/turbo/cli/internal/turbopath"
1517 "github.com/vercel/turbo/cli/internal/util"
1618 "github.com/vercel/turbo/cli/internal/workspace"
@@ -124,7 +126,7 @@ func (rsm *Meta) getPath() turbopath.AbsoluteSystemPath {
124126}
125127
126128// Close wraps up the RunSummary at the end of a `turbo run`.
127- func (rsm * Meta ) Close (exitCode int , workspaceInfos workspace.Catalog ) error {
129+ func (rsm * Meta ) Close (ctx context. Context , exitCode int , workspaceInfos workspace.Catalog ) error {
128130 if rsm .runType == runTypeDryJSON || rsm .runType == runTypeDryText {
129131 return rsm .closeDryRun (workspaceInfos )
130132 }
@@ -161,8 +163,19 @@ func (rsm *Meta) Close(exitCode int, workspaceInfos workspace.Catalog) error {
161163 return nil
162164 }
163165
164- url , errs := rsm .record ()
166+ // Wrap the record function so we can hoist out url/errors but keep
167+ // the function signature/type the spinner.WaitFor expects.
168+ var url string
169+ var errs []error
170+ record := func () {
171+ url , errs = rsm .record ()
172+ }
173+
174+ func () {
175+ _ = spinner .WaitFor (ctx , record , rsm .ui , "...sending run summary..." , 1000 * time .Millisecond )
176+ }()
165177
178+ // After the spinner is done
166179 if len (errs ) > 0 {
167180 rsm .ui .Warn ("Errors recording run to Spaces" )
168181 for _ , err := range errs {
@@ -234,7 +247,7 @@ func (rsm *Meta) record() (string, []error) {
234247 payload := rsm .newSpacesRunCreatePayload ()
235248 if startPayload , err := json .Marshal (payload ); err == nil {
236249 if resp , err := rsm .apiClient .JSONPost (createRunEndpoint , startPayload ); err != nil {
237- errs = append (errs , err )
250+ errs = append (errs , fmt . Errorf ( "POST %s: %w" , createRunEndpoint , err ) )
238251 } else {
239252 if err := json .Unmarshal (resp , response ); err != nil {
240253 errs = append (errs , fmt .Errorf ("Error unmarshaling response: %w" , err ))
@@ -250,7 +263,7 @@ func (rsm *Meta) record() (string, []error) {
250263 if donePayload , err := json .Marshal (newSpacesDonePayload (rsm .RunSummary )); err == nil {
251264 patchURL := fmt .Sprintf (runsPatchEndpoint , rsm .spaceID , response .ID )
252265 if _ , err := rsm .apiClient .JSONPatch (patchURL , donePayload ); err != nil {
253- errs = append (errs , fmt .Errorf ("Error marking run as done : %w" , err ))
266+ errs = append (errs , fmt .Errorf ("PATCH %s : %w" , patchURL , err ))
254267 }
255268 }
256269 }
0 commit comments