From 6557c72e57ed6525ca92391df75bfae07a18a1f0 Mon Sep 17 00:00:00 2001 From: Nyholm Date: Sun, 8 Nov 2020 08:36:44 +0100 Subject: [PATCH 1/4] Add support for creating a repo dispatch evnet --- doc/repos.md | 8 ++++++++ lib/Github/Api/Repo.php | 20 ++++++++++++++++++++ 2 files changed, 28 insertions(+) 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..fefa6d7bcb7 100644 --- a/lib/Github/Api/Repo.php +++ b/lib/Github/Api/Repo.php @@ -276,6 +276,26 @@ 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('/repos/'.rawurlencode($username).'/'.rawurlencode($repository), [ + 'event_type' => $eventType, + 'client_payload' => $clientPayload, + ]); + } + + /** * Manage the collaborators of a repository. * From a068d5cb51f6533dc5d6b92f8ed7aeda26699da1 Mon Sep 17 00:00:00 2001 From: Nyholm Date: Sun, 8 Nov 2020 08:38:24 +0100 Subject: [PATCH 2/4] cs --- lib/Github/Api/Repo.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/lib/Github/Api/Repo.php b/lib/Github/Api/Repo.php index fefa6d7bcb7..18c2a50a283 100644 --- a/lib/Github/Api/Repo.php +++ b/lib/Github/Api/Repo.php @@ -277,7 +277,7 @@ public function readme($username, $repository, $format = 'raw') } /** - * Create a repository dispatch event + * Create a repository dispatch event. * * @link https://developer.github.com/v3/repos/#create-a-repository-dispatch-event * @@ -295,7 +295,6 @@ public function dispatch($username, $repository, $eventType, array $clientPayloa ]); } - /** * Manage the collaborators of a repository. * From a1527d58fe3416aafbd313b302a4bcc8121eb79a Mon Sep 17 00:00:00 2001 From: Nyholm Date: Sun, 8 Nov 2020 11:07:38 +0100 Subject: [PATCH 3/4] Update URL --- lib/Github/Api/Repo.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Github/Api/Repo.php b/lib/Github/Api/Repo.php index 18c2a50a283..d0e7f02113e 100644 --- a/lib/Github/Api/Repo.php +++ b/lib/Github/Api/Repo.php @@ -289,7 +289,7 @@ public function readme($username, $repository, $format = 'raw') */ public function dispatch($username, $repository, $eventType, array $clientPayload) { - return $this->post('/repos/'.rawurlencode($username).'/'.rawurlencode($repository), [ + return $this->post('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/dispatches', [ 'event_type' => $eventType, 'client_payload' => $clientPayload, ]); From 8a6a553d44867c4fd52bd148f0c9b805931c17df Mon Sep 17 00:00:00 2001 From: Nyholm Date: Sun, 8 Nov 2020 11:22:31 +0100 Subject: [PATCH 4/4] Style fix --- lib/Github/Api/Repo.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Github/Api/Repo.php b/lib/Github/Api/Repo.php index d0e7f02113e..45c36099d53 100644 --- a/lib/Github/Api/Repo.php +++ b/lib/Github/Api/Repo.php @@ -289,7 +289,7 @@ public function readme($username, $repository, $format = 'raw') */ public function dispatch($username, $repository, $eventType, array $clientPayload) { - return $this->post('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/dispatches', [ + return $this->post(\sprintf('/repos/%s/%s/dispatches', rawurlencode($username), rawurlencode($repository)), [ 'event_type' => $eventType, 'client_payload' => $clientPayload, ]);