111 lines
2.5 KiB
Plaintext
111 lines
2.5 KiB
Plaintext
/**
|
|
* List the Git hooks in a repository.
|
|
*
|
|
* @param string $ownerName The owner name.
|
|
* @param string $repoName The repository name.
|
|
*
|
|
* @return array|null
|
|
* @since 3.2.0
|
|
**/
|
|
public function list(string $ownerName, string $repoName): ?array
|
|
{
|
|
// Build the request path.
|
|
$path = "/repos/{$ownerName}/{$repoName}/hooks/git";
|
|
|
|
// Get the URI object with the path.
|
|
$uri = $this->uri->get($path);
|
|
|
|
// Send the get request.
|
|
return $this->response->get(
|
|
$this->http->get($uri)
|
|
);
|
|
}
|
|
|
|
/**
|
|
* Get a Git hook.
|
|
*
|
|
* @param string $ownerName The owner name.
|
|
* @param string $repoName The repository name.
|
|
* @param int $hookId The Git hook ID.
|
|
*
|
|
* @return object|null
|
|
* @since 3.2.0
|
|
**/
|
|
public function get(
|
|
string $ownerName,
|
|
string $repoName,
|
|
int $hookId
|
|
): ?object
|
|
{
|
|
// Build the request path.
|
|
$path = "/repos/{$ownerName}/{$repoName}/hooks/git/{$hookId}";
|
|
|
|
// Get the URI object with the path.
|
|
$uri = $this->uri->get($path);
|
|
|
|
// Send the get request.
|
|
return $this->response->get(
|
|
$this->http->get($uri)
|
|
);
|
|
}
|
|
|
|
/**
|
|
* Delete a Git hook in a repository.
|
|
*
|
|
* @param string $ownerName The owner name.
|
|
* @param string $repositoryName The repository name.
|
|
* @param string $hookId The Git hook ID.
|
|
*
|
|
* @return string
|
|
* @since 3.2.0
|
|
**/
|
|
public function delete(
|
|
string $ownerName,
|
|
string $repositoryName,
|
|
string $hookId
|
|
): string
|
|
{
|
|
// Build the request path.
|
|
$path = "/repos/{$ownerName}/{$repositoryName}/hooks/git/{$hookId}";
|
|
|
|
// Send the delete request.
|
|
return $this->response->get(
|
|
$this->http->delete(
|
|
$this->uri->get($path)
|
|
), 204, 'success'
|
|
);
|
|
}
|
|
|
|
/**
|
|
* Edit a Git hook in a repository.
|
|
*
|
|
* @param string $owner The owner name.
|
|
* @param string $repo The repository name.
|
|
* @param string $hookId The Git hook ID.
|
|
* @param array $hookOptions The hook configuration.
|
|
*
|
|
* @return object|null
|
|
* @since 3.2.0
|
|
**/
|
|
public function edit(
|
|
string $owner,
|
|
string $repo,
|
|
string $hookId,
|
|
array $hookOptions
|
|
): ?object
|
|
{
|
|
// Build the request path.
|
|
$path = "/repos/{$owner}/{$repo}/hooks/git/{$hookId}";
|
|
|
|
// Set the hook data.
|
|
$data = new \stdClass();
|
|
$data->config = (object) $hookOptions;
|
|
|
|
// Send the PATCH request.
|
|
return $this->response->get(
|
|
$this->http->patch(
|
|
$this->uri->get($path), json_encode($data)
|
|
)
|
|
);
|
|
}
|