public static function getSections()

in src/shipit/filter/ShipItMessageSections.php [59:100]


  public static function getSections(
    ShipItChangeset $changeset,
    ?keyset<ShipItMessageSectionHeaders> $valid_sections = null,
  ): dict<string, string> {
    $sections = dict[ShipItMessageSectionHeaders::_NO_HEADER => ''];
    $section = '';
    foreach (Str\split($changeset->getMessage(), "\n") as $line) {
      $line = Str\trim_right($line);
      if (Regex\matches($line, re'/^[a-zA-Z ]+:/')) {
        $h = Str\lowercase(Str\slice($line, 0, Str\search($line, ':')));
        if ($valid_sections === null || C\contains($valid_sections, $h)) {
          $section = $h;
          $value = Str\trim(Str\slice($line, Str\length($section) + 1));

          // Treat "Summary: FBOnly: bar" as "FBOnly: bar" - handy if using
          // Phabricator
          if (
            Regex\matches($value, re'/^[a-zA-Z ]+:/') &&
            $valid_sections !== null
          ) {
            $h = Str\lowercase(Str\slice($value, 0, Str\search($value, ':')));
            if (C\contains($valid_sections, $h)) {
              $section = $h;
              $value = Str\trim(Str\slice($value, Str\length($section) + 1));
            }
          }
          if (C\contains_key($sections, $section)) {
            $sections[$section] .= $value;
          } else {
            $sections[$section] = $value;
          }
          continue;
        }
      }
      $sections[$section] .= "\n{$line}";
    }
    if ($sections[""] === '') {
      unset($sections['']);
    }

    return Dict\map($sections, $x ==> Str\trim($x));
  }