Skip to content

Commit a15e756

Browse files
Add group hook endpoints
1 parent f946d06 commit a15e756

4 files changed

Lines changed: 437 additions & 0 deletions

File tree

‎CHANGELOG.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1212
* Add support for `visibility` in `Groups::all`
1313
* Add support for personal access tokens
1414
* Add support for project integrations endpoints
15+
* Add support for group hook endpoints
1516
* Add support for `job_inputs` and `job_variables_attributes` in `Jobs::play`
1617
* Add support for filters in `Projects::projectAccessTokens`
1718
* Add support for `Projects::rotateProjectAccessToken`

‎src/Api/GroupsHooks.php‎

Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
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 <matth@windsor-telecom.co.uk>
9+
* (c) Graham Campbell <hello@gjcampbell.co.uk>
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+
class GroupsHooks extends AbstractApi
18+
{
19+
/**
20+
* @param array $parameters {
21+
*
22+
* @var int $page page number
23+
* @var int $per_page number of items to list per page
24+
* }
25+
*/
26+
public function all(int|string $group_id, array $parameters = []): mixed
27+
{
28+
$resolver = $this->createOptionsResolver();
29+
30+
return $this->get('groups/'.self::encodePath($group_id).'/hooks', $resolver->resolve($parameters));
31+
}
32+
33+
public function show(int|string $group_id, int $hook_id): mixed
34+
{
35+
return $this->get('groups/'.self::encodePath($group_id).'/hooks/'.self::encodePath($hook_id));
36+
}
37+
38+
/**
39+
* Create a group hook.
40+
*
41+
* Hook parameters vary across GitLab versions and are passed through.
42+
*
43+
* @see https://docs.gitlab.com/api/group_webhooks/#create-a-group-hook
44+
*
45+
* @param array<string,mixed> $parameters
46+
*/
47+
public function create(int|string $group_id, string $url, array $parameters = []): mixed
48+
{
49+
$parameters['url'] = $url;
50+
51+
return $this->post('groups/'.self::encodePath($group_id).'/hooks', $parameters);
52+
}
53+
54+
/**
55+
* Update a group hook.
56+
*
57+
* Hook parameters vary across GitLab versions and are passed through.
58+
*
59+
* @see https://docs.gitlab.com/api/group_webhooks/#update-a-group-hook
60+
*
61+
* @param array<string,mixed> $parameters
62+
*/
63+
public function update(int|string $group_id, int $hook_id, array $parameters): mixed
64+
{
65+
return $this->put('groups/'.self::encodePath($group_id).'/hooks/'.self::encodePath($hook_id), $parameters);
66+
}
67+
68+
public function remove(int|string $group_id, int $hook_id): mixed
69+
{
70+
return $this->delete('groups/'.self::encodePath($group_id).'/hooks/'.self::encodePath($hook_id));
71+
}
72+
73+
/**
74+
* @param array $parameters {
75+
*
76+
* @var int $page page number
77+
* @var int $per_page number of items to list per page
78+
* @var int|string $status response status code or status category
79+
* }
80+
*/
81+
public function events(int|string $group_id, int $hook_id, array $parameters = []): mixed
82+
{
83+
$resolver = $this->createOptionsResolver();
84+
$resolver->setDefined('status')
85+
->setAllowedTypes('status', ['int', 'string'])
86+
;
87+
88+
return $this->get('groups/'.self::encodePath($group_id).'/hooks/'.self::encodePath($hook_id).'/events', $resolver->resolve($parameters));
89+
}
90+
91+
public function resendEvent(int|string $group_id, int $hook_id, int $hook_event_id): mixed
92+
{
93+
return $this->post('groups/'.self::encodePath($group_id).'/hooks/'.self::encodePath($hook_id).'/events/'.self::encodePath($hook_event_id).'/resend');
94+
}
95+
96+
public function test(int|string $group_id, int $hook_id, string $trigger): mixed
97+
{
98+
return $this->post('groups/'.self::encodePath($group_id).'/hooks/'.self::encodePath($hook_id).'/test/'.self::encodePath($trigger));
99+
}
100+
101+
public function setCustomHeader(int|string $group_id, int $hook_id, string $key, string $value): mixed
102+
{
103+
return $this->put('groups/'.self::encodePath($group_id).'/hooks/'.self::encodePath($hook_id).'/custom_headers/'.self::encodePath($key), [
104+
'value' => $value,
105+
]);
106+
}
107+
108+
public function deleteCustomHeader(int|string $group_id, int $hook_id, string $key): mixed
109+
{
110+
return $this->delete('groups/'.self::encodePath($group_id).'/hooks/'.self::encodePath($hook_id).'/custom_headers/'.self::encodePath($key));
111+
}
112+
113+
public function setUrlVariable(int|string $group_id, int $hook_id, string $key, string $value): mixed
114+
{
115+
return $this->put('groups/'.self::encodePath($group_id).'/hooks/'.self::encodePath($hook_id).'/url_variables/'.self::encodePath($key), [
116+
'value' => $value,
117+
]);
118+
}
119+
120+
public function deleteUrlVariable(int|string $group_id, int $hook_id, string $key): mixed
121+
{
122+
return $this->delete('groups/'.self::encodePath($group_id).'/hooks/'.self::encodePath($hook_id).'/url_variables/'.self::encodePath($key));
123+
}
124+
}

‎src/Client.php‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
use Gitlab\Api\Groups;
2222
use Gitlab\Api\GroupsBoards;
2323
use Gitlab\Api\GroupsEpics;
24+
use Gitlab\Api\GroupsHooks;
2425
use Gitlab\Api\GroupsMilestones;
2526
use Gitlab\Api\Integrations;
2627
use Gitlab\Api\IssueBoards;
@@ -168,6 +169,11 @@ public function groupsEpics(): GroupsEpics
168169
return new GroupsEpics($this);
169170
}
170171

172+
public function groupsHooks(): GroupsHooks
173+
{
174+
return new GroupsHooks($this);
175+
}
176+
171177
public function groupsMilestones(): GroupsMilestones
172178
{
173179
return new GroupsMilestones($this);

0 commit comments

Comments
 (0)