Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
* Add support for `visibility` in `Groups::all`
* Add support for personal access tokens
* Add support for project integrations endpoints
* Add support for group hook endpoints
* Add support for `job_inputs` and `job_variables_attributes` in `Jobs::play`
* Add support for filters in `Projects::projectAccessTokens`
* Add support for `Projects::rotateProjectAccessToken`
Expand Down
115 changes: 115 additions & 0 deletions src/Api/GroupsHooks.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
<?php

declare(strict_types=1);

/*
* This file is part of the Gitlab API library.
*
* (c) Matt Humphrey <matth@windsor-telecom.co.uk>
* (c) Graham Campbell <hello@gjcampbell.co.uk>
*
* 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\OptionsResolver;

class GroupsHooks extends AbstractApi
{
public function all(int|string $group_id): mixed
{
return $this->get('groups/'.self::encodePath($group_id).'/hooks');
}

public function show(int|string $group_id, int $hook_id): mixed
{
return $this->get('groups/'.self::encodePath($group_id).'/hooks/'.self::encodePath($hook_id));
}

/**
* Create a group hook.
*
* Hook parameters vary across GitLab versions and are passed through.
*
* @see https://docs.gitlab.com/api/group_webhooks/#create-a-group-hook
*
* @param array<string,mixed> $parameters
*/
public function create(int|string $group_id, string $url, array $parameters = []): mixed
{
$parameters['url'] = $url;

return $this->post('groups/'.self::encodePath($group_id).'/hooks', $parameters);
}

/**
* Update a group hook.
*
* Hook parameters vary across GitLab versions and are passed through.
*
* @see https://docs.gitlab.com/api/group_webhooks/#update-a-group-hook
*
* @param array<string,mixed> $parameters
*/
public function update(int|string $group_id, int $hook_id, array $parameters): mixed
{
return $this->put('groups/'.self::encodePath($group_id).'/hooks/'.self::encodePath($hook_id), $parameters);
}

public function remove(int|string $group_id, int $hook_id): mixed
{
return $this->delete('groups/'.self::encodePath($group_id).'/hooks/'.self::encodePath($hook_id));
}

/**
* @param array $parameters {
*
* @var int|string $status response status code or status category
* }
*/
public function events(int|string $group_id, int $hook_id, array $parameters = []): mixed
{
$resolver = new OptionsResolver();
$resolver->setDefined('status')
->setAllowedTypes('status', ['int', 'string'])
;

return $this->get('groups/'.self::encodePath($group_id).'/hooks/'.self::encodePath($hook_id).'/events', $resolver->resolve($parameters));
}

public function resendEvent(int|string $group_id, int $hook_id, int $hook_event_id): mixed
{
return $this->post('groups/'.self::encodePath($group_id).'/hooks/'.self::encodePath($hook_id).'/events/'.self::encodePath($hook_event_id).'/resend');
}

public function test(int|string $group_id, int $hook_id, string $trigger): mixed
{
return $this->post('groups/'.self::encodePath($group_id).'/hooks/'.self::encodePath($hook_id).'/test/'.self::encodePath($trigger));
}

public function setCustomHeader(int|string $group_id, int $hook_id, string $key, string $value): mixed
{
return $this->put('groups/'.self::encodePath($group_id).'/hooks/'.self::encodePath($hook_id).'/custom_headers/'.self::encodePath($key), [
'value' => $value,
]);
}

public function deleteCustomHeader(int|string $group_id, int $hook_id, string $key): mixed
{
return $this->delete('groups/'.self::encodePath($group_id).'/hooks/'.self::encodePath($hook_id).'/custom_headers/'.self::encodePath($key));
}

public function setUrlVariable(int|string $group_id, int $hook_id, string $key, string $value): mixed
{
return $this->put('groups/'.self::encodePath($group_id).'/hooks/'.self::encodePath($hook_id).'/url_variables/'.self::encodePath($key), [
'value' => $value,
]);
}

public function deleteUrlVariable(int|string $group_id, int $hook_id, string $key): mixed
{
return $this->delete('groups/'.self::encodePath($group_id).'/hooks/'.self::encodePath($hook_id).'/url_variables/'.self::encodePath($key));
}
}
6 changes: 6 additions & 0 deletions src/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
use Gitlab\Api\Groups;
use Gitlab\Api\GroupsBoards;
use Gitlab\Api\GroupsEpics;
use Gitlab\Api\GroupsHooks;
use Gitlab\Api\GroupsMilestones;
use Gitlab\Api\Integrations;
use Gitlab\Api\IssueBoards;
Expand Down Expand Up @@ -168,6 +169,11 @@ public function groupsEpics(): GroupsEpics
return new GroupsEpics($this);
}

public function groupsHooks(): GroupsHooks
{
return new GroupsHooks($this);
}

public function groupsMilestones(): GroupsMilestones
{
return new GroupsMilestones($this);
Expand Down
Loading