planAvailability function

PlanAvailability planAvailability(
  1. ChangePlan plan,
  2. PlanLocationRecord? location, {
  3. PathExists pathExists = _pathExists,
  4. ReadTextFile readTextFile = _readTextFile,
})

Implementation

PlanAvailability planAvailability(
  ChangePlan plan,
  PlanLocationRecord? location, {
  PathExists pathExists = _pathExists,
  ReadTextFile readTextFile = _readTextFile,
}) {
  if (location == null || !pathExists(location.stagingRoot)) {
    return const PlanAvailability(contentReviewAvailable: false);
  }

  final contents = <String, String>{};
  for (final operation in plan.operations) {
    final path =
        '${location.stagingRoot}${Platform.pathSeparator}'
        '${operation.logicalPath.replaceAll('/', Platform.pathSeparator)}';
    if (!pathExists(path)) {
      return const PlanAvailability(contentReviewAvailable: false);
    }
    contents[operation.logicalPath] = readTextFile(path);
  }
  return PlanAvailability(
    contentReviewAvailable: true,
    contents: Map.unmodifiable(contents),
  );
}