forked from phacility/phabricator
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathReleephRequestDifferentialCreateController.php
106 lines (88 loc) · 3.17 KB
/
ReleephRequestDifferentialCreateController.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
104
105
106
<?php
// TODO: After T2222, this is likely unreachable?
final class ReleephRequestDifferentialCreateController
extends ReleephController {
private $revisionID;
private $revision;
public function willProcessRequest(array $data) {
$this->revisionID = $data['diffRevID'];
}
public function processRequest() {
$request = $this->getRequest();
$user = $request->getUser();
$diff_rev = id(new DifferentialRevisionQuery())
->setViewer($user)
->withIDs(array($this->revisionID))
->executeOne();
if (!$diff_rev) {
return new Aphront404Response();
}
$this->revision = $diff_rev;
$arc_project = id(new PhabricatorRepositoryArcanistProject())
->loadOneWhere('phid = %s', $this->revision->getArcanistProjectPHID());
$projects = id(new ReleephProject())->loadAllWhere(
'arcanistProjectID = %d AND isActive = 1',
$arc_project->getID());
if (!$projects) {
throw new Exception(sprintf(
"D%d belongs to the '%s' Arcanist project, ".
"which is not part of any Releeph project!",
$this->revision->getID(),
$arc_project->getName()));
}
$branches = id(new ReleephBranch())->loadAllWhere(
'releephProjectID IN (%Ld) AND isActive = 1',
mpull($projects, 'getID'));
if (!$branches) {
throw new Exception(sprintf(
'D%d could be in the Releeph project(s) %s, '.
'but this project / none of these projects have open branches.',
$this->revision->getID(),
implode(', ', mpull($projects, 'getName'))));
}
if (count($branches) === 1) {
return id(new AphrontRedirectResponse())
->setURI($this->buildReleephRequestURI(head($branches)));
}
$projects = msort(
mpull($projects, null, 'getID'),
'getName');
$branch_groups = mgroup($branches, 'getReleephProjectID');
require_celerity_resource('releeph-request-differential-create-dialog');
$dialog = id(new AphrontDialogView())
->setUser($user)
->setTitle(pht('Choose Releeph Branch'))
->setClass('releeph-request-differential-create-dialog')
->addCancelButton('/D'.$request->getStr('D'));
$dialog->appendChild(
pht('This differential revision changes code that is associated '.
'with multiple Releeph branches. '.
'Please select the branch where you would like this code to be picked.'));
foreach ($branch_groups as $project_id => $branches) {
$project = idx($projects, $project_id);
$dialog->appendChild(
phutil_tag(
'h1',
array(),
$project->getName()));
$branches = msort($branches, 'getBasename');
foreach ($branches as $branch) {
$uri = $this->buildReleephRequestURI($branch);
$dialog->appendChild(
phutil_tag(
'a',
array(
'href' => $uri,
),
$branch->getDisplayNameWithDetail()));
}
}
return id(new AphrontDialogResponse)
->setDialog($dialog);
}
private function buildReleephRequestURI(ReleephBranch $branch) {
$uri = $branch->getURI('request/');
return id(new PhutilURI($uri))
->setQueryParam('D', $this->revision->getID());
}
}