mirror of
https://we.phorge.it/source/phorge.git
synced 2024-12-23 22:10:55 +01:00
Make CommitController more flexible about handling URIs
Summary: Ref T4245. This adds support for both ID-based and callsign-based routes, although the ID-based routes don't occur anywhere. Also moves toward simplifying the DiffusionRequest stuff. Test Plan: Visited normal callsign-based commit pages; visited new ID-based commit pages. Reviewers: chad Reviewed By: chad Maniphest Tasks: T4245 Differential Revision: https://secure.phabricator.com/D14940
This commit is contained in:
parent
07e2596aa1
commit
fb3b4ee532
6 changed files with 68 additions and 18 deletions
|
@ -47,8 +47,13 @@ final class PhabricatorDiffusionApplication extends PhabricatorApplication {
|
||||||
|
|
||||||
public function getRoutes() {
|
public function getRoutes() {
|
||||||
return array(
|
return array(
|
||||||
'/r(?P<callsign>[A-Z]+)(?P<commit>[a-z0-9]+)'
|
'/(?:'.
|
||||||
|
'r(?P<repositoryCallsign>[A-Z]+)'.
|
||||||
|
'|'.
|
||||||
|
'R(?P<repositoryID>[1-9]\d*):'.
|
||||||
|
')(?P<commit>[a-f0-9]+)'
|
||||||
=> 'DiffusionCommitController',
|
=> 'DiffusionCommitController',
|
||||||
|
|
||||||
'/diffusion/' => array(
|
'/diffusion/' => array(
|
||||||
'(?:query/(?P<queryKey>[^/]+)/)?'
|
'(?:query/(?P<queryKey>[^/]+)/)?'
|
||||||
=> 'DiffusionRepositoryListController',
|
=> 'DiffusionRepositoryListController',
|
||||||
|
|
|
@ -17,20 +17,16 @@ final class DiffusionCommitController extends DiffusionController {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function shouldLoadDiffusionRequest() {
|
public function handleRequest(AphrontRequest $request) {
|
||||||
return false;
|
$response = $this->loadDiffusionContext();
|
||||||
}
|
if ($response) {
|
||||||
|
return $response;
|
||||||
|
}
|
||||||
|
|
||||||
|
$drequest = $this->getDiffusionRequest();
|
||||||
|
|
||||||
protected function processDiffusionRequest(AphrontRequest $request) {
|
|
||||||
$user = $request->getUser();
|
$user = $request->getUser();
|
||||||
|
|
||||||
// This controller doesn't use blob/path stuff, just pass the dictionary
|
|
||||||
// in directly instead of using the AphrontRequest parsing mechanism.
|
|
||||||
$data = $request->getURIMap();
|
|
||||||
$data['user'] = $user;
|
|
||||||
$drequest = DiffusionRequest::newFromDictionary($data);
|
|
||||||
$this->diffusionRequest = $drequest;
|
|
||||||
|
|
||||||
if ($request->getStr('diff')) {
|
if ($request->getStr('diff')) {
|
||||||
return $this->buildRawDiffResponse($drequest);
|
return $this->buildRawDiffResponse($drequest);
|
||||||
}
|
}
|
||||||
|
|
|
@ -35,7 +35,7 @@ abstract class DiffusionController extends PhabricatorController {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
final public function handleRequest(AphrontRequest $request) {
|
public function handleRequest(AphrontRequest $request) {
|
||||||
if ($request->getURIData('callsign') &&
|
if ($request->getURIData('callsign') &&
|
||||||
$this->shouldLoadDiffusionRequest()) {
|
$this->shouldLoadDiffusionRequest()) {
|
||||||
try {
|
try {
|
||||||
|
@ -48,10 +48,51 @@ abstract class DiffusionController extends PhabricatorController {
|
||||||
}
|
}
|
||||||
$this->setDiffusionRequest($drequest);
|
$this->setDiffusionRequest($drequest);
|
||||||
}
|
}
|
||||||
|
|
||||||
return $this->processDiffusionRequest($request);
|
return $this->processDiffusionRequest($request);
|
||||||
}
|
}
|
||||||
|
|
||||||
abstract protected function processDiffusionRequest(AphrontRequest $request);
|
protected function loadDiffusionContext() {
|
||||||
|
$request = $this->getRequest();
|
||||||
|
$viewer = $this->getViewer();
|
||||||
|
|
||||||
|
$identifier = $request->getURIData('repositoryCallsign');
|
||||||
|
if (!strlen($identifier)) {
|
||||||
|
$identifier = (int)$request->getURIData('repositoryID');
|
||||||
|
}
|
||||||
|
|
||||||
|
$blob = $request->getURIData('dblob');
|
||||||
|
if (strlen($blob)) {
|
||||||
|
$parsed = DiffusionRequest::parseRequestBlob($blob);
|
||||||
|
} else {
|
||||||
|
$parsed = array(
|
||||||
|
'commit' => $request->getURIData('commit'),
|
||||||
|
'path' => $request->getURIData('path'),
|
||||||
|
'line' => $request->getURIData('line'),
|
||||||
|
'branch' => $request->getURIData('branch'),
|
||||||
|
'lint' => $request->getStr('lint'),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
$params = array(
|
||||||
|
'repository' => $identifier,
|
||||||
|
'user' => $viewer,
|
||||||
|
) + $parsed;
|
||||||
|
|
||||||
|
$drequest = DiffusionRequest::newFromDictionary($params);
|
||||||
|
|
||||||
|
if (!$drequest) {
|
||||||
|
return new Aphront404Response();
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->diffusionRequest = $drequest;
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function processDiffusionRequest(AphrontRequest $request) {
|
||||||
|
throw new PhutilMethodNotImplementedException();
|
||||||
|
}
|
||||||
|
|
||||||
public function buildCrumbs(array $spec = array()) {
|
public function buildCrumbs(array $spec = array()) {
|
||||||
$crumbs = $this->buildApplicationCrumbs();
|
$crumbs = $this->buildApplicationCrumbs();
|
||||||
|
|
|
@ -105,6 +105,10 @@ abstract class DiffusionRequest extends Phobject {
|
||||||
$object = self::newFromRepository($repository);
|
$object = self::newFromRepository($repository);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!$object) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
$object->initializeFromDictionary($data);
|
$object->initializeFromDictionary($data);
|
||||||
|
|
||||||
return $object;
|
return $object;
|
||||||
|
@ -175,7 +179,7 @@ abstract class DiffusionRequest extends Phobject {
|
||||||
->executeOne();
|
->executeOne();
|
||||||
|
|
||||||
if (!$repository) {
|
if (!$repository) {
|
||||||
throw new Exception(pht("No such repository '%s'.", $identifier));
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
return self::newFromRepository($repository);
|
return self::newFromRepository($repository);
|
||||||
|
|
|
@ -55,7 +55,7 @@ final class PhabricatorRepositoryQuery
|
||||||
$monograms = array();
|
$monograms = array();
|
||||||
|
|
||||||
foreach ($identifiers as $identifier) {
|
foreach ($identifiers as $identifier) {
|
||||||
if (ctype_digit($identifier)) {
|
if (ctype_digit((string)$identifier)) {
|
||||||
$ids[$identifier] = $identifier;
|
$ids[$identifier] = $identifier;
|
||||||
} else if (preg_match('/^(r[A-Z]+)|(R[1-9]\d*)\z/', $identifier)) {
|
} else if (preg_match('/^(r[A-Z]+)|(R[1-9]\d*)\z/', $identifier)) {
|
||||||
$monograms[$identifier] = $identifier;
|
$monograms[$identifier] = $identifier;
|
||||||
|
|
|
@ -252,8 +252,12 @@ final class PhabricatorRepositoryCommit
|
||||||
$repository = $this->getRepository();
|
$repository = $this->getRepository();
|
||||||
$callsign = $repository->getCallsign();
|
$callsign = $repository->getCallsign();
|
||||||
$identifier = $this->getCommitIdentifier();
|
$identifier = $this->getCommitIdentifier();
|
||||||
|
if ($callsign !== null) {
|
||||||
return "r{$callsign}{$identifier}";
|
return "r{$callsign}{$identifier}";
|
||||||
|
} else {
|
||||||
|
$id = $repository->getID();
|
||||||
|
return "R{$id}:{$identifier}";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getDisplayName() {
|
public function getDisplayName() {
|
||||||
|
|
Loading…
Reference in a new issue