@recaptime-dev's working patches + fork for Phorge, a community fork of Phabricator. (Upstream dev and stable branches are at upstream/main and upstream/stable respectively.)
hq.recaptime.dev/wiki/Phorge
phorge
phabricator
1<?php
2
3final class DifferentialRevisionCloseDetailsController
4 extends DifferentialController {
5
6 public function handleRequest(AphrontRequest $request) {
7 $viewer = $this->getViewer();
8
9 $xaction = id(new PhabricatorObjectQuery())
10 ->withPHIDs(array($request->getURIData('phid')))
11 ->setViewer($viewer)
12 ->executeOne();
13 if (!$xaction) {
14 return new Aphront404Response();
15 }
16
17 $obj_phid = $xaction->getObjectPHID();
18 $obj_handle = id(new PhabricatorHandleQuery())
19 ->setViewer($viewer)
20 ->withPHIDs(array($obj_phid))
21 ->executeOne();
22
23 $body = $this->getRevisionMatchExplanation(
24 $xaction->getMetadataValue('revisionMatchData'),
25 $obj_handle);
26
27 $dialog = id(new AphrontDialogView())
28 ->setUser($viewer)
29 ->setTitle(pht('Commit Close Explanation'))
30 ->appendParagraph($body)
31 ->addCancelButton($obj_handle->getURI());
32
33 return id(new AphrontDialogResponse())->setDialog($dialog);
34 }
35
36 private function getRevisionMatchExplanation(
37 $revision_match_data,
38 PhabricatorObjectHandle $obj_handle) {
39
40 if (!$revision_match_data) {
41 return pht(
42 'This commit was made before this feature was built and thus this '.
43 'information is unavailable.');
44 }
45
46 $body_why = array();
47 if ($revision_match_data['usedURI']) {
48 return pht(
49 'We found a "%s" field with value "%s" in the commit message, '.
50 'and the domain on the URI matches this install, so '.
51 'we linked this commit to %s.',
52 'Differential Revision',
53 $revision_match_data['foundURI'],
54 phutil_tag(
55 'a',
56 array(
57 'href' => $obj_handle->getURI(),
58 ),
59 $obj_handle->getName()));
60 } else if ($revision_match_data['foundURI']) {
61 $body_why[] = pht(
62 'We found a "%s" field with value "%s" in the commit message, '.
63 'but the domain on this URI did not match the configured '.
64 'domain for this install, "%s", so we ignored it under '.
65 'the assumption that it refers to some third-party revision.',
66 'Differential Revision',
67 $revision_match_data['foundURI'],
68 $revision_match_data['validDomain']);
69 } else {
70 $body_why[] = pht(
71 'We didn\'t find a "%s" field in the commit message.',
72 'Differential Revision');
73 }
74
75 switch ($revision_match_data['matchHashType']) {
76 case ArcanistDifferentialRevisionHash::HASH_GIT_TREE:
77 $hash_info = true;
78 $hash_type = 'tree';
79 break;
80 case ArcanistDifferentialRevisionHash::HASH_GIT_COMMIT:
81 case ArcanistDifferentialRevisionHash::HASH_MERCURIAL_COMMIT:
82 $hash_info = true;
83 $hash_type = 'commit';
84 break;
85 default:
86 $hash_info = false;
87 break;
88 }
89 if ($hash_info) {
90 $diff_link = phutil_tag(
91 'a',
92 array(
93 'href' => $obj_handle->getURI(),
94 ),
95 $obj_handle->getName());
96 $body_why[] = pht(
97 'This commit and the active diff of %s had the same %s hash '.
98 '(%s) so we linked this commit to %s.',
99 $diff_link,
100 $hash_type,
101 $revision_match_data['matchHashValue'],
102 $diff_link);
103 }
104
105 return phutil_implode_html("\n", $body_why);
106
107 }
108}