Skip to content

Commit f82214a

Browse files
authored
feature #931 Add support for creating a repo dispatch event (Nyholm)
This PR was squashed before being merged into the 2.x branch. Discussion ---------- If you want to trigger a custom action, you need this API call. Commits ------- 6557c72 Add support for creating a repo dispatch evnet a068d5c cs a1527d5 Update URL 8a6a553 Style fix
1 parent b79d090 commit f82214a

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
@@ -276,6 +276,25 @@ public function readme($username, $repository, $format = 'raw')
276276
]);
277277
}
278278

279+
/**
280+
* Create a repository dispatch event.
281+
*
282+
* @link https://developer.github.com/v3/repos/#create-a-repository-dispatch-event
283+
*
284+
* @param string $username the user who owns the repository
285+
* @param string $repository the name of the repository
286+
* @param string $eventType A custom webhook event name
287+
*
288+
* @return mixed null on success, array on error with 'message'
289+
*/
290+
public function dispatch($username, $repository, $eventType, array $clientPayload)
291+
{
292+
return $this->post(\sprintf('/repos/%s/%s/dispatches', rawurlencode($username), rawurlencode($repository)), [
293+
'event_type' => $eventType,
294+
'client_payload' => $clientPayload,
295+
]);
296+
}
297+
279298
/**
280299
* Manage the collaborators of a repository.
281300
*

0 commit comments

Comments
 (0)