stepLogs static method

Stream<AppBuildStepLog> stepLogs(
  1. Client cloudApiClient, {
  2. required String projectId,
  3. required UuidValue buildId,
  4. required Stream<AppBuildDetail> details,
})

Returns the log of each step of the app build buildId of project projectId, in run order, as the build details show the step has ended. Once a detail shows the build has ended, the steps that have not ended follow.

The stream emits a FailureException for each step whose log cannot be fetched, and goes on with the next step.

Implementation

static Stream<AppBuildStepLog> stepLogs(
  Client cloudApiClient, {
  required String projectId,
  required UuidValue buildId,
  required Stream<AppBuildDetail> details,
}) async* {
  var loggedStepCount = 0;
  await for (final detail in details) {
    final remainingSteps = detail.steps.skip(loggedStepCount);
    final stepsToLog = _hasBuildEnded(detail.build.status)
        ? remainingSteps
        : remainingSteps.takeWhile((step) => _hasEnded(step.status));
    for (final step in stepsToLog) {
      loggedStepCount++;
      final String? log;
      try {
        log = _hasLog(step)
            ? await _getStepLog(
                cloudApiClient,
                projectId: projectId,
                buildId: buildId,
                stepIndex: step.index,
              )
            : null;
      } on FailureException catch (e, stackTrace) {
        yield* Stream.error(e, stackTrace);
        continue;
      }
      yield AppBuildStepLog(step: step, log: log);
    }
  }
}