-
-
Notifications
You must be signed in to change notification settings - Fork 592
Expand file tree
/
Copy pathDeployment.php
More file actions
140 lines (128 loc) · 4.56 KB
/
Deployment.php
File metadata and controls
140 lines (128 loc) · 4.56 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
<?php
namespace Github\Api;
use Github\Api\Deployment\Environments;
use Github\Api\Deployment\Policies;
use Github\Exception\MissingArgumentException;
/**
* Listing, creating and updating deployments.
*
* @link https://developer.github.com/v3/repos/deployments/
*/
class Deployment extends AbstractApi
{
/**
* List deployments for a particular repository.
*
* @link https://developer.github.com/v3/repos/deployments/#list-deployments
*
* @param string $username the username of the user who owns the repository
* @param string $repository the name of the repository
* @param array $params query parameters to filter deployments by (see link)
*
* @return array the deployments requested
*/
public function all($username, $repository, array $params = [])
{
return $this->get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/deployments', $params);
}
/**
* Get a deployment in selected repository.
*
* @param string $username the user who owns the repo
* @param string $repository the name of the repo
* @param int $id the id of the deployment
*
* @return array
*/
public function show($username, $repository, $id)
{
return $this->get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/deployments/'.$id);
}
/**
* Create a new deployment for the given username and repo.
*
* @link https://developer.github.com/v3/repos/deployments/#create-a-deployment
*
* Important: Once a deployment is created, it cannot be updated. Changes are indicated by creating new statuses.
* @see updateStatus
*
* @param string $username the username
* @param string $repository the repository
* @param array $params the new deployment data
*
* @throws MissingArgumentException
*
* @return array information about the deployment
*/
public function create($username, $repository, array $params)
{
if (!isset($params['ref'])) {
throw new MissingArgumentException(['ref']);
}
return $this->post('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/deployments', $params);
}
/**
* Delete a deployment for the given username and repo.
*
* @link https://docs.github.com/en/rest/reference/repos#delete-a-deployment
*
* Important: Deployments can only be deleted when in inactive state
* @see updateStatus
*
* @return mixed null on success, array on error with 'message'
*/
public function remove(string $username, string $repository, int $id)
{
return $this->delete('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/deployments/'.$id);
}
/**
* Updates a deployment by creating a new status update.
*
* @link https://developer.github.com/v3/repos/deployments/#create-a-deployment-status
*
* @param string $username the username
* @param string $repository the repository
* @param int $id the deployment number
* @param array $params The information about the deployment update.
* Must include a "state" field of pending, success, error, or failure.
* May also be given a target_url and description, see link for more details.
*
* @throws MissingArgumentException
*
* @return array information about the deployment
*/
public function updateStatus($username, $repository, $id, array $params)
{
if (!isset($params['state'])) {
throw new MissingArgumentException(['state']);
}
return $this->post('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/deployments/'.$id.'/statuses', $params);
}
/**
* Gets all of the status updates tied to a given deployment.
*
* @param string $username the username
* @param string $repository the repository
* @param int $id the deployment identifier
*
* @return array the deployment statuses
*/
public function getStatuses($username, $repository, $id)
{
return $this->get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/deployments/'.$id.'/statuses');
}
/**
* @return Environments
*/
public function environments()
{
return new Environments($this->getClient());
}
/**
* @return Policies
*/
public function policies()
{
return new Policies($this->getClient());
}
}