3 final class DiffusionExternalController
extends DiffusionController
{
5 public function shouldAllowPublic() {
9 public function handleRequest(AphrontRequest
$request) {
10 $uri = $request->getStr('uri');
11 $id = $request->getStr('id');
13 $repositories = id(new PhabricatorRepositoryQuery())
14 ->setViewer($request->getUser())
18 $uri_path = id(new PhutilURI($uri))->getPath();
21 // Try to figure out which tracked repository this external lives in by
22 // comparing repository metadata. We look for an exact match, but accept
25 foreach ($repositories as $key => $repository) {
26 $remote_uri = new PhutilURI($repository->getRemoteURI());
27 if ($remote_uri->getPath() == $uri_path) {
30 if ($repository->getPublicCloneURI() == $uri) {
33 if ($repository->getRemoteURI() == $uri) {
39 $best_match = head_key($matches);
42 $repository = $repositories[$best_match];
43 $redirect = $repository->generateURI(
46 'branch' => $repository->getDefaultBranch(),
50 return id(new AphrontRedirectResponse())->setURI($redirect);
54 // TODO: This is a rare query but does a table scan, add a key?
56 $commits = id(new PhabricatorRepositoryCommit())->loadAllWhere(
57 'commitIdentifier = %s',
60 if (empty($commits)) {
63 $desc = pht('"%s", at "%s"', $uri, $id);
65 $desc = pht('"%s"', $id);
68 $content = id(new PHUIInfoView())
69 ->setTitle(pht('Unknown External'))
70 ->setSeverity(PHUIInfoView
::SEVERITY_WARNING
)
71 ->appendChild(phutil_tag(
75 'This external (%s) does not appear in any tracked '.
76 'repository. It may exist in an untracked repository that '.
77 'Diffusion does not know about.',
79 } else if (count($commits) == 1) {
80 $commit = head($commits);
81 $repo = $repositories[$commit->getRepositoryID()];
82 $redirect = $repo->generateURI(
85 'branch' => $repo->getDefaultBranch(),
86 'commit' => $commit->getCommitIdentifier(),
88 return id(new AphrontRedirectResponse())->setURI($redirect);
92 foreach ($commits as $commit) {
93 $repo = $repositories[$commit->getRepositoryID()];
94 $href = $repo->generateURI(
97 'branch' => $repo->getDefaultBranch(),
98 'commit' => $commit->getCommitIdentifier(),
107 $commit->loadCommitData()->getSummary(),
111 $table = new AphrontTableView($rows);
117 $table->setColumnClasses(
123 $caption = id(new PHUIInfoView())
124 ->setSeverity(PHUIInfoView
::SEVERITY_NOTICE
)
126 pht('This external reference matches multiple known commits.'));
128 $content = new PHUIObjectBoxView();
129 $content->setHeaderText(pht('Multiple Matching Commits'));
130 $content->setInfoView($caption);
131 $content->setTable($table);
134 $crumbs = $this->buildApplicationCrumbs();
135 $crumbs->addTextCrumb(pht('External'));
137 return $this->newPage()
138 ->setTitle(pht('Unresolvable External'))
140 ->appendChild($content);