|
| 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 | +} |
0 commit comments