Skip to content

Commit ff95464

Browse files
committed
Merge branch '2.x'
* 2.x: feature #931 Add support for creating a repo dispatch event (Nyholm)
2 parents ea98734 + f82214a commit ff95464

File tree

2 files changed

+27
-0
lines changed

2 files changed

+27
-0
lines changed

doc/repos.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -346,3 +346,11 @@ You can optionally assign some teams by passing an array with their ID's if you'
346346
```php
347347
$repo = $client->api('repo')->transfer('KnpLabs', 'php-github-api', 'github', [1234]);
348348
```
349+
350+
### Create a repository dispatch event
351+
352+
Example when you want to configure custom github action workflows.
353+
354+
```php
355+
$client->api('repo')->dispatch('KnpLabs', 'php-github-api', 'acme-event', ['foo'=>'bar']);
356+
```

lib/Github/Api/Repo.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -260,6 +260,25 @@ public function readme($username, $repository, $format = 'raw')
260260
]);
261261
}
262262

263+
/**
264+
* Create a repository dispatch event.
265+
*
266+
* @link https://developer.github.com/v3/repos/#create-a-repository-dispatch-event
267+
*
268+
* @param string $username the user who owns the repository
269+
* @param string $repository the name of the repository
270+
* @param string $eventType A custom webhook event name
271+
*
272+
* @return mixed null on success, array on error with 'message'
273+
*/
274+
public function dispatch($username, $repository, $eventType, array $clientPayload)
275+
{
276+
return $this->post(\sprintf('/repos/%s/%s/dispatches', rawurlencode($username), rawurlencode($repository)), [
277+
'event_type' => $eventType,
278+
'client_payload' => $clientPayload,
279+
]);
280+
}
281+
263282
/**
264283
* Manage the collaborators of a repository.
265284
*

0 commit comments

Comments
 (0)