func checkCurrentStatus()

in pkg/plan/track_change.go [150:192]


func checkCurrentStatus(params TrackChangeParams, c chan<- TrackResponse, changedResources []string, retries int) {
	res, err := params.V1API.Deployments.GetDeployment(
		deployments.NewGetDeploymentParams().
			WithDeploymentID(params.DeploymentID).
			WithShowPlanLogs(ec.Bool(true)).
			WithShowPlans(ec.Bool(true)).
			// Necessary for deployments which failed on creation
			WithShowPlanHistory(ec.Bool(true)),
		params.AuthWriter,
	)
	if err != nil {
		// retry the API call again until params.Config.MaxRetries is reached.
		if retries < params.Config.MaxRetries {
			retries++
			checkCurrentStatus(params, c, changedResources, retries)
		}
		return
	}

	for _, trackResponse := range buildTrackResponse(res.Payload.Resources, true) {
		trackResponse.DeploymentID = *res.Payload.ID
		ignoreChange := params.ResourceID != trackResponse.ID && params.IgnoreDownstream

		// This conditional catches plans that failed but finished before the
		// plan tracker had the chance to call the API, changedResources will be
		// 0 length.
		// Since we'd still like to report on any failures that that plan might
		// have had, we're effectively sending a message to the plan tracker
		// when the current plan ended with an error.
		if len(changedResources) == 0 && trackResponse.Err != nil {
			if !ignoreChange {
				c <- trackResponse
			}
			continue
		}

		if slice.HasString(changedResources, trackResponse.ID) {
			if !ignoreChange {
				c <- trackResponse
			}
		}
	}
}