Add a "/source/..." URI for Diffusion commits which redirects
Summary: See PHI112. The install presumably wants to generate links to Diffusion commits from an external tool, but only knows the short name of the repository. Provide a `/source/phabricator/commit/abcdef908273` URI which redirects to the canonical URI for the commit. Test Plan: - Visited `/source/` URI for a commit, got a redirect. - Visited normal URI for a commit, got a commit page. - Visited `/branches/` and `/tags/` for a `/source/` repository, got proper pages. Reviewers: amckinley Reviewed By: amckinley Differential Revision: https://secure.phabricator.com/D18676
This commit is contained in:
@@ -22,17 +22,27 @@ final class DiffusionCommitController extends DiffusionController {
|
||||
|
||||
$drequest = $this->getDiffusionRequest();
|
||||
$viewer = $request->getUser();
|
||||
$repository = $drequest->getRepository();
|
||||
$commit_identifier = $drequest->getCommit();
|
||||
|
||||
// If this page is being accessed via "/source/xyz/commit/...", redirect
|
||||
// to the canonical URI.
|
||||
$has_callsign = strlen($request->getURIData('repositoryCallsign'));
|
||||
$has_id = strlen($request->getURIData('repositoryID'));
|
||||
if (!$has_callsign && !$has_id) {
|
||||
$canonical_uri = $repository->getCommitURI($commit_identifier);
|
||||
return id(new AphrontRedirectResponse())
|
||||
->setURI($canonical_uri);
|
||||
}
|
||||
|
||||
if ($request->getStr('diff')) {
|
||||
return $this->buildRawDiffResponse($drequest);
|
||||
}
|
||||
|
||||
$repository = $drequest->getRepository();
|
||||
|
||||
$commit = id(new DiffusionCommitQuery())
|
||||
->setViewer($viewer)
|
||||
->withRepository($repository)
|
||||
->withIdentifiers(array($drequest->getCommit()))
|
||||
->withIdentifiers(array($commit_identifier))
|
||||
->needCommitData(true)
|
||||
->needAuditRequests(true)
|
||||
->executeOne();
|
||||
|
||||
Reference in New Issue
Block a user