Skip to content

Commit 88c8337

Browse files
lol768a-lwilliams
lol768
authored andcommitted
No need for a special header on deployment API requests
1 parent 7c74ebe commit 88c8337

File tree

2 files changed

+69
-12
lines changed

2 files changed

+69
-12
lines changed

lib/Github/Api/Deployment.php

Lines changed: 43 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,33 @@
44

55
use Github\Exception\MissingArgumentException;
66

7+
/**
8+
* Listing, creating and updating deployments.
9+
*
10+
* @link https://developer.github.com/v3/repos/deployments/
11+
*/
712
class Deployment extends AbstractApi
813
{
9-
14+
/**
15+
* List deployments for a particular repository
16+
* @link https://developer.github.com/v3/repos/deployments/#list-deployments
17+
*
18+
* @param string $username the username of the user who owns the repository
19+
* @param string $repository the name of the repository
20+
* @param array $params query parameters to filter deployments by (see link)
21+
* @return array the deployments requested
22+
*/
1023
public function all($username, $repository, array $params = array())
1124
{
12-
return $this->get('repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/deployments', array(),
13-
array('Accept' => 'application/vnd.github.cannonball-preview+json')
14-
);
25+
return $this->get('repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/deployments', $params);
1526
}
1627

17-
18-
1928
/**
2029
* Create a new deployment for the given username and repo.
30+
* @link https://developer.github.com/v3/repos/deployments/#create-a-deployment
31+
*
32+
* Important: Once a deployment is created, it cannot be updated. Changes are indicated by creating new statuses.
33+
* @see updateStatus
2134
*
2235
* @param string $username the username
2336
* @param string $repository the repository
@@ -32,22 +45,40 @@ public function create($username, $repository, array $params)
3245
throw new MissingArgumentException(array('ref'));
3346
}
3447

35-
return $this->post('repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/deployments', $params, ['Accept' => 'application/vnd.github.cannonball-preview+json']);
48+
return $this->post('repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/deployments', $params);
3649
}
3750

3851
/**
39-
* Update deployment information's by username, repo and deployment number. Requires authentication.
52+
* Updates a deployment by creating a new status update.
53+
* @link https://developer.github.com/v3/repos/deployments/#create-a-deployment-status
4054
*
41-
* @param string $username the username
55+
* @param string $username the username
4256
* @param string $repository the repository
43-
* @param string $id the deployment number
57+
* @param string $id the deployment number
58+
* @param array $params The information about the deployment update.
59+
* Must include a "state" field of pending, success, error, or failure.
60+
* May also be given a target_url and description, ßee link for more details.
4461
* @return array information about the deployment
62+
*
63+
* @throws MissingArgumentException
4564
*/
46-
public function update($username, $repository, $id, array $params)
65+
public function updateStatus($username, $repository, $id, array $params)
4766
{
4867
if (!isset($params['state'])) {
4968
throw new MissingArgumentException(array('state'));
5069
}
51-
return $this->post('repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/deployments/'.rawurlencode($id).'/statuses', $params, ['Accept' => 'application/vnd.github.cannonball-preview+json']);
70+
return $this->post('repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/deployments/'.rawurlencode($id).'/statuses', $params);
71+
}
72+
73+
/**
74+
* Gets all of the status updates tied to a given deployment.
75+
*
76+
* @param string $username the username
77+
* @param string $repository the repository
78+
* @param int $id the deployment identifier
79+
* @return array the deployment statuses
80+
*/
81+
public function getStatuses($username, $repository, $id) {
82+
return $this->get('repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/deployments/'.rawurlencode($id).'/statuses');
5283
}
5384
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?php
2+
3+
namespace Github\Tests\Api;
4+
5+
class DeploymentTest extends TestCase
6+
{
7+
/**
8+
* @test
9+
*/
10+
public function shouldCreateDeployment()
11+
{
12+
/** @var \Github\Api\Deployment $api */
13+
$api = $this->getApiMock();
14+
$deploymentData = array("ref" => "fd6a5f9e5a430dddae8d6a8ea378f913d3a766f9");
15+
$api->expects($this->once())
16+
->method('post')
17+
->with('/repos/KnpLabs/php-github-api/deployments', $deploymentData);
18+
19+
$api->create("KnpLabs", "php-github-api", $deploymentData);
20+
}
21+
22+
protected function getApiClass()
23+
{
24+
return 'Github\Api\Deployment';
25+
}
26+
}

0 commit comments

Comments
 (0)