You are here

protected function RoboFile::getPatchFilesForDrupalIssue in Panopoly 7

Gets the individual patch files from an issue on Drupal.org

Parameters

int $issue_number: The Drupal.org issue number.

bool $profile_patch: TRUE if the patches found should be applied to the profile; FALSE if they are intended for the individual manyrepos.

Return value

array An associative array of the patches, keyed by repo name.

Throws

\Exception If the repo each patch belongs to can't be worked out.

1 call to RoboFile::getPatchFilesForDrupalIssue()
RoboFile::createTestBranch in ./RoboFile.php
Creates a branch which includes patches from a Drupal.org issue, in order to trigger Travis-CI to test them.

File

./RoboFile.php, line 462

Class

RoboFile
This is project's console commands configuration for Robo task runner.

Code

protected function getPatchFilesForDrupalIssue($issue_number, $profile_patch = FALSE) {
  $node = json_decode(file_get_contents(sprintf(static::DRUPAL_ORG_API_NODE_URL, $issue_number)), TRUE);
  $files = [];
  foreach ($node['field_issue_files'] as $value) {
    if ($value['display'] == '1') {
      $file = json_decode(file_get_contents($value['file']['uri'] . '.json'), TRUE);
      if (!preg_match('/\\.patch$/', $file['name'])) {
        continue;
      }
      $component = NULL;
      if ($profile_patch) {
        $component = 'profile';
      }
      else {
        if (preg_match('/^panopoly[_-]([^_-]+)[_-]/', $file['name'], $matches)) {
          $component = 'panopoly_' . $matches[1];
          if (!in_array($component, $this->PANOPOLY_COMPONENT_MAP)) {
            $component = NULL;
          }
        }
        if (!$component) {
          $component = isset($this->PANOPOLY_COMPONENT_MAP[$node['field_issue_component']]) ? $this->PANOPOLY_COMPONENT_MAP[$node['field_issue_component']] : NULL;
        }
        if (!$component) {
          throw new \Exception("Unable to identify project for patch based on name '{$file['name']}' or issue component '{$node['field_issue_component']}'");
        }
      }
      $files[$component] = $file['url'];
    }
  }
  return $files;
}