Skip to content

Commit

Permalink
Add MS Teams and Jira Integrations APIs
Browse files Browse the repository at this point in the history
  • Loading branch information
PhilippKolmann committed Mar 19, 2024
1 parent 6b80588 commit ea0e3a9
Show file tree
Hide file tree
Showing 5 changed files with 552 additions and 0 deletions.
323 changes: 323 additions & 0 deletions src/Api/Integrations.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,323 @@
<?php

declare(strict_types=1);

/*
* This file is part of the Gitlab API library.
*
* (c) Matt Humphrey <[email protected]>
* (c) Graham Campbell <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Gitlab\Api;

use Symfony\Component\OptionsResolver\Options;
use Symfony\Component\OptionsResolver\OptionsResolver;

class Integrations extends AbstractApi
{
/**
* @param int|string $project_id
* @return mixed
*/
public function all(int|string $project_id): mixed

Check failure on line 26 in src/Api/Integrations.php

View workflow job for this annotation

GitHub Actions / Psalm

ParseError

src/Api/Integrations.php:26:25: ParseError: Union types are not supported in PHP < 8 (see https://psalm.dev/173)

Check failure on line 26 in src/Api/Integrations.php

View workflow job for this annotation

GitHub Actions / Psalm

ReservedWord

src/Api/Integrations.php:26:50: ReservedWord: mixed is a reserved word (see https://psalm.dev/095)
{
$path = $this->getProjectPath($project_id, 'integrations');
return $this->get($path);
}

// Microsoft Teams

/**
* Create Microsoft Teams integration
* Set Microsoft Teams integration for a project
*
* @param int|string $project_id
* @param array $params {
* @var string $webhook The Microsoft Teams webhook.
* @var bool $notify_only_broken_pipelines Send notifications for broken pipelines
* @var string $branches_to_be_notified Branches to send notifications for. Valid options are all, default,
* protected, and default_and_protected. The default value is "default"
* @var bool $push_events Enable notifications for push events
* @var bool $issues_events Enable notifications for issue events
* @var bool $confidential_issues_events Enable notifications for confidential issue events
* @var bool $merge_requests_events Enable notifications for merge request events
* @var bool $tag_push_events Enable notifications for tag push events
* @var bool $note_events Enable notifications for note events
* @var bool $confidential_note_events Enable notifications for confidential note events
* @var bool $pipeline_events Enable notifications for pipeline events
* @var bool $wiki_page_events Enable notifications for wiki page events
* }
*
* @return mixed
*/
public function createMicrosoftTeams(int|string $project_id, array $params = []): mixed

Check failure on line 57 in src/Api/Integrations.php

View workflow job for this annotation

GitHub Actions / Psalm

ParseError

src/Api/Integrations.php:57:42: ParseError: Union types are not supported in PHP < 8 (see https://psalm.dev/173)

Check failure on line 57 in src/Api/Integrations.php

View workflow job for this annotation

GitHub Actions / Psalm

ReservedWord

src/Api/Integrations.php:57:87: ReservedWord: mixed is a reserved word (see https://psalm.dev/095)
{
$resolver = new OptionsResolver();
$booleanNormalizer = function (Options $resolver, $value): string {
return $value ? 'true' : 'false';
};

$resolver->setDefined('webhook')
->setAllowedTypes('webhook', 'string')
->setRequired('webhook')
;
$resolver->setDefined('notify_only_broken_pipelines')
->setAllowedTypes('notify_only_broken_pipelines', 'bool')
->setNormalizer('notify_only_broken_pipelines', $booleanNormalizer)
;
$resolver->setDefined('branches_to_be_notified')
->setAllowedTypes('branches_to_be_notified', 'string')
->setAllowedValues('branches_to_be_notified', ['all', 'default', 'protected', 'default_and_protected'])
;
$resolver->setDefined('push_events')
->setAllowedTypes('push_events', 'bool')
->setNormalizer('push_events', $booleanNormalizer)
;
$resolver->setDefined('issues_events')
->setAllowedTypes('issues_events', 'bool')
->setNormalizer('issues_events', $booleanNormalizer)
;
$resolver->setDefined('confidential_issues_events')
->setAllowedTypes('confidential_issues_events', 'bool')
->setNormalizer('confidential_issues_events', $booleanNormalizer)
;
$resolver->setDefined('merge_requests_events')
->setAllowedTypes('merge_requests_events', 'bool')
->setNormalizer('merge_requests_events', $booleanNormalizer)
;
$resolver->setDefined('tag_push_events')
->setAllowedTypes('tag_push_events', 'bool')
->setNormalizer('tag_push_events', $booleanNormalizer)
;
$resolver->setDefined('note_events')
->setAllowedTypes('note_events', 'bool')
->setNormalizer('note_events', $booleanNormalizer)
;
$resolver->setDefined('confidential_note_events')
->setAllowedTypes('confidential_note_events', 'bool')
->setNormalizer('confidential_note_events', $booleanNormalizer)
;
$resolver->setDefined('pipeline_events')
->setAllowedTypes('pipeline_events', 'bool')
->setNormalizer('pipeline_events', $booleanNormalizer)
;
$resolver->setDefined('wiki_page_events')
->setAllowedTypes('wiki_page_events', 'bool')
->setNormalizer('wiki_page_events', $booleanNormalizer)
;

return $this->put($this->getProjectPath($project_id, 'integrations/microsoft-teams'), $resolver->resolve($params));
}

/**
* Update Microsoft Teams integration
* Set Microsoft Teams integration for a project
*
* @param int|string $project_id
* @param array $params {
* @var string $webhook The Microsoft Teams webhook.
* @var bool $notify_only_broken_pipelines Send notifications for broken pipelines
* @var string $branches_to_be_notified Branches to send notifications for. Valid options are all, default,
* protected, and default_and_protected. The default value is "default"
* @var bool $push_events Enable notifications for push events
* @var bool $issues_events Enable notifications for issue events
* @var bool $confidential_issues_events Enable notifications for confidential issue events
* @var bool $merge_requests_events Enable notifications for merge request events
* @var bool $tag_push_events Enable notifications for tag push events
* @var bool $note_events Enable notifications for note events
* @var bool $confidential_note_events Enable notifications for confidential note events
* @var bool $pipeline_events Enable notifications for pipeline events
* @var bool $wiki_page_events Enable notifications for wiki page events
* }
*
* @return mixed
*/
public function updateMicrosoftTeams(int|string $project_id, array $params = []): mixed

Check failure on line 139 in src/Api/Integrations.php

View workflow job for this annotation

GitHub Actions / Psalm

ParseError

src/Api/Integrations.php:139:42: ParseError: Union types are not supported in PHP < 8 (see https://psalm.dev/173)

Check failure on line 139 in src/Api/Integrations.php

View workflow job for this annotation

GitHub Actions / Psalm

ReservedWord

src/Api/Integrations.php:139:87: ReservedWord: mixed is a reserved word (see https://psalm.dev/095)
{
return $this->createMicrosoftTeams($project_id, $params);
}

/**
* Get Microsoft Teams integration settings for a project
*
* @param int|string $project_id
* @return mixed
*/
public function getMicrosoftTeams(int|string $project_id): mixed

Check failure on line 150 in src/Api/Integrations.php

View workflow job for this annotation

GitHub Actions / Psalm

ParseError

src/Api/Integrations.php:150:39: ParseError: Union types are not supported in PHP < 8 (see https://psalm.dev/173)

Check failure on line 150 in src/Api/Integrations.php

View workflow job for this annotation

GitHub Actions / Psalm

ReservedWord

src/Api/Integrations.php:150:64: ReservedWord: mixed is a reserved word (see https://psalm.dev/095)
{
return $this->get($this->getProjectPath($project_id, 'integrations/microsoft-teams'));
}

/**
* Disable the Microsoft Teams integration for a project. Integration settings are reset
*
* @param int|string $project_id
* @return mixed
*/
public function removeMicrosoftTeams(int|string $project_id): mixed

Check failure on line 161 in src/Api/Integrations.php

View workflow job for this annotation

GitHub Actions / Psalm

ParseError

src/Api/Integrations.php:161:42: ParseError: Union types are not supported in PHP < 8 (see https://psalm.dev/173)

Check failure on line 161 in src/Api/Integrations.php

View workflow job for this annotation

GitHub Actions / Psalm

ReservedWord

src/Api/Integrations.php:161:67: ReservedWord: mixed is a reserved word (see https://psalm.dev/095)
{
return $this->delete($this->getProjectPath($project_id, 'integrations/microsoft-teams'));
}


// JIRA

/**
* Create Jira integration
* Set Jira integration for a project
*
* @param int|string $project_id
* @param array $params {
* @var string $url The URL to the Jira project which is being linked to this GitLab project
* @var bool $api_url The base URL to the Jira instance API. Web URL value is used if not set
* @var string $username The email or username to be used with Jira. For Jira Cloud use an email,
* for Jira Data Center and Jira Server use a username. Required when using
* Basic authentication (jira_auth_type is 0)
* @var string $password The Jira API token, password, or personal access token to be used with
* Jira. When your authentication method is Basic (jira_auth_type is 0) use
* an API token for Jira Cloud, or a password for Jira Data Center or Jira
* Server. When your authentication method is Jira personal access token
* (jira_auth_type is 1) use a personal access token.
* @var string $active Activates or deactivates the integration. Defaults to false (deactivated).
* @var string $jira_auth_type The authentication method to be used with Jira. 0 means Basic
* Authentication. 1 means Jira personal access token. Defaults to 0.
* @var string $jira_issue_prefix Prefix to match Jira issue keys.
* @var string $jira_issue_regex Regular expression to match Jira issue keys.
* @var string $jira_issue_transition_automatic Enable automatic issue transitions. Takes precedence over
* jira_issue_transition_id if enabled. Defaults to false
* @var string $jira_issue_transition_id The ID of one or more transitions for custom issue
* transitions. Ignored if jira_issue_transition_automatic is
* enabled. Defaults to a blank string, which disables custom
* transitions.
* @var string $commit_events Enable notifications for commit events
* @var string $merge_requests_events Enable notifications for merge request events
* @var string $comment_on_event_enabled Enable comments inside Jira issues on each GitLab event
* (commit / merge request)
* }
*
* @return mixed
*/
public function createJira(int|string $project_id, array $params = []): mixed
{
$resolver = new OptionsResolver();
$booleanNormalizer = function (Options $resolver, $value): string {
return $value ? 'true' : 'false';
};

$resolver->setDefined('url')
->setAllowedTypes('url', 'string')
->setRequired('url')
;
$resolver->setDefined('api_url')
->setAllowedTypes('api_url', 'string')
;
$resolver->setDefined('username')
->setAllowedTypes('username', 'string')
;
$resolver->setDefined('password')
->setAllowedTypes('password', 'string')
->setRequired('password')
;
$resolver->setDefined('active')
->setAllowedTypes('active', 'bool')
->setNormalizer('active', $booleanNormalizer)
;
$resolver->setDefined('jira_auth_type')
->setAllowedTypes('jira_auth_type', 'int')
;
$resolver->setDefined('jira_issue_prefix')
->setAllowedTypes('jira_issue_prefix', 'string')
;
$resolver->setDefined('jira_issue_regex')
->setAllowedTypes('jira_issue_regex', 'string')
;
$resolver->setDefined('jira_issue_transition_automatic')
->setAllowedTypes('jira_issue_transition_automatic', 'bool')
->setNormalizer('jira_issue_transition_automatic', $booleanNormalizer)
;
$resolver->setDefined('jira_issue_transition_id')
->setAllowedTypes('jira_issue_transition_id', 'string')
;
$resolver->setDefined('commit_events')
->setAllowedTypes('commit_events', 'bool')
->setNormalizer('commit_events', $booleanNormalizer)
;
$resolver->setDefined('merge_requests_events')
->setAllowedTypes('merge_requests_events', 'bool')
->setNormalizer('merge_requests_events', $booleanNormalizer)
;
$resolver->setDefined('comment_on_event_enabled')
->setAllowedTypes('comment_on_event_enabled', 'bool')
->setNormalizer('comment_on_event_enabled', $booleanNormalizer)
;

return $this->put($this->getProjectPath($project_id, 'integrations/jira'), $resolver->resolve($params));
}

/**
* Update Jira integration
* Set Jira integration for a project
*
* @param int|string $project_id
* @param array $params {
* @var string $url The URL to the Jira project which is being linked to this GitLab project
* @var bool $api_url The base URL to the Jira instance API. Web URL value is used if not set
* @var string $username The email or username to be used with Jira. For Jira Cloud use an email,
* for Jira Data Center and Jira Server use a username. Required when using
* Basic authentication (jira_auth_type is 0)
* @var string $password The Jira API token, password, or personal access token to be used with
* Jira. When your authentication method is Basic (jira_auth_type is 0) use
* an API token for Jira Cloud, or a password for Jira Data Center or Jira
* Server. When your authentication method is Jira personal access token
* (jira_auth_type is 1) use a personal access token.
* @var string $active Activates or deactivates the integration. Defaults to false (deactivated).
* @var string $jira_auth_type The authentication method to be used with Jira. 0 means Basic
* Authentication. 1 means Jira personal access token. Defaults to 0.
* @var string $jira_issue_prefix Prefix to match Jira issue keys.
* @var string $jira_issue_regex Regular expression to match Jira issue keys.
* @var string $jira_issue_transition_automatic Enable automatic issue transitions. Takes precedence over
* jira_issue_transition_id if enabled. Defaults to false
* @var string $jira_issue_transition_id The ID of one or more transitions for custom issue
* transitions. Ignored if jira_issue_transition_automatic is
* enabled. Defaults to a blank string, which disables custom
* transitions.
* @var string $commit_events Enable notifications for commit events
* @var string $merge_requests_events Enable notifications for merge request events
* @var string $comment_on_event_enabled Enable comments inside Jira issues on each GitLab event
* (commit / merge request)
* }
*
* @return mixed
*/
public function updateJira(int|string $project_id, array $params = []): mixed
{
return $this->createJira($project_id, $params);
}

/**
* Get Jira integration settings for a project
*
* @param int|string $project_id
* @return mixed
*/
public function getJira(int|string $project_id): mixed
{
return $this->get($this->getProjectPath($project_id, 'integrations/jira'));
}

/**
* Disable the Jira integration for a project. Integration settings are reset
*
* @param int|string $project_id
* @return mixed
*/
public function removeJira(int|string $project_id): mixed
{
return $this->delete($this->getProjectPath($project_id, 'integrations/jira'));
}

}
12 changes: 12 additions & 0 deletions src/Api/Projects.php
Original file line number Diff line number Diff line change
Expand Up @@ -1832,4 +1832,16 @@ public function search($id, array $parameters = [])

return $this->get('projects/'.self::encodePath($id).'/search', $resolver->resolve($parameters));
}


/**
* @param int|string $project_id
*
* @return mixed
*/
public function integrations($project_id)
{
return $this->get($this->getProjectPath($project_id, 'integrations'));
}

}
9 changes: 9 additions & 0 deletions src/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
use Gitlab\Api\GroupsBoards;
use Gitlab\Api\GroupsEpics;
use Gitlab\Api\GroupsMilestones;
use Gitlab\Api\Integrations;
use Gitlab\Api\IssueBoards;
use Gitlab\Api\IssueLinks;
use Gitlab\Api\Issues;
Expand Down Expand Up @@ -216,6 +217,14 @@ public function groupsMilestones(): GroupsMilestones
return new GroupsMilestones($this);
}

/**
* @return Integrations
*/
public function integrations(): Integrations
{
return new Integrations($this);
}

/**
* @return IssueBoards
*/
Expand Down
Loading

0 comments on commit ea0e3a9

Please sign in to comment.