Skip to content
This repository was archived by the owner on Aug 9, 2019. It is now read-only.

Commit 037a2d5

Browse files
committed
Option prev_status
1 parent 1ce0279 commit 037a2d5

File tree

2 files changed

+31
-1
lines changed

2 files changed

+31
-1
lines changed

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ This PHPCI plugin allows to update the Redmine issues with build results.
66

77
* **enabled** - Required - The plugin is enabled or disabled (example, `enabled: true`).
88
* **status** - Redmine issue will change status to this status (example, `status: 4`).
9+
* **prev_status** - Current redmine issue's status (example, `prev_status: 2`).
910
* **percent** - Redmine issue will change `done_ratio` to *percent* value (example, `percent: 80`).
1011
* **lang** - Redmine issue's notes language. Can be `en` or `ru` (example, `lang: en`).
1112
* **issue_regexp** - Mask for issue id searching in branch string (example, `issue_regexp: "/task-(\d+)/"`).

Redmine.php

+30-1
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ class Redmine implements \PHPCI\Plugin
2424
protected $enabled = true;
2525

2626
protected $status;
27+
protected $prevStatus;
2728
protected $percent;
2829

2930
protected $lang = 'en';
@@ -50,6 +51,9 @@ public function __construct(Builder $phpci, Build $build, array $options = array
5051
if (isset($options['status'])) {
5152
$this->status = $options['status'];
5253
}
54+
if (isset($options['prev_status'])) {
55+
$this->prevStatus = $options['prev_status'];
56+
}
5357
if (isset($options['percent'])) {
5458
$this->percent = $options['percent'];
5559
}
@@ -91,7 +95,32 @@ public function execute()
9195
$issue['notes'] .= sprintf($this->messages['passed'], $buildLink) . "\n";
9296

9397
if ($this->status) {
94-
$issue['status_id'] = $this->status;
98+
if ($this->prevStatus) {
99+
$headers = array(
100+
'Content-Type: application/json',
101+
'X-Redmine-API-Key: ' . $this->apiKey,
102+
);
103+
104+
$ch = curl_init();
105+
curl_setopt($ch, CURLOPT_URL, $url);
106+
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
107+
curl_setopt($ch, CURLOPT_FAILONERROR, false);
108+
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); // return into a variable
109+
curl_setopt($ch, CURLOPT_TIMEOUT, 30); // times out after 30s
110+
111+
$response = curl_exec($ch);
112+
$response = json_decode($response);
113+
114+
if ($response) {
115+
if (isset($response['issue']['status']['id'])) {
116+
if ($this->prevStatus == $response['issue']['status']['id']) {
117+
$issue['status_id'] = $this->status;
118+
}
119+
}
120+
}
121+
} else {
122+
$issue['status_id'] = $this->status;
123+
}
95124
}
96125
if ($this->percent) {
97126
$issue['done_ratio'] = $this->percent;

0 commit comments

Comments
 (0)