Skip to content

Commit 2f1502a

Browse files
committed
App: add hook endpoints
1 parent 3467a34 commit 2f1502a

File tree

3 files changed

+197
-0
lines changed

3 files changed

+197
-0
lines changed

lib/Github/Api/App/Hook.php

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

lib/Github/Api/Apps.php

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

0 commit comments

Comments
 (0)