diff --git a/doc/repos.md b/doc/repos.md index c5dbfe89b7a..0c7068987d5 100644 --- a/doc/repos.md +++ b/doc/repos.md @@ -346,3 +346,11 @@ You can optionally assign some teams by passing an array with their ID's if you' ```php $repo = $client->api('repo')->transfer('KnpLabs', 'php-github-api', 'github', [1234]); ``` + +### Create a repository dispatch event + +Example when you want to configure custom github action workflows. + +```php +$client->api('repo')->dispatch('KnpLabs', 'php-github-api', 'acme-event', ['foo'=>'bar']); +``` diff --git a/lib/Github/Api/Repo.php b/lib/Github/Api/Repo.php index 867cb7efd08..45c36099d53 100644 --- a/lib/Github/Api/Repo.php +++ b/lib/Github/Api/Repo.php @@ -276,6 +276,25 @@ public function readme($username, $repository, $format = 'raw') ]); } + /** + * Create a repository dispatch event. + * + * @link https://developer.github.com/v3/repos/#create-a-repository-dispatch-event + * + * @param string $username the user who owns the repository + * @param string $repository the name of the repository + * @param string $eventType A custom webhook event name + * + * @return mixed null on success, array on error with 'message' + */ + public function dispatch($username, $repository, $eventType, array $clientPayload) + { + return $this->post(\sprintf('/repos/%s/%s/dispatches', rawurlencode($username), rawurlencode($repository)), [ + 'event_type' => $eventType, + 'client_payload' => $clientPayload, + ]); + } + /** * Manage the collaborators of a repository. *