(ctx context.Context, app, deploymentID string)
| 13 | ) |
| 14 | |
| 15 | func Logs(ctx context.Context, app, deploymentID string) error { |
| 16 | client, err := config.ScalingoClient(ctx) |
| 17 | if err != nil { |
| 18 | return errors.Wrapf(ctx, err, "fail to get Scalingo client") |
| 19 | } |
| 20 | if deploymentID == "" { |
| 21 | deployments, err := client.DeploymentList(ctx, app) |
| 22 | if err != nil { |
| 23 | return errors.Wrapf(ctx, err, "fail to get the most recent deployment") |
| 24 | } |
| 25 | if len(deployments) == 0 { |
| 26 | return errors.New(ctx, "This application has not been deployed") |
| 27 | } |
| 28 | deploymentID = deployments[0].ID |
| 29 | io.Infof("-----> Selected the most recent deployment (%s)\n", deploymentID) |
| 30 | } |
| 31 | |
| 32 | deploy, err := client.Deployment(ctx, app, deploymentID) |
| 33 | if err != nil { |
| 34 | return errors.Wrapf(ctx, err, "get deployment %s", deploymentID) |
| 35 | } |
| 36 | |
| 37 | readCloser, err := client.DeploymentLogs(ctx, deploy.Links.Output) |
| 38 | if err != nil { |
| 39 | var requestFailedErr *httpclient.RequestFailedError |
| 40 | if !errors.As(err, &requestFailedErr) || requestFailedErr.Code != http.StatusNotFound { |
| 41 | return errors.Wrap(ctx, err, "fetch deployment logs") |
| 42 | } |
| 43 | |
| 44 | io.Error("There is no log for this deployment.") |
| 45 | return nil |
| 46 | } |
| 47 | defer readCloser.Close() |
| 48 | |
| 49 | _, err = stdio.Copy(os.Stdout, readCloser) |
| 50 | if err != nil { |
| 51 | return errors.Wrap(ctx, err, "copy deployment logs to stdout") |
| 52 | } |
| 53 | return nil |
| 54 | } |
no test coverage detected