|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace ParityBit\DeploymentNotifier\Clients; |
|
4
|
|
|
|
|
5
|
|
|
use Curl\Curl; |
|
6
|
|
|
use ParityBit\DeploymentNotifier\Deployment; |
|
7
|
|
|
|
|
8
|
|
|
class CodebaseClient |
|
9
|
|
|
{ |
|
10
|
|
|
protected $curl; |
|
11
|
|
|
protected $codebaseProjectName; |
|
12
|
|
|
protected $repositoryName; |
|
13
|
|
|
protected $headers = [ |
|
14
|
|
|
'Accept' => 'application/xml', |
|
15
|
|
|
'Content-type' => 'application/xml', |
|
16
|
|
|
]; |
|
17
|
|
|
|
|
18
|
|
|
const WEBSERVICE_URL = 'http://api3.codebasehq.com/'; |
|
19
|
|
|
|
|
20
|
|
|
public function __construct(Curl $curl, $username, $password, $codebaseProjectName, $repositoryName = null) |
|
21
|
|
|
{ |
|
22
|
|
|
$this->curl = $curl; |
|
23
|
|
|
$this->codebaseProjectName = $codebaseProjectName; |
|
24
|
|
|
$this->repositoryName = $repositoryName; |
|
25
|
|
|
foreach ($this->headers as $header => $value) { |
|
26
|
|
|
$this->curl->setHeader($header, $value); |
|
27
|
|
|
} |
|
28
|
|
|
|
|
29
|
|
|
$this->curl->setBasicAuthentication($username, $password); |
|
30
|
|
|
} |
|
31
|
|
|
|
|
32
|
|
|
public function getTicketsFromIds($ticketIds = []) |
|
33
|
|
|
{ |
|
34
|
|
|
$this->curl->get( |
|
35
|
|
|
self::WEBSERVICE_URL . $this->codebaseProjectName . '/tickets', |
|
36
|
|
|
[ |
|
37
|
|
|
'query' => 'id' . implode(',', $ticketIds) |
|
38
|
|
|
] |
|
39
|
|
|
); |
|
40
|
|
|
|
|
41
|
|
|
if ($this->curl->error) { |
|
42
|
|
|
return []; |
|
43
|
|
|
} |
|
44
|
|
|
else { |
|
45
|
|
|
$tickets = simplexml_load_string($this->curl->response); |
|
46
|
|
|
$completed_ticket_names = []; |
|
47
|
|
|
foreach($tickets as $ticket) { |
|
48
|
|
|
$completed_ticket_names[] = (string) $ticket->summary; |
|
49
|
|
|
} |
|
50
|
|
|
|
|
51
|
|
|
return $completed_ticket_names; |
|
52
|
|
|
} |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
|
|
public function updateTicketStatus($ticketId, $newStatus) |
|
56
|
|
|
{ |
|
57
|
|
|
$payload = "<ticket-note> |
|
58
|
|
|
<changes> |
|
59
|
|
|
<status-id>" . $newStatus . "</status-id> |
|
60
|
|
|
</changes> |
|
61
|
|
|
</ticket-note>"; |
|
62
|
|
|
|
|
63
|
|
|
$this->curl->post( |
|
64
|
|
|
self::WEBSERVICE_URL . $this->codebaseProjectName . '/tickets/' . $ticketId . '/notes', |
|
65
|
|
|
$payload |
|
|
|
|
|
|
66
|
|
|
); |
|
67
|
|
|
} |
|
68
|
|
|
|
|
69
|
|
|
public function registerDeployment(Deployment $deployment) |
|
70
|
|
|
{ |
|
71
|
|
|
$payload = "<deployment> |
|
72
|
|
|
<revision>" . (string) $deployment->getCurrentVersion() . "</revision> |
|
73
|
|
|
<environment>" . (string) $deployment->getEnvironment() . "</environment> |
|
74
|
|
|
<servers>" . (string) $deployment->getServer() . "</servers> |
|
75
|
|
|
</deployment>"; |
|
76
|
|
|
|
|
77
|
|
|
$this->curl->post( |
|
78
|
|
|
self::WEBSERVICE_URL . $this->codebaseProjectName . '/' . $this->repositoryName . '/deployments', |
|
79
|
|
|
$payload |
|
|
|
|
|
|
80
|
|
|
); |
|
81
|
|
|
} |
|
82
|
|
|
} |
|
83
|
|
|
|
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: