Skip to content

Commit ea0e3a9

Browse files
Add MS Teams and Jira Integrations APIs
1 parent 6b80588 commit ea0e3a9

File tree

5 files changed

+552
-0
lines changed

5 files changed

+552
-0
lines changed

src/Api/Integrations.php

+323
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,323 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
/*
6+
* This file is part of the Gitlab API library.
7+
*
8+
* (c) Matt Humphrey <[email protected]>
9+
* (c) Graham Campbell <[email protected]>
10+
*
11+
* For the full copyright and license information, please view the LICENSE
12+
* file that was distributed with this source code.
13+
*/
14+
15+
namespace Gitlab\Api;
16+
17+
use Symfony\Component\OptionsResolver\Options;
18+
use Symfony\Component\OptionsResolver\OptionsResolver;
19+
20+
class Integrations extends AbstractApi
21+
{
22+
/**
23+
* @param int|string $project_id
24+
* @return mixed
25+
*/
26+
public function all(int|string $project_id): mixed
27+
{
28+
$path = $this->getProjectPath($project_id, 'integrations');
29+
return $this->get($path);
30+
}
31+
32+
// Microsoft Teams
33+
34+
/**
35+
* Create Microsoft Teams integration
36+
* Set Microsoft Teams integration for a project
37+
*
38+
* @param int|string $project_id
39+
* @param array $params {
40+
* @var string $webhook The Microsoft Teams webhook.
41+
* @var bool $notify_only_broken_pipelines Send notifications for broken pipelines
42+
* @var string $branches_to_be_notified Branches to send notifications for. Valid options are all, default,
43+
* protected, and default_and_protected. The default value is "default"
44+
* @var bool $push_events Enable notifications for push events
45+
* @var bool $issues_events Enable notifications for issue events
46+
* @var bool $confidential_issues_events Enable notifications for confidential issue events
47+
* @var bool $merge_requests_events Enable notifications for merge request events
48+
* @var bool $tag_push_events Enable notifications for tag push events
49+
* @var bool $note_events Enable notifications for note events
50+
* @var bool $confidential_note_events Enable notifications for confidential note events
51+
* @var bool $pipeline_events Enable notifications for pipeline events
52+
* @var bool $wiki_page_events Enable notifications for wiki page events
53+
* }
54+
*
55+
* @return mixed
56+
*/
57+
public function createMicrosoftTeams(int|string $project_id, array $params = []): mixed
58+
{
59+
$resolver = new OptionsResolver();
60+
$booleanNormalizer = function (Options $resolver, $value): string {
61+
return $value ? 'true' : 'false';
62+
};
63+
64+
$resolver->setDefined('webhook')
65+
->setAllowedTypes('webhook', 'string')
66+
->setRequired('webhook')
67+
;
68+
$resolver->setDefined('notify_only_broken_pipelines')
69+
->setAllowedTypes('notify_only_broken_pipelines', 'bool')
70+
->setNormalizer('notify_only_broken_pipelines', $booleanNormalizer)
71+
;
72+
$resolver->setDefined('branches_to_be_notified')
73+
->setAllowedTypes('branches_to_be_notified', 'string')
74+
->setAllowedValues('branches_to_be_notified', ['all', 'default', 'protected', 'default_and_protected'])
75+
;
76+
$resolver->setDefined('push_events')
77+
->setAllowedTypes('push_events', 'bool')
78+
->setNormalizer('push_events', $booleanNormalizer)
79+
;
80+
$resolver->setDefined('issues_events')
81+
->setAllowedTypes('issues_events', 'bool')
82+
->setNormalizer('issues_events', $booleanNormalizer)
83+
;
84+
$resolver->setDefined('confidential_issues_events')
85+
->setAllowedTypes('confidential_issues_events', 'bool')
86+
->setNormalizer('confidential_issues_events', $booleanNormalizer)
87+
;
88+
$resolver->setDefined('merge_requests_events')
89+
->setAllowedTypes('merge_requests_events', 'bool')
90+
->setNormalizer('merge_requests_events', $booleanNormalizer)
91+
;
92+
$resolver->setDefined('tag_push_events')
93+
->setAllowedTypes('tag_push_events', 'bool')
94+
->setNormalizer('tag_push_events', $booleanNormalizer)
95+
;
96+
$resolver->setDefined('note_events')
97+
->setAllowedTypes('note_events', 'bool')
98+
->setNormalizer('note_events', $booleanNormalizer)
99+
;
100+
$resolver->setDefined('confidential_note_events')
101+
->setAllowedTypes('confidential_note_events', 'bool')
102+
->setNormalizer('confidential_note_events', $booleanNormalizer)
103+
;
104+
$resolver->setDefined('pipeline_events')
105+
->setAllowedTypes('pipeline_events', 'bool')
106+
->setNormalizer('pipeline_events', $booleanNormalizer)
107+
;
108+
$resolver->setDefined('wiki_page_events')
109+
->setAllowedTypes('wiki_page_events', 'bool')
110+
->setNormalizer('wiki_page_events', $booleanNormalizer)
111+
;
112+
113+
return $this->put($this->getProjectPath($project_id, 'integrations/microsoft-teams'), $resolver->resolve($params));
114+
}
115+
116+
/**
117+
* Update Microsoft Teams integration
118+
* Set Microsoft Teams integration for a project
119+
*
120+
* @param int|string $project_id
121+
* @param array $params {
122+
* @var string $webhook The Microsoft Teams webhook.
123+
* @var bool $notify_only_broken_pipelines Send notifications for broken pipelines
124+
* @var string $branches_to_be_notified Branches to send notifications for. Valid options are all, default,
125+
* protected, and default_and_protected. The default value is "default"
126+
* @var bool $push_events Enable notifications for push events
127+
* @var bool $issues_events Enable notifications for issue events
128+
* @var bool $confidential_issues_events Enable notifications for confidential issue events
129+
* @var bool $merge_requests_events Enable notifications for merge request events
130+
* @var bool $tag_push_events Enable notifications for tag push events
131+
* @var bool $note_events Enable notifications for note events
132+
* @var bool $confidential_note_events Enable notifications for confidential note events
133+
* @var bool $pipeline_events Enable notifications for pipeline events
134+
* @var bool $wiki_page_events Enable notifications for wiki page events
135+
* }
136+
*
137+
* @return mixed
138+
*/
139+
public function updateMicrosoftTeams(int|string $project_id, array $params = []): mixed
140+
{
141+
return $this->createMicrosoftTeams($project_id, $params);
142+
}
143+
144+
/**
145+
* Get Microsoft Teams integration settings for a project
146+
*
147+
* @param int|string $project_id
148+
* @return mixed
149+
*/
150+
public function getMicrosoftTeams(int|string $project_id): mixed
151+
{
152+
return $this->get($this->getProjectPath($project_id, 'integrations/microsoft-teams'));
153+
}
154+
155+
/**
156+
* Disable the Microsoft Teams integration for a project. Integration settings are reset
157+
*
158+
* @param int|string $project_id
159+
* @return mixed
160+
*/
161+
public function removeMicrosoftTeams(int|string $project_id): mixed
162+
{
163+
return $this->delete($this->getProjectPath($project_id, 'integrations/microsoft-teams'));
164+
}
165+
166+
167+
// JIRA
168+
169+
/**
170+
* Create Jira integration
171+
* Set Jira integration for a project
172+
*
173+
* @param int|string $project_id
174+
* @param array $params {
175+
* @var string $url The URL to the Jira project which is being linked to this GitLab project
176+
* @var bool $api_url The base URL to the Jira instance API. Web URL value is used if not set
177+
* @var string $username The email or username to be used with Jira. For Jira Cloud use an email,
178+
* for Jira Data Center and Jira Server use a username. Required when using
179+
* Basic authentication (jira_auth_type is 0)
180+
* @var string $password The Jira API token, password, or personal access token to be used with
181+
* Jira. When your authentication method is Basic (jira_auth_type is 0) use
182+
* an API token for Jira Cloud, or a password for Jira Data Center or Jira
183+
* Server. When your authentication method is Jira personal access token
184+
* (jira_auth_type is 1) use a personal access token.
185+
* @var string $active Activates or deactivates the integration. Defaults to false (deactivated).
186+
* @var string $jira_auth_type The authentication method to be used with Jira. 0 means Basic
187+
* Authentication. 1 means Jira personal access token. Defaults to 0.
188+
* @var string $jira_issue_prefix Prefix to match Jira issue keys.
189+
* @var string $jira_issue_regex Regular expression to match Jira issue keys.
190+
* @var string $jira_issue_transition_automatic Enable automatic issue transitions. Takes precedence over
191+
* jira_issue_transition_id if enabled. Defaults to false
192+
* @var string $jira_issue_transition_id The ID of one or more transitions for custom issue
193+
* transitions. Ignored if jira_issue_transition_automatic is
194+
* enabled. Defaults to a blank string, which disables custom
195+
* transitions.
196+
* @var string $commit_events Enable notifications for commit events
197+
* @var string $merge_requests_events Enable notifications for merge request events
198+
* @var string $comment_on_event_enabled Enable comments inside Jira issues on each GitLab event
199+
* (commit / merge request)
200+
* }
201+
*
202+
* @return mixed
203+
*/
204+
public function createJira(int|string $project_id, array $params = []): mixed
205+
{
206+
$resolver = new OptionsResolver();
207+
$booleanNormalizer = function (Options $resolver, $value): string {
208+
return $value ? 'true' : 'false';
209+
};
210+
211+
$resolver->setDefined('url')
212+
->setAllowedTypes('url', 'string')
213+
->setRequired('url')
214+
;
215+
$resolver->setDefined('api_url')
216+
->setAllowedTypes('api_url', 'string')
217+
;
218+
$resolver->setDefined('username')
219+
->setAllowedTypes('username', 'string')
220+
;
221+
$resolver->setDefined('password')
222+
->setAllowedTypes('password', 'string')
223+
->setRequired('password')
224+
;
225+
$resolver->setDefined('active')
226+
->setAllowedTypes('active', 'bool')
227+
->setNormalizer('active', $booleanNormalizer)
228+
;
229+
$resolver->setDefined('jira_auth_type')
230+
->setAllowedTypes('jira_auth_type', 'int')
231+
;
232+
$resolver->setDefined('jira_issue_prefix')
233+
->setAllowedTypes('jira_issue_prefix', 'string')
234+
;
235+
$resolver->setDefined('jira_issue_regex')
236+
->setAllowedTypes('jira_issue_regex', 'string')
237+
;
238+
$resolver->setDefined('jira_issue_transition_automatic')
239+
->setAllowedTypes('jira_issue_transition_automatic', 'bool')
240+
->setNormalizer('jira_issue_transition_automatic', $booleanNormalizer)
241+
;
242+
$resolver->setDefined('jira_issue_transition_id')
243+
->setAllowedTypes('jira_issue_transition_id', 'string')
244+
;
245+
$resolver->setDefined('commit_events')
246+
->setAllowedTypes('commit_events', 'bool')
247+
->setNormalizer('commit_events', $booleanNormalizer)
248+
;
249+
$resolver->setDefined('merge_requests_events')
250+
->setAllowedTypes('merge_requests_events', 'bool')
251+
->setNormalizer('merge_requests_events', $booleanNormalizer)
252+
;
253+
$resolver->setDefined('comment_on_event_enabled')
254+
->setAllowedTypes('comment_on_event_enabled', 'bool')
255+
->setNormalizer('comment_on_event_enabled', $booleanNormalizer)
256+
;
257+
258+
return $this->put($this->getProjectPath($project_id, 'integrations/jira'), $resolver->resolve($params));
259+
}
260+
261+
/**
262+
* Update Jira integration
263+
* Set Jira integration for a project
264+
*
265+
* @param int|string $project_id
266+
* @param array $params {
267+
* @var string $url The URL to the Jira project which is being linked to this GitLab project
268+
* @var bool $api_url The base URL to the Jira instance API. Web URL value is used if not set
269+
* @var string $username The email or username to be used with Jira. For Jira Cloud use an email,
270+
* for Jira Data Center and Jira Server use a username. Required when using
271+
* Basic authentication (jira_auth_type is 0)
272+
* @var string $password The Jira API token, password, or personal access token to be used with
273+
* Jira. When your authentication method is Basic (jira_auth_type is 0) use
274+
* an API token for Jira Cloud, or a password for Jira Data Center or Jira
275+
* Server. When your authentication method is Jira personal access token
276+
* (jira_auth_type is 1) use a personal access token.
277+
* @var string $active Activates or deactivates the integration. Defaults to false (deactivated).
278+
* @var string $jira_auth_type The authentication method to be used with Jira. 0 means Basic
279+
* Authentication. 1 means Jira personal access token. Defaults to 0.
280+
* @var string $jira_issue_prefix Prefix to match Jira issue keys.
281+
* @var string $jira_issue_regex Regular expression to match Jira issue keys.
282+
* @var string $jira_issue_transition_automatic Enable automatic issue transitions. Takes precedence over
283+
* jira_issue_transition_id if enabled. Defaults to false
284+
* @var string $jira_issue_transition_id The ID of one or more transitions for custom issue
285+
* transitions. Ignored if jira_issue_transition_automatic is
286+
* enabled. Defaults to a blank string, which disables custom
287+
* transitions.
288+
* @var string $commit_events Enable notifications for commit events
289+
* @var string $merge_requests_events Enable notifications for merge request events
290+
* @var string $comment_on_event_enabled Enable comments inside Jira issues on each GitLab event
291+
* (commit / merge request)
292+
* }
293+
*
294+
* @return mixed
295+
*/
296+
public function updateJira(int|string $project_id, array $params = []): mixed
297+
{
298+
return $this->createJira($project_id, $params);
299+
}
300+
301+
/**
302+
* Get Jira integration settings for a project
303+
*
304+
* @param int|string $project_id
305+
* @return mixed
306+
*/
307+
public function getJira(int|string $project_id): mixed
308+
{
309+
return $this->get($this->getProjectPath($project_id, 'integrations/jira'));
310+
}
311+
312+
/**
313+
* Disable the Jira integration for a project. Integration settings are reset
314+
*
315+
* @param int|string $project_id
316+
* @return mixed
317+
*/
318+
public function removeJira(int|string $project_id): mixed
319+
{
320+
return $this->delete($this->getProjectPath($project_id, 'integrations/jira'));
321+
}
322+
323+
}

