-
-
Notifications
You must be signed in to change notification settings - Fork 597
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
197 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
<?php declare(strict_types=1); | ||
|
||
namespace Github\Api\App; | ||
|
||
use Github\Api\AbstractApi; | ||
|
||
class Hook extends AbstractApi | ||
{ | ||
/** | ||
* Show the app hook configuration. | ||
* | ||
* @link https://docs.github.com/en/rest/apps/webhooks#get-a-webhook-configuration-for-an-app | ||
* | ||
* @return array | ||
*/ | ||
public function showConfig() | ||
{ | ||
return $this->get('/app/hook/config'); | ||
} | ||
|
||
/** | ||
* Update the hook configuration of an app. | ||
* | ||
* @link https://docs.github.com/en/rest/apps/webhooks#update-a-webhook-configuration-for-an-app | ||
* | ||
* @param array $params | ||
* | ||
* @return array | ||
*/ | ||
public function updateConfig(array $params) | ||
{ | ||
return $this->patch('/app/hook/config', $params); | ||
} | ||
|
||
/** | ||
* List deliveries for an app webhook. | ||
* | ||
* @link https://docs.github.com/en/rest/apps/webhooks#list-deliveries-for-an-app-webhook | ||
* | ||
* @return array | ||
*/ | ||
public function deliveries() | ||
{ | ||
return $this->get('/app/hook/deliveries'); | ||
} | ||
|
||
/** | ||
* Get a delivery for an app webhook. | ||
* | ||
* @link https://docs.github.com/en/rest/apps/webhooks#get-a-delivery-for-an-app-webhook | ||
* | ||
* @param int $delivery | ||
* | ||
* @return array | ||
*/ | ||
public function delivery($delivery) | ||
{ | ||
return $this->get('/app/hook/deliveries/' . $delivery); | ||
} | ||
|
||
/** | ||
* Redeliver a delivery for an app webhook | ||
* | ||
* @link https://docs.github.com/en/rest/apps/webhooks#redeliver-a-delivery-for-an-app-webhook | ||
* | ||
* @param int $delivery | ||
* | ||
* @return array | ||
*/ | ||
public function redeliver($delivery) | ||
{ | ||
return $this->post('/app/hook/deliveries/' . $delivery . '/attempts'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
<?php declare(strict_types=1); | ||
|
||
namespace Github\Api\App; | ||
|
||
use Github\Tests\Api\TestCase; | ||
|
||
class HookTest extends TestCase | ||
{ | ||
/** | ||
* @test | ||
*/ | ||
public function shouldShowHookConfiguration() | ||
{ | ||
$result = [ | ||
'content_type' => 'json', | ||
'insecure_ssl' => 0, | ||
'secret' => '********', | ||
'url' => 'https://localhost/', | ||
]; | ||
|
||
$api = $this->getApiMock(); | ||
$api->expects($this->once()) | ||
->method('get') | ||
->with('/app/hook/config', []) | ||
->willReturn($result); | ||
|
||
$this->assertEquals($result, $api->showConfig()); | ||
} | ||
|
||
/** | ||
* @test | ||
*/ | ||
public function shouldUpdateHookConfiguration() | ||
{ | ||
$parameters = [ | ||
'content_type' => 'json', | ||
]; | ||
|
||
$api = $this->getApiMock(); | ||
$api->expects($this->once()) | ||
->method('patch') | ||
->with('/app/hook/config', $parameters) | ||
->willReturn([]); | ||
|
||
$this->assertEquals([], $api->updateConfig($parameters)); | ||
} | ||
|
||
/** | ||
* @test | ||
*/ | ||
public function shouldListHookDelivieries() | ||
{ | ||
$result = []; | ||
|
||
$api = $this->getApiMock(); | ||
$api->expects($this->once()) | ||
->method('get') | ||
->with('/app/hook/deliveries', []) | ||
->willReturn($result); | ||
|
||
$this->assertEquals($result, $api->deliveries()); | ||
} | ||
|
||
/** | ||
* @test | ||
*/ | ||
public function shouldListHookDeliviery() | ||
{ | ||
$result = []; | ||
|
||
$delivery = 1234567; | ||
|
||
$api = $this->getApiMock(); | ||
$api->expects($this->once()) | ||
->method('get') | ||
->with('/app/hook/deliveries/' . $delivery, []) | ||
->willReturn($result); | ||
|
||
$this->assertEquals($result, $api->delivery($delivery)); | ||
} | ||
|
||
/** | ||
* @test | ||
*/ | ||
public function shouldRedeliveryHook() | ||
{ | ||
$result = []; | ||
|
||
$delivery = 1234567; | ||
|
||
$api = $this->getApiMock(); | ||
$api->expects($this->once()) | ||
->method('post') | ||
->with('/app/hook/deliveries/' . $delivery . '/attempts', []) | ||
->willReturn($result); | ||
|
||
$this->assertEquals($result, $api->redeliver($delivery)); | ||
} | ||
|
||
/** | ||
* @return string | ||
*/ | ||
protected function getApiClass() | ||
{ | ||
return \Github\Api\App\Hook::class; | ||
} | ||
} |