-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.php
More file actions
93 lines (76 loc) · 2.48 KB
/
index.php
File metadata and controls
93 lines (76 loc) · 2.48 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
<?php
date_default_timezone_set('Europe/Luxembourg');
require_once __DIR__.'/config.php';
try {
$issuesToClose = getResolvedIssues();
foreach ($issuesToClose as $issueToClose) {
$url = Config::REDMINE_URL.'/issues/'.$issueToClose['id'].'.json';
callApi(
$url,
'PUT',
array(
'issue' => array(
'status_id' => Config::STATUS_CLOSED,
'notes' => "Hey o/\n\nsorry to bother you, but I'm closing this issue now as it has been resolved for over ".Config::CLOSE_IF_OLDER_THEN.".\n\nRegards,\nVaiva",
),
)
);
}
} catch (Exception $e) {
echo $e->getMessage();
}
function getResolvedIssues()
{
return getAllRows(
Config::REDMINE_URL
.'/issues.json'
.'?status_id='.Config::STATUS_RESOLVED
.'&updated_on=%3C%3D'.date('Y-m-d', strtotime('-'.Config::CLOSE_IF_OLDER_THEN))
);
}
function callApi($url, $method = 'GET', $data = null)
{
$curl = curl_init();
$curlOptions = array(
CURLOPT_URL => $url,
CURLOPT_SSL_VERIFYPEER => false,
CURLOPT_SSL_VERIFYHOST => false,
CURLOPT_RETURNTRANSFER => 1,
CURLOPT_CUSTOMREQUEST => strtoupper($method),
CURLOPT_HTTPHEADER => array(
'content-type: application/json',
'x-redmine-api-key: '.Config::API_KEY,
),
);
if ($data) {
$curlOptions = $curlOptions + array(
CURLOPT_POSTFIELDS => json_encode($data),
);
}
curl_setopt_array($curl, $curlOptions);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
throw new Exception('cURL Error #:'.$err);
}
return json_decode($response, true);
}
function getAllRows($url, $offset = 0, $limit = 100)
{
$results = callApi($url.'&offset='.$offset.'&limit='.$limit);
if ($results['offset'] + $results['limit'] < $results['total_count']) {
$issues = array_merge($results['issues'], getAllRows($url, $offset + $limit, $limit));
} else {
$issues = $results['issues'];
}
return $issues;
}
function getLatestIssues($startDate = null)
{
if ($startDate === null) {
$startDate = date('Y-m-d\TH:i:s\Z', strtotime('-'.Config::TIME_WINDOW));
}
$latestIssues = getAllRows(Config::REDMINE_URL.'/issues.json?updated_on=>='.$startDate.'&sort=updated_on:desc');
return $latestIssues;
}