|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* This dispatcher takes care of updating and returning information about this |
|
5
|
|
|
* projects git repository |
|
6
|
|
|
*/ |
|
7
|
|
|
class DeployDispatcher extends Dispatcher { |
|
8
|
|
|
|
|
9
|
|
|
const ACTION_DEPLOY = 'deploy'; |
|
10
|
|
|
|
|
11
|
|
|
/** |
|
12
|
|
|
* @var array |
|
13
|
|
|
*/ |
|
14
|
|
|
private static $action_types = [ |
|
15
|
|
|
self::ACTION_DEPLOY |
|
16
|
|
|
]; |
|
17
|
|
|
|
|
18
|
|
|
/** |
|
19
|
|
|
* @var array |
|
20
|
|
|
*/ |
|
21
|
|
|
public static $allowed_actions = [ |
|
22
|
|
|
'history' |
|
23
|
|
|
]; |
|
24
|
|
|
|
|
25
|
|
|
/** |
|
26
|
|
|
* @var \DNProject |
|
27
|
|
|
*/ |
|
28
|
|
|
protected $project = null; |
|
29
|
|
|
|
|
30
|
|
|
/** |
|
31
|
|
|
* @var \DNEnvironment |
|
32
|
|
|
*/ |
|
33
|
|
|
protected $environment = null; |
|
34
|
|
|
|
|
35
|
|
|
public function init() { |
|
36
|
|
|
parent::init(); |
|
37
|
|
|
|
|
38
|
|
|
$this->project = $this->getCurrentProject(); |
|
39
|
|
|
|
|
40
|
|
|
if(!$this->project) { |
|
41
|
|
|
return $this->project404Response(); |
|
42
|
|
|
} |
|
43
|
|
|
} |
|
44
|
|
|
|
|
45
|
|
|
/** |
|
46
|
|
|
* |
|
47
|
|
|
* @param \SS_HTTPRequest $request |
|
48
|
|
|
* |
|
49
|
|
|
* @return \HTMLText|\SS_HTTPResponse |
|
50
|
|
|
*/ |
|
51
|
|
|
public function index(\SS_HTTPRequest $request) { |
|
52
|
|
|
return $this->redirect(\Controller::join_links($this->Link(), 'history'), 302); |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
|
|
/** |
|
56
|
|
|
* @return SS_HTTPResponse |
|
57
|
|
|
*/ |
|
58
|
|
|
public function history(SS_HTTPRequest $request) { |
|
59
|
|
|
$data = []; |
|
60
|
|
|
$list = $this->DeployHistory(); |
|
61
|
|
|
$page = $request->getVar('page') ?: 1; |
|
62
|
|
|
$start = ($page-1) * $list->getPageLength(); |
|
63
|
|
|
|
|
64
|
|
|
$list->setPageStart($start); |
|
65
|
|
|
if (empty($list)) { |
|
66
|
|
|
return $this->getAPIResponse(['message' => 'No deploy history'], 404); |
|
67
|
|
|
} |
|
68
|
|
|
|
|
69
|
|
|
foreach ($list as $deployment) { |
|
70
|
|
|
$data[] = [ |
|
71
|
|
|
'CreatedDate' => $deployment->Created, |
|
72
|
|
|
'Branch' => $deployment->Branch, |
|
73
|
|
|
'Tags' => $deployment->getTags()->toArray(), |
|
74
|
|
|
'Changes' => $deployment->getDeploymentStrategy()->getChanges(), |
|
75
|
|
|
'CommitMessage' => $deployment->getCommitMessage(), |
|
76
|
|
|
'Deployer' => $deployment->Deployer()->getName(), |
|
77
|
|
|
'Approver' => $deployment->Approver()->getName(), |
|
78
|
|
|
'State' => $deployment->State, |
|
79
|
|
|
]; |
|
80
|
|
|
} |
|
81
|
|
|
|
|
82
|
|
|
return $this->getAPIResponse( |
|
83
|
|
|
[ |
|
84
|
|
|
'list' => $data, |
|
85
|
|
|
'pagelength' => $list->getPageLength(), |
|
86
|
|
|
'pagestart' => $list->getPageStart(), |
|
87
|
|
|
'totalpages' => $list->TotalPages(), |
|
88
|
|
|
'currentpage' => $list->CurrentPage() |
|
89
|
|
|
], |
|
90
|
|
|
200 |
|
91
|
|
|
); |
|
92
|
|
|
} |
|
93
|
|
|
|
|
94
|
|
|
/** |
|
95
|
|
|
* @return string |
|
96
|
|
|
*/ |
|
97
|
|
|
public function Link() { |
|
98
|
|
|
return \Controller::join_links($this->project->Link(), self::ACTION_DEPLOY); |
|
99
|
|
|
} |
|
100
|
|
|
|
|
101
|
|
|
/** |
|
102
|
|
|
* @param string $name |
|
103
|
|
|
* |
|
104
|
|
|
* @return array |
|
105
|
|
|
*/ |
|
106
|
|
|
public function getModel($name = '') { |
|
107
|
|
|
return []; |
|
108
|
|
|
} |
|
109
|
|
|
|
|
110
|
|
|
} |
|
111
|
|
|
|