Skip to content

Commit 4e2900e

Browse files
committed
App: add hook endpoints
1 parent 3467a34 commit 4e2900e

File tree

3 files changed

+199
-0
lines changed

3 files changed

+199
-0
lines changed

lib/Github/Api/App/Hook.php

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Github\Api\App;
6+
7+
use Github\Api\AbstractApi;
8+
9+
class Hook extends AbstractApi
10+
{
11+
/**
12+
* Show the app hook configuration.
13+
*
14+
* @link https://docs.github.com/en/rest/apps/webhooks#get-a-webhook-configuration-for-an-app
15+
*
16+
* @return array
17+
*/
18+
public function showConfig()
19+
{
20+
return $this->get('/app/hook/config');
21+
}
22+
23+
/**
24+
* Update the hook configuration of an app.
25+
*
26+
* @link https://docs.github.com/en/rest/apps/webhooks#update-a-webhook-configuration-for-an-app
27+
*
28+
* @param array $params
29+
*
30+
* @return array
31+
*/
32+
public function updateConfig(array $params)
33+
{
34+
return $this->patch('/app/hook/config', $params);
35+
}
36+
37+
/**
38+
* List deliveries for an app webhook.
39+
*
40+
* @link https://docs.github.com/en/rest/apps/webhooks#list-deliveries-for-an-app-webhook
41+
*
42+
* @return array
43+
*/
44+
public function deliveries()
45+
{
46+
return $this->get('/app/hook/deliveries');
47+
}
48+
49+
/**
50+
* Get a delivery for an app webhook.
51+
*
52+
* @link https://docs.github.com/en/rest/apps/webhooks#get-a-delivery-for-an-app-webhook
53+
*
54+
* @param int $delivery
55+
*
56+
* @return array
57+
*/
58+
public function delivery($delivery)
59+
{
60+
return $this->get('/app/hook/deliveries/'.$delivery);
61+
}
62+
63+
/**
64+
* Redeliver a delivery for an app webhook.
65+
*
66+
* @link https://docs.github.com/en/rest/apps/webhooks#redeliver-a-delivery-for-an-app-webhook
67+
*
68+
* @param int $delivery
69+
*
70+
* @return array
71+
*/
72+
public function redeliver($delivery)
73+
{
74+
return $this->post('/app/hook/deliveries/'.$delivery.'/attempts');
75+
}
76+
}

lib/Github/Api/Apps.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
namespace Github\Api;
44

5+
use Github\Api\App\Hook;
6+
57
/**
68
* @link https://developer.github.com/v3/apps/
79
*
@@ -198,4 +200,16 @@ public function getAuthenticatedApp()
198200
{
199201
return $this->get('/app');
200202
}
203+
204+
/**
205+
* Manage the hook of an app.
206+
*
207+
* @link https://docs.github.com/en/rest/apps/webhooks
208+
*
209+
* @return Hook
210+
*/
211+
public function hook()
212+
{
213+
return new Hook($this->getClient());
214+
}
201215
}
Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Github\Api\App;
6+
7+
use Github\Tests\Api\TestCase;
8+
9+
class HookTest extends TestCase
10+
{
11+
/**
12+
* @test
13+
*/
14+
public function shouldShowHookConfiguration()
15+
{
16+
$result = [
17+
'content_type' => 'json',
18+
'insecure_ssl' => 0,
19+
'secret' => '********',
20+
'url' => 'https://localhost/',
21+
];
22+
23+
$api = $this->getApiMock();
24+
$api->expects($this->once())
25+
->method('get')
26+
->with('/app/hook/config', [])
27+
->willReturn($result);
28+
29+
$this->assertEquals($result, $api->showConfig());
30+
}
31+
32+
/**
33+
* @test
34+
*/
35+
public function shouldUpdateHookConfiguration()
36+
{
37+
$parameters = [
38+
'content_type' => 'json',
39+
];
40+
41+
$api = $this->getApiMock();
42+
$api->expects($this->once())
43+
->method('patch')
44+
->with('/app/hook/config', $parameters)
45+
->willReturn([]);
46+
47+
$this->assertEquals([], $api->updateConfig($parameters));
48+
}
49+
50+
/**
51+
* @test
52+
*/
53+
public function shouldListHookDelivieries()
54+
{
55+
$result = [];
56+
57+
$api = $this->getApiMock();
58+
$api->expects($this->once())
59+
->method('get')
60+
->with('/app/hook/deliveries', [])
61+
->willReturn($result);
62+
63+
$this->assertEquals($result, $api->deliveries());
64+
}
65+
66+
/**
67+
* @test
68+
*/
69+
public function shouldListHookDeliviery()
70+
{
71+
$result = [];
72+
73+
$delivery = 1234567;
74+
75+
$api = $this->getApiMock();
76+
$api->expects($this->once())
77+
->method('get')
78+
->with('/app/hook/deliveries/'.$delivery, [])
79+
->willReturn($result);
80+
81+
$this->assertEquals($result, $api->delivery($delivery));
82+
}
83+
84+
/**
85+
* @test
86+
*/
87+
public function shouldRedeliveryHook()
88+
{
89+
$result = [];
90+
91+
$delivery = 1234567;
92+
93+
$api = $this->getApiMock();
94+
$api->expects($this->once())
95+
->method('post')
96+
->with('/app/hook/deliveries/'.$delivery.'/attempts', [])
97+
->willReturn($result);
98+
99+
$this->assertEquals($result, $api->redeliver($delivery));
100+
}
101+
102+
/**
103+
* @return string
104+
*/
105+
protected function getApiClass()
106+
{
107+
return \Github\Api\App\Hook::class;
108+
}
109+
}

0 commit comments

Comments
 (0)