Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for Pages API #824

Merged
merged 4 commits into from Nov 1, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 6 additions & 0 deletions lib/Github/Api/Repo.php
Expand Up @@ -12,6 +12,7 @@
use Github\Api\Repository\Forks;
use Github\Api\Repository\Hooks;
use Github\Api\Repository\Labels;
use Github\Api\Repository\Pages;
use Github\Api\Repository\Projects;
use Github\Api\Repository\Protection;
use Github\Api\Repository\Releases;
Expand Down Expand Up @@ -595,6 +596,11 @@ public function traffic()
return new Traffic($this->client);
}

public function pages()
{
return new Pages($this->client);
}

/**
* @param string $username
* @param string $repository
Expand Down
60 changes: 60 additions & 0 deletions lib/Github/Api/Repository/Pages.php
@@ -0,0 +1,60 @@
<?php

namespace Github\Api\Repository;

use Github\Api\AbstractApi;
use Github\Api\AcceptHeaderTrait;

/**
* @link https://developer.github.com/v3/repos/pages/
*
* @author yunwuxin <tzzhangyajun@qq.com>
*/
class Pages extends AbstractApi
{
use AcceptHeaderTrait;

public function show($username, $repository)
{
return $this->get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/pages');
}

public function enable($username, $repository, array $params = [])
{
$this->acceptHeaderValue = 'application/vnd.github.switcheroo-preview+json';

return $this->post('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/pages', $params);
}

public function disable($username, $repository)
{
$this->acceptHeaderValue = 'application/vnd.github.switcheroo-preview+json';

return $this->delete('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/pages');
}

public function update($username, $repository, array $params = [])
{
return $this->put('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/pages', $params);
}

public function requestBuild($username, $repository)
{
return $this->post('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/pages/builds');
}

public function builds($username, $repository)
{
return $this->get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/pages/builds');
}

public function showLatestBuild($username, $repository)
{
return $this->get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/pages/builds/latest');
}

public function showBuild($username, $repository, $id)
{
return $this->get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/pages/builds/'.rawurlencode($id));
}
}
150 changes: 150 additions & 0 deletions test/Github/Tests/Api/Repository/PagesTest.php
@@ -0,0 +1,150 @@
<?php

namespace Github\Tests\Api\Repository;

use Github\Api\Repository\Pages;
use Github\Tests\Api\TestCase;
use PHPUnit\Framework\MockObject\MockObject;

/**
* Class PagesTest.
*
* @method Pages|MockObject getApiMock()
*/
class PagesTest extends TestCase
{
/**
* @test
*/
public function shouldGetPagesInfo()
{
$expectedValue = ['status' => 'built'];

$api = $this->getApiMock();
$api->expects($this->once())
->method('get')
->with('/repos/KnpLabs/php-github-api/pages')
->will($this->returnValue($expectedValue));

$this->assertEquals($expectedValue, $api->show('KnpLabs', 'php-github-api'));
}

/**
* @test
*/
public function shouldEnablePages()
{
$params = [
'source' => [
'branch' => 'master',
'path' => '/path',
],
];

$api = $this->getApiMock();
$api->expects($this->once())
->method('post')
->with('/repos/KnpLabs/php-github-api/pages', $params);

$api->enable('KnpLabs', 'php-github-api', $params);
}

/**
* @test
*/
public function shouldDisablePages()
{
$api = $this->getApiMock();
$api->expects($this->once())
->method('delete')
->with('/repos/KnpLabs/php-github-api/pages');

$api->disable('KnpLabs', 'php-github-api');
}

/**
* @test
*/
public function shouldUpdatePages()
{
$params = [
'source' => 'master /docs',
];

$api = $this->getApiMock();
$api->expects($this->once())
->method('put')
->with('/repos/KnpLabs/php-github-api/pages', $params);

$api->update('KnpLabs', 'php-github-api', $params);
}

/**
* @test
*/
public function shouldRequestPagesBuild()
{
$api = $this->getApiMock();
$api->expects($this->once())
->method('post')
->with('/repos/KnpLabs/php-github-api/pages/builds');

$api->requestBuild('KnpLabs', 'php-github-api');
}

/**
* @test
*/
public function shouldGetAllPagesBuilds()
{
$expectedValue = [['status' => 'built']];

$api = $this->getApiMock();
$api->expects($this->once())
->method('get')
->with('/repos/KnpLabs/php-github-api/pages/builds')
->will($this->returnValue($expectedValue));

$this->assertEquals($expectedValue, $api->builds('KnpLabs', 'php-github-api'));
}

/**
* @test
*/
public function shouldGetLatestPagesBuild()
{
$expectedValue = ['status' => 'built'];

$api = $this->getApiMock();
$api->expects($this->once())
->method('get')
->with('/repos/KnpLabs/php-github-api/pages/builds/latest')
->will($this->returnValue($expectedValue));

$this->assertEquals($expectedValue, $api->showLatestBuild('KnpLabs', 'php-github-api'));
}

/**
* @test
*/
public function showGetOnePagesBuild()
{
$expectedValue = ['status' => 'built'];

$api = $this->getApiMock();
$api->expects($this->once())
->method('get')
->with('/repos/KnpLabs/php-github-api/pages/builds/some')
->will($this->returnValue($expectedValue));

$this->assertEquals($expectedValue, $api->showBuild('KnpLabs', 'php-github-api', 'some'));
}

/**
* @return string
*/
protected function getApiClass()
{
return \Github\Api\Repository\Pages::class;
}
}