This repository was archived by the owner on Nov 24, 2017. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathJira.php
104 lines (96 loc) · 3.88 KB
/
Jira.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
<?php
/**
* TicketListener which will resolve and reopen issues in Jira based on PHPUnit
* test results.<p>
*
* phpunit.xml
* <code>
* <listeners>
* <listener class="PHPUnit_Extensions_TicketListener_Jira">
* <arguments>
* <string>$wsdl</string>
* <string>$username</string>
* <string>$password</string>
* <array>
* <element key="0">
* <string>New</string>
* </element>
* <element key="1">
* <string>In Progress</string>
* </element>
* <element key="2">
* <string>Reopened</string>
* </element>
* </array>
* <array>
* <element key="0">
* <string>Completed</string>
* </element>
* <element key="1">
* <string>Closed</string>
* </element>
* </array>
* <string>Resolve Issue</string>
* <string>Reopen Issue</string>
* </arguments>
* </listener>
* </listeners>
* </code><p>
*
* The above example lists 'New', 'In Progress', and 'Reopened' as 'Open'
* issue statuses, and 'Completed' and 'Closed' as 'Closed' issue statuses.
* The workflow action button to resolve an open issue is 'Resolve Issue',
* and the workflow action button to reopen a closed issue is 'Reopen Issue'.
*/
class PHPUnit_Extesions_TicketListener_Jira
extends PHPUnit_Extensions_TicketListener {
private $client;
private $jiraToTicketStatusMap;
private $ticketToJiraActionMap;
/**
* @param string $wsdl https://jira.mycompany.com/rpc/soap/jirasoapservice-v2?wsdl
* @param string $username Valid Jira username
* @param string password Password for Jira username
* @param array $openStatuses List of statuses mapping to an open issue.
* @param array $closedStatuses List of statuses mapping to a closed issue.
* @param string $resolveAction Workflow action for resolving an open issue.
* @param string $reopenAction Workflow action for reopening a closed issue.
*/
public function __construct(
$wsdl, $username, $password,
$openStatuses, $closedStatuses, $resolveAction, $reopenAction,
$soapClient = NULL, $auth = NULL) {
$this->client = new PHPUnit_Extensions_TicketListener_Jira_Client(
$wsdl, $username, $password);
$this->client->connect($soapClient, $auth);
$statusConverter =
new PHPUnit_Extensions_TicketListener_Jira_StatusConverter();
$this->jiraToTicketStatusMap = $statusConverter->getJiraToTicketStatusMap(
$openStatuses, $closedStatuses, $this->client->getStatuses());
$this->ticketToJiraActionMap = $statusConverter->getTicketToJiraActionMap(
$resolveAction, $reopenAction);
}
/**
* @param string $ticketId Jira issue id string (not numeric id).
* @return array Ticket property maps. 'status' is the only supported key.
*/
protected function getTicketInfo($ticketId = NULL) {
if ($ticketId === NULL) {
return;
}
$jiraTicket = $this->client->getTicket($ticketId);
return array('status' => $this->jiraToTicketStatusMap[$jiraTicket->status]);
}
/**
* @param string $ticketId Jira issue id string (not numeric id).
* @param string $newStatus 'reopen' or 'close'
* @param string $message Comment on status change.
* @param string $resolution Ignored.
*/
protected function updateTicket($ticketId, $newStatus, $message, $resolution) {
$this->client->progressWorkflowAction(
$ticketId,
$this->ticketToJiraActionMap[$newStatus],
$message);
}
}