mirror of
https://we.phorge.it/source/phorge.git
synced 2024-11-26 00:32:42 +01:00
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:
parent
f9110b87ab
commit
89fe84f978
2 changed files with 18 additions and 7 deletions
|
@ -69,10 +69,11 @@ final class PhabricatorDiffusionApplication extends PhabricatorApplication {
|
||||||
'branches/(?P<dblob>.*)' => 'DiffusionBranchTableController',
|
'branches/(?P<dblob>.*)' => 'DiffusionBranchTableController',
|
||||||
'refs/(?P<dblob>.*)' => 'DiffusionRefTableController',
|
'refs/(?P<dblob>.*)' => 'DiffusionRefTableController',
|
||||||
'lint/(?P<dblob>.*)' => 'DiffusionLintController',
|
'lint/(?P<dblob>.*)' => 'DiffusionLintController',
|
||||||
'commit/(?P<commit>[a-z0-9]+)/branches/'
|
'commit/(?P<commit>[a-z0-9]+)' => array(
|
||||||
=> 'DiffusionCommitBranchesController',
|
'/?' => 'DiffusionCommitController',
|
||||||
'commit/(?P<commit>[a-z0-9]+)/tags/'
|
'/branches/' => 'DiffusionCommitBranchesController',
|
||||||
=> 'DiffusionCommitTagsController',
|
'/tags/' => 'DiffusionCommitTagsController',
|
||||||
|
),
|
||||||
'compare/' => 'DiffusionCompareController',
|
'compare/' => 'DiffusionCompareController',
|
||||||
'manage/(?:(?P<panel>[^/]+)/)?'
|
'manage/(?:(?P<panel>[^/]+)/)?'
|
||||||
=> 'DiffusionRepositoryManagePanelsController',
|
=> 'DiffusionRepositoryManagePanelsController',
|
||||||
|
|
|
@ -22,17 +22,27 @@ final class DiffusionCommitController extends DiffusionController {
|
||||||
|
|
||||||
$drequest = $this->getDiffusionRequest();
|
$drequest = $this->getDiffusionRequest();
|
||||||
$viewer = $request->getUser();
|
$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')) {
|
if ($request->getStr('diff')) {
|
||||||
return $this->buildRawDiffResponse($drequest);
|
return $this->buildRawDiffResponse($drequest);
|
||||||
}
|
}
|
||||||
|
|
||||||
$repository = $drequest->getRepository();
|
|
||||||
|
|
||||||
$commit = id(new DiffusionCommitQuery())
|
$commit = id(new DiffusionCommitQuery())
|
||||||
->setViewer($viewer)
|
->setViewer($viewer)
|
||||||
->withRepository($repository)
|
->withRepository($repository)
|
||||||
->withIdentifiers(array($drequest->getCommit()))
|
->withIdentifiers(array($commit_identifier))
|
||||||
->needCommitData(true)
|
->needCommitData(true)
|
||||||
->needAuditRequests(true)
|
->needAuditRequests(true)
|
||||||
->executeOne();
|
->executeOne();
|
||||||
|
|
Loading…
Reference in a new issue