src/Api/Projects.php

+12
Original file line numberDiff line numberDiff line change
@@ -1832,4 +1832,16 @@ public function search($id, array $parameters = [])
18321832

18331833
return $this->get('projects/'.self::encodePath($id).'/search', $resolver->resolve($parameters));
18341834
}
1835+
1836+
1837+
/**
1838+
* @param int|string $project_id
1839+
*
1840+
* @return mixed
1841+
*/
1842+
public function integrations($project_id)
1843+
{
1844+
return $this->get($this->getProjectPath($project_id, 'integrations'));
1845+
}
1846+
18351847
}

src/Client.php

+9
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
use Gitlab\Api\GroupsBoards;
2323
use Gitlab\Api\GroupsEpics;
2424
use Gitlab\Api\GroupsMilestones;
25+
use Gitlab\Api\Integrations;
2526
use Gitlab\Api\IssueBoards;
2627
use Gitlab\Api\IssueLinks;
2728
use Gitlab\Api\Issues;
@@ -216,6 +217,14 @@ public function groupsMilestones(): GroupsMilestones
216217
return new GroupsMilestones($this);
217218
}
218219

220+
/**
221+
* @return Integrations
222+
*/
223+
public function integrations(): Integrations
224+
{
225+
return new Integrations($this);
226+
}
227+
219228
/**
220229
* @return IssueBoards
221230
*/

0 commit comments

Comments
 (0)