Skip to content
Snippets Groups Projects
Commit e53adba8 authored by Daniel Speicher's avatar Daniel Speicher
Browse files

Issue #3442076: Implement interfaces of framework

parent 51933657
No related branches found
No related tags found
Loading
Pipeline #156615 failed
......@@ -8,6 +8,7 @@ use Drupal\helpdesk_integration\HelpdeskInterface;
use Drupal\helpdesk_integration\IssueInterface;
use Drupal\helpdesk_integration\PluginBase;
use Drupal\user\UserInterface;
use Gitlab\Client;
/**
* Plugin implementation of the GitLab.
......@@ -22,6 +23,13 @@ class GitLab extends PluginBase {
use StringTranslationTrait;
/**
* The GitLab client.
*
* @var \Gitlab\Client|null
*/
protected ?Client $client = NULL;
/**
* {@inheritdoc}
*/
......@@ -46,6 +54,7 @@ class GitLab extends PluginBase {
$form['api_token'] = [
'#type' => 'textfield',
'#title' => $this->t('API Token'),
'#default_value' => $helpdesk->get('api_token'),
] + $required;
$form['project_id'] = [
'#type' => 'textfield',
......@@ -55,6 +64,7 @@ class GitLab extends PluginBase {
$form['max_file_size'] = [
'#type' => 'number',
'#title' => $this->t('Max. file size for attachments (in MB)'),
'#default_value' => $helpdesk->get('max_file_size'),
'#min' => 1,
] + $required;
......@@ -79,7 +89,12 @@ class GitLab extends PluginBase {
* {@inheritdoc}
*/
public function createIssue(HelpdeskInterface $helpdesk, IssueInterface $issue): void {
// @todo Implement createIssue() method.
$incident = $this->getClient($helpdesk)->issues()
->create($helpdesk->get('project_id'), [
'type' => 'INCIDENT',
'title' => $issue->getTitle(),
'description' => $issue->get('body')->value,
]);
}
/**
......@@ -103,4 +118,22 @@ class GitLab extends PluginBase {
return FALSE;
}
/**
* Gets the GitLAb client and initializes if necessary.
*
* @param \Drupal\helpdesk_integration\HelpdeskInterface $helpdesk
* The helpdesk.
*
* @return \Gitlab\Client
* The GitLab client.
*/
private function getClient(HelpdeskInterface $helpdesk): Client {
if (!$this->client) {
$this->client = new Client();
$this->client->setUrl($helpdesk->get('url'));
$this->client->authenticate($helpdesk->get('api_token'), Client::AUTH_HTTP_TOKEN);
}
return $this->client;
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment