private async function genMaybeLogStats()

in src/shipit/ShipItSync.php [199:243]


  private async function genMaybeLogStats(
    vec<ShipItChangeset> $changesets_applied,
    vec<ShipItChangeset> $changesets_skipped,
  ): Awaitable<void> {
    $stats_function = $this->syncConfig->getStatsFunction();
    if ($stats_function is nonnull) {
      $stats_function($changesets_applied, $changesets_skipped);
    }
    $filename = $this->syncConfig->getStatsFilename();
    if ($filename === null) {
      return;
    }
    $destination_branch = $this->manifest->getDestinationBranch();
    // Support logging stats for a project with multiple branches.
    if (PHP\is_dir($filename)) {
      // Slashes are allowed in branch names but not filenames.
      $namesafe_branch =
        Regex\replace($destination_branch, re"/[^a-zA-Z0-9_\-.]/", '_');
      $filename = $filename.'/'.$namesafe_branch.'.json';
    }
    $source_repo = await $this->genRepo<ShipItSourceRepo>();
    $source_changeset = await $source_repo->genHeadChangeset();
    $destination_repo = await $this->genRepo<ShipItDestinationRepo>();
    $destination_changeset = await $destination_repo
      ->genHeadChangeset();
    PHP\file_put_contents(
      $filename,
      \json_encode(dict[
        'source' => dict[
          'id' => $source_changeset?->getID(),
          'timestamp' => $source_changeset?->getTimestamp(),
          'branch' => $this->manifest->getSourceBranch(),
        ],
        'destination' => dict[
          'id' => $destination_changeset?->getID(),
          'timestamp' => $destination_changeset?->getTimestamp(),
          'branch' => $destination_branch,
        ],
        'changesets' =>
          Vec\map($changesets_applied, $changeset ==> $changeset->getID()),
        'skipped' =>
          Vec\map($changesets_skipped, $changeset ==> $changeset->getID()),
      ]),
    );
  }