You are here

private function BitbucketFrontendEnvironment::getLastBitbucketDeploymentsTable in Build Hooks 8.2

Same name and namespace in other branches
  1. 3.x modules/build_hooks_bitbucket/src/Plugin/FrontendEnvironment/BitbucketFrontendEnvironment.php \Drupal\build_hooks_bitbucket\Plugin\FrontendEnvironment\BitbucketFrontendEnvironment::getLastBitbucketDeploymentsTable()

Gets info about the latest bitbucket deployments for this environment.

Parameters

array $settings: The plugin settings array.

Return value

array Render array.

Throws

\GuzzleHttp\Exception\GuzzleException When fetching fails.

1 call to BitbucketFrontendEnvironment::getLastBitbucketDeploymentsTable()
BitbucketFrontendEnvironment::getAdditionalDeployFormElements in modules/build_hooks_bitbucket/src/Plugin/FrontendEnvironment/BitbucketFrontendEnvironment.php
Allows the plugin to add elements to the deployment form.

File

modules/build_hooks_bitbucket/src/Plugin/FrontendEnvironment/BitbucketFrontendEnvironment.php, line 206

Class

BitbucketFrontendEnvironment
Provides a 'Bitbucket pipelines' frontend environment type.

Namespace

Drupal\build_hooks_bitbucket\Plugin\FrontendEnvironment

Code

private function getLastBitbucketDeploymentsTable(array $settings) {
  $latestBuilds = $this->bitbucketManager
    ->retrieveLatestBuilds($settings, 15);
  $element = [
    '#type' => 'table',
    '#attributes' => [
      'id' => 'ajax-replace-table',
    ],
    '#header' => [
      $this
        ->t('Build'),
      $this
        ->t('Status'),
      $this
        ->t('Started at'),
      $this
        ->t('Finished at'),
    ],
  ];
  if (!empty($latestBuilds)) {
    foreach ($latestBuilds['values'] as $pipelineId => $pipelineData) {
      $element[$pipelineId]['build'] = [
        '#type' => 'link',
        '#url' => Url::fromUri($pipelineData['repository']['links']['html']['href'] . '/addon/pipelines/home', [
          'fragment' => '!/results/' . $pipelineData['build_number'],
        ]),
        '#title' => 'Build ' . $pipelineData['build_number'],
        '#attributes' => [
          'target' => '_blank',
        ],
      ];
      $element[$pipelineId]['name'] = [
        '#plain_text' => $pipelineData['state']['name'] . ' - ' . $pipelineData['state']['result']['name'],
      ];
      $element[$pipelineId]['started_at'] = [
        '#type' => 'item',
        '#markup' => $pipelineData['created_on'],
      ];
      $element[$pipelineId]['completed_on'] = [
        '#type' => 'item',
        '#markup' => $pipelineData['completed_on'],
      ];
    }
  }
  return $element;
}