/
JiraSoapService.php
126 lines (105 loc) · 3.8 KB
/
JiraSoapService.php
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
<?php
class JiraSoapService extends SoapClient {
private $client;
private $token;
private static $defaultOptions = array(
'soap_version' => SOAP_1_2,
'encoding' => 'UTF-8',
'exceptions' => true
);
/**
* @param $address address in JIRA Service URI
* @param $compression compression enabled to use compression of HTTP SOAP requests and responses
*/
public function __construct($address, array $options = array()){
$options = array_merge(self::$defaultOptions, $options);
$options = array_merge($options,
array(
'location' => $address . 'rpc/soap/jirasoapservice-v2?wsdl',
'uri' => $address . 'rpc/soap/jirasoapservice-v2',
)
);
$options['compression'] = SOAP_COMPRESSION_ACCEPT | SOAP_COMPRESSION_GZIP;
$this->client = new parent(null, $options);
}
public function __destruct(){
$this->logout();
}
public function login($user, $password){
try {
$this->token = $this->client->login($user, $password);
} catch(SoapFault $e){
throw $e;
}
}
public function getServerInfo(){
return $this->client->getServerInfo();
}
public function logout(){
$this->client->logout($this->token);
}
public function getComponents(JiraProject $project){
$res = array();
$components = $this->client->getComponents($this->token, $project->key);
foreach($components as $component){
$res[] = new JiraComponent($component);
}
return $res;
}
public function getVersions(JiraProject $project){
$res = array();
$versions = $this->client->getVersions($this->token, $project->key);
foreach($versions as $version){
$res[] = new JiraVersion($version);
}
return $res;
}
public function addVersion(JiraProject $project, JiraVersion $version){
$this->client->addVersion($this->token, $project->key, $version->toArray());
}
public function updateVersion(JiraVersion $version){
}
public function getIssue($key){
return new JiraIssue($this->client->getIssue($this->token, $key));
}
public function createIssue(JiraProject $project, JiraIssue $issue){
if(!($issue->type instanceof JiraIssueType)){
$issue->type = JiraIssueType::valueOf($issue->type)->value;
}
if(!($issue->status instanceof JiraStatus)){
$issue->status = JiraStatus::valueOf($issue->status)->value;
}
$query = array_merge($issue->toArray(), array('project' => $project->key));
return $this->client->createIssue($this->token, $query);
}
public function updateIssue(JiraIssue $issue){
$query = array_merge($issue->toArray(), array('project' => $issue->project));
return $this->client->updateIssue($this->token, $query);
}
public function addComment(JiraIssue $issue, $comment){
return $this->client->addComment($this->token, array($issue->key, array('body' => $comment)));
}
public function getProject($key){
return new JiraProject($this->client->getProjectByKey($key));
}
public function getProjects(){
$res = array();
$projects = $this->client->getProjects($this->token);
foreach($projects as $project){
$res[] = new JiraProject($project);
}
return $res;
}
public function findProject($name){
$projects = $this->getProjects();
foreach($projects as $project){
if(strcasecmp($project->name, $name) === 0){
return $project;
}
if(strcasecmp($project->key, $name) === 0){
return $project;
}
}
return null;
}
}