private static function parseHeader()

in src/shipit/repo/ShipItRepoHG.php [210:249]


  private static function parseHeader(string $header): ShipItChangeset {
    $changeset = new ShipItChangeset();

    $subject = null;
    $message = '';
    $past_separator = false;
    foreach (Str\split($header, "\n") as $line) {
      if (!$past_separator && $line === self::COMMIT_SEPARATOR) {
        $past_separator = true;
        continue;
      }
      if (Str\length($line) === 0) {
        $message .= "\n";
        continue;
      }
      if ($line[0] === '#' && !$past_separator) {
        if (Str\starts_with_ci($line, '# User ')) {
          $changeset = $changeset->withAuthor(Str\slice($line, 7));
          if (!Regex\matches($changeset->getAuthor(), re"/.*<.*>/")) {
            $changeset = $changeset->withAuthor(
              Str\format('%s <>', $changeset->getAuthor()),
            );
          }
        } else if (Str\starts_with_ci($line, '# Date ')) {
          $changeset = $changeset->withTimestamp((int)Str\slice($line, 7));
        }
        // Ignore anything else in the envelope
        continue;
      }
      if ($subject === null) {
        $subject = $line;
        continue;
      }
      $message .= "{$line}\n";
    }

    return $changeset
      ->withSubject((string)$subject)
      ->withMessage(Str\trim($message));
  }