1
0
Fork 0
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:
epriestley 2016-01-05 04:42:07 -08:00
parent 07e2596aa1
commit fb3b4ee532
6 changed files with 68 additions and 18 deletions

View file

@ -47,8 +47,13 @@ final class PhabricatorDiffusionApplication extends PhabricatorApplication {
public function getRoutes() {
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',
'/diffusion/' => array(
'(?:query/(?P<queryKey>[^/]+)/)?'
=> 'DiffusionRepositoryListController',

View file

@ -17,19 +17,15 @@ final class DiffusionCommitController extends DiffusionController {
return true;
}
protected function shouldLoadDiffusionRequest() {
return false;
public function handleRequest(AphrontRequest $request) {
$response = $this->loadDiffusionContext();
if ($response) {
return $response;
}
protected function processDiffusionRequest(AphrontRequest $request) {
$user = $request->getUser();
$drequest = $this->getDiffusionRequest();
// 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;
$user = $request->getUser();
if ($request->getStr('diff')) {
return $this->buildRawDiffResponse($drequest);

View file

@ -35,7 +35,7 @@ abstract class DiffusionController extends PhabricatorController {
return true;
}
final public function handleRequest(AphrontRequest $request) {
public function handleRequest(AphrontRequest $request) {
if ($request->getURIData('callsign') &&
$this->shouldLoadDiffusionRequest()) {
try {
@ -48,10 +48,51 @@ abstract class DiffusionController extends PhabricatorController {
}
$this->setDiffusionRequest($drequest);
}
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()) {
$crumbs = $this->buildApplicationCrumbs();

View file

@ -105,6 +105,10 @@ abstract class DiffusionRequest extends Phobject {
$object = self::newFromRepository($repository);
}
if (!$object) {
return null;
}
$object->initializeFromDictionary($data);
return $object;
@ -175,7 +179,7 @@ abstract class DiffusionRequest extends Phobject {
->executeOne();
if (!$repository) {
throw new Exception(pht("No such repository '%s'.", $identifier));
return null;
}
return self::newFromRepository($repository);

View file

@ -55,7 +55,7 @@ final class PhabricatorRepositoryQuery
$monograms = array();
foreach ($identifiers as $identifier) {
if (ctype_digit($identifier)) {
if (ctype_digit((string)$identifier)) {
$ids[$identifier] = $identifier;
} else if (preg_match('/^(r[A-Z]+)|(R[1-9]\d*)\z/', $identifier)) {
$monograms[$identifier] = $identifier;

View file

@ -252,8 +252,12 @@ final class PhabricatorRepositoryCommit
$repository = $this->getRepository();
$callsign = $repository->getCallsign();
$identifier = $this->getCommitIdentifier();
if ($callsign !== null) {
return "r{$callsign}{$identifier}";
} else {
$id = $repository->getID();
return "R{$id}:{$identifier}";
}
}
public function getDisplayName() {