Skip to content
Snippets Groups Projects
Commit 389b7c85 authored by Jürgen Haas's avatar Jürgen Haas
Browse files

Issue #3384270 by jurgenhaas: Provide access to all methods of the GitLab client

parent 082f59e3
Branches
Tags
No related merge requests found
Pipeline #202993 failed
......@@ -44,7 +44,7 @@ class Command extends ConfigurableActionBase {
public function defaultConfiguration(): array {
$config = parent::defaultConfiguration();
$config['gitlab'] = '';
foreach ($this->pluginDefinition['params'] as $param) {
foreach ($this->getPluginDefinition()['params'] as $param) {
$config['api_' . $param['name']] = $param['default'];
}
return $config;
......@@ -55,7 +55,7 @@ class Command extends ConfigurableActionBase {
*/
public function buildConfigurationForm(array $form, FormStateInterface $form_state): array {
$instances = [];
foreach ($this->entityTypeManager->getStorage('gitlab_server') as $item) {
foreach ($this->entityTypeManager->getStorage('gitlab_server')->loadMultiple() as $item) {
$instances[$item->id()] = $item->label();
}
$form['gitlab'] = [
......@@ -67,7 +67,7 @@ class Command extends ConfigurableActionBase {
'#weight' => -10,
'#eca_token_select_option' => TRUE,
];
foreach ($this->pluginDefinition['params'] as $param) {
foreach ($this->getPluginDefinition()['params'] as $param) {
$id = 'api_' . $param['name'];
$form[$id] = [
'#type' => is_array($param['default']) ? 'textarea' : 'textfield',
......@@ -103,7 +103,7 @@ class Command extends ConfigurableActionBase {
/**
* {@inheritdoc}
*/
public function execute($object = NULL): void {
public function execute(mixed $object = NULL): void {
$this->api->switchServer($this->configuration['gitlab']);
}
......
......@@ -87,6 +87,7 @@ class CommandDeriver extends DeriverBase {
foreach ($classes as $class) {
$parts = explode('\\', $class);
$className = array_pop($parts);
/** @var array $parts */
$parts = preg_split('/(?=[A-Z])/', $className);
$name = implode(' ', $parts);
$classId = strtolower($className);
......@@ -104,13 +105,17 @@ class CommandDeriver extends DeriverBase {
if ($id === '__construct') {
continue;
}
/** @var array $parts */
$parts = preg_split('/(?=[A-Z])/', $id);
$methodName = implode(' ', $parts);
$id = strtolower($id);
$doc = $reflection->getDocComment();
$params = [];
foreach ($reflection->getParameters() as $parameter) {
$default = $parameter->getType()?->getName() === 'array' ? [] : '';
$default = '';
if (($type = $parameter->getType()) && $type instanceof \ReflectionNamedType && $type->getName() === 'array') {
$default = [];
}
$params[] = [
'position' => $parameter->getPosition(),
'name' => $parameter->getName(),
......
parameters:
level: 6
checkMissingIterableValueType: false
checkGenericClassInNonGenericObjectType: false
ignoreErrors:
- identifier: missingType.iterableValue
......@@ -34,9 +34,9 @@ class Api {
/**
* The GitLab server entity.
*
* @var \Drupal\gitlab_api\Entity\GitlabServer
* @var \Drupal\gitlab_api\Entity\GitlabServer|null
*/
protected GitlabServer $server;
protected ?GitlabServer $server = NULL;
/**
* Api constructor.
......@@ -52,7 +52,7 @@ class Api {
* Initialize client and authenticate session.
*/
protected function init(): void {
if (!isset($this->server)) {
if ($this->server === NULL) {
$this->switchServer();
}
if ($this->client === NULL) {
......
......@@ -81,19 +81,23 @@ class GitlabServer extends ConfigEntityBase {
/**
* Get the default GitLab server.
*
* @return \Drupal\gitlab_api\Entity\GitlabServer|false
* The default GitLab server vondig entity or FALSE, if it doesn't exist.
* @return \Drupal\gitlab_api\Entity\GitlabServer|null
* The default GitLab server vondig entity or NULL, if it doesn't exist.
*/
public static function loadDefaultServer() {
public static function loadDefaultServer(): ?GitlabServer {
try {
/** @var \Drupal\gitlab_api\Entity\GitlabServer $server */
$server = \Drupal::entityTypeManager()
->getStorage('gitlab_server')
->loadByProperties(['default_server' => TRUE]);
if ($server !== NULL && count($server)) {
return reset($server);
}
}
catch (InvalidPluginDefinitionException | PluginNotFoundException $e) {
return FALSE;
catch (InvalidPluginDefinitionException | PluginNotFoundException) {
// Ignored.
}
return $server ? reset($server) : FALSE;
return NULL;
}
/**
......
......@@ -130,6 +130,9 @@ class CreateProject extends WebformHandlerBase {
$path = $this->replaceTokens($this->configuration['path_pattern'], $webform_submission);
$name = $this->replaceTokens($this->configuration['name_pattern'], $webform_submission);
if (is_array($path) || is_array($name)) {
return;
}
$project = $this->api->createProject($this->configuration['namespace'], $path, $name);
$data[$this->configuration['field_gitlab_project']] = json_encode($project);
$data[$this->configuration['field_gitlab_url']] = $project['ssh_url_to_repo'];
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment