You are here

public function CircleV2::getBuildHookDetails in Build Hooks 3.x

Same name and namespace in other branches
  1. 8.2 modules/build_hooks_circleci/src/Plugin/FrontendEnvironment/CircleV2.php \Drupal\build_hooks_circleci\Plugin\FrontendEnvironment\CircleV2::getBuildHookDetails()

Get the info to trigger the hook based on the configuration of the plugin.

Return value

\Drupal\build_hooks\BuildHookDetails An object containing the details to trigger the hook.

Overrides FrontendEnvironmentInterface::getBuildHookDetails

File

modules/build_hooks_circleci/src/Plugin/FrontendEnvironment/CircleV2.php, line 256

Class

CircleV2
Defines a circle v2 environment.

Namespace

Drupal\build_hooks_circleci\Plugin\FrontendEnvironment

Code

public function getBuildHookDetails() {
  $buildHookDetails = new BuildHookDetails();
  $buildHookDetails
    ->setOptions([
    'json' => [
      $this->configuration['type'] => $this->configuration['reference'],
      'parameters' => array_reduce($this->configuration['parameters'], function (array $carry, array $item) {
        switch ($item['type']) {
          case 'boolean':
            $carry[$item['name']] = (bool) $item['value'];
            return $carry;
          case 'integer':
            $carry[$item['name']] = (int) $item['value'];
            return $carry;
          default:
            $carry[$item['name']] = $item['value'];
        }
        return $carry;
      }, []),
    ],
    'auth' => [
      $this->configuration['token'],
      '',
    ],
  ]);
  $buildHookDetails
    ->setMethod('POST');
  $buildHookDetails
    ->setUrl('https://circleci.com/api/v2/project/gh/' . $this->configuration['project'] . '/pipeline');
  return $buildHookDetails;
}