-
Notifications
You must be signed in to change notification settings - Fork 38
/
ticket.php
61 lines (51 loc) · 1.69 KB
/
ticket.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
<?php
require("git_users.php");
require("milestones.php");
class Ticket {
public static $github;
private $id;
private $attr;
public static function loadFromTrac($id) {
$q_select = "SELECT * FROM `ticket` WHERE `id` = $id";
$result = Trac::queryRow($q_select);
return $result ? new self($result) : null;
}
public function __construct($dbAttributes) {
$this->attr = $dbAttributes;
$this->id = $this->attr['id'];
}
public function toIssueJson() {
$json = array(
'title' => $this->attr['summary'],
'body' => $this->translateDescription(),
'assignee' => GitUsers::fromTrac($this->attr['owner']) ?: $this->attr['owner'],
'milestone' => Milestones::gitId($this->attr['milestone']),
'labels' => $this->getLabels()
);
return $json;
}
public function saveToGithub() {
self::$github->add_issue($this->toIssueJson());
if ($this->attr['status'] == 'closed') {
self::$github->update_issue($this->id, array('state' => 'closed'));
}
}
private function translateDescription() {
// more on this later
$desc = $this->attr['description'];
$desc = str_replace("\r\n", "\n", $desc);
return $dec;
}
private function getLabels() {
$labels = array();
if ($comp = $this->attr['component'])
$labels[] = "C-{$comp}";
if ($resolution = $this->attr['resolution'])
$labels[] = "R-{$resolution}";
if (($status = $this->attr['status']) && $status != 'closed' && $status != 'assigned')
$labels[] = $status;
if ($priority = $this->attr['priority'])
$labels[] = "P-{$priority}";
return $labels;
}
}