mirror of
https://we.phorge.it/source/phorge.git
synced 2024-11-10 08:52:39 +01:00
Add commits/audits to Asana bridge
Summary: Ref T2852. Adds sync for commits/audits. Test Plan: {F51660} Reviewers: btrahan Reviewed By: btrahan CC: aran Maniphest Tasks: T2852 Differential Revision: https://secure.phabricator.com/D6573
This commit is contained in:
parent
3a80c512c7
commit
1c454ea6d9
4 changed files with 194 additions and 1 deletions
|
@ -446,6 +446,7 @@ phutil_register_library_map(array(
|
||||||
'DiffusionCommitTagsController' => 'applications/diffusion/controller/DiffusionCommitTagsController.php',
|
'DiffusionCommitTagsController' => 'applications/diffusion/controller/DiffusionCommitTagsController.php',
|
||||||
'DiffusionController' => 'applications/diffusion/controller/DiffusionController.php',
|
'DiffusionController' => 'applications/diffusion/controller/DiffusionController.php',
|
||||||
'DiffusionDiffController' => 'applications/diffusion/controller/DiffusionDiffController.php',
|
'DiffusionDiffController' => 'applications/diffusion/controller/DiffusionDiffController.php',
|
||||||
|
'DiffusionDoorkeeperCommitFeedStoryPublisher' => 'applications/diffusion/doorkeeper/DiffusionDoorkeeperCommitFeedStoryPublisher.php',
|
||||||
'DiffusionEmptyResultView' => 'applications/diffusion/view/DiffusionEmptyResultView.php',
|
'DiffusionEmptyResultView' => 'applications/diffusion/view/DiffusionEmptyResultView.php',
|
||||||
'DiffusionExpandCommitQueryException' => 'applications/diffusion/exception/DiffusionExpandCommitQueryException.php',
|
'DiffusionExpandCommitQueryException' => 'applications/diffusion/exception/DiffusionExpandCommitQueryException.php',
|
||||||
'DiffusionExpandShortNameQuery' => 'applications/diffusion/query/expandshortname/DiffusionExpandShortNameQuery.php',
|
'DiffusionExpandShortNameQuery' => 'applications/diffusion/query/expandshortname/DiffusionExpandShortNameQuery.php',
|
||||||
|
@ -2436,6 +2437,7 @@ phutil_register_library_map(array(
|
||||||
'DiffusionCommitTagsController' => 'DiffusionController',
|
'DiffusionCommitTagsController' => 'DiffusionController',
|
||||||
'DiffusionController' => 'PhabricatorController',
|
'DiffusionController' => 'PhabricatorController',
|
||||||
'DiffusionDiffController' => 'DiffusionController',
|
'DiffusionDiffController' => 'DiffusionController',
|
||||||
|
'DiffusionDoorkeeperCommitFeedStoryPublisher' => 'DoorkeeperFeedStoryPublisher',
|
||||||
'DiffusionEmptyResultView' => 'DiffusionView',
|
'DiffusionEmptyResultView' => 'DiffusionView',
|
||||||
'DiffusionExpandCommitQueryException' => 'Exception',
|
'DiffusionExpandCommitQueryException' => 'Exception',
|
||||||
'DiffusionExpandShortNameQuery' => 'DiffusionQuery',
|
'DiffusionExpandShortNameQuery' => 'DiffusionQuery',
|
||||||
|
|
|
@ -0,0 +1,163 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
final class DiffusionDoorkeeperCommitFeedStoryPublisher
|
||||||
|
extends DoorkeeperFeedStoryPublisher {
|
||||||
|
|
||||||
|
private $auditRequests;
|
||||||
|
private $activePHIDs;
|
||||||
|
private $passivePHIDs;
|
||||||
|
|
||||||
|
private function getAuditRequests() {
|
||||||
|
return $this->auditRequests;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function canPublishStory(PhabricatorFeedStory $story, $object) {
|
||||||
|
return ($object instanceof PhabricatorRepositoryCommit);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function willPublishStory($commit) {
|
||||||
|
$requests = id(new PhabricatorAuditQuery())
|
||||||
|
->withCommitPHIDs(array($commit->getPHID()))
|
||||||
|
->execute();
|
||||||
|
|
||||||
|
// TODO: This is messy and should be generalized, but we don't have a good
|
||||||
|
// query for it yet. Since we run in the daemons, just do the easiest thing
|
||||||
|
// we can for the moment. Figure out who all of the "active" (need to
|
||||||
|
// audit) and "passive" (no action necessary) user are.
|
||||||
|
|
||||||
|
$auditor_phids = mpull($requests, 'getAuditorPHID');
|
||||||
|
$objects = id(new PhabricatorObjectHandleData($auditor_phids))
|
||||||
|
->setViewer($this->getViewer())
|
||||||
|
->loadObjects();
|
||||||
|
|
||||||
|
$active = array();
|
||||||
|
$passive = array();
|
||||||
|
|
||||||
|
foreach ($requests as $request) {
|
||||||
|
$status = $request->getAuditStatus();
|
||||||
|
if ($status == PhabricatorAuditStatusConstants::CC) {
|
||||||
|
// We handle these specially below.
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
$object = idx($objects, $request->getAuditorPHID());
|
||||||
|
if (!$object) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
$request_phids = array();
|
||||||
|
if ($object instanceof PhabricatorUser) {
|
||||||
|
$request_phids = array($object->getPHID());
|
||||||
|
} else if ($object instanceof PhabricatorOwnersPackage) {
|
||||||
|
$request_phids = PhabricatorOwnersOwner::loadAffiliatedUserPHIDs(
|
||||||
|
array($object->getID()));
|
||||||
|
} else if ($object instanceof PhabricatorProject) {
|
||||||
|
$request_phids = $object->loadMemberPHIDs();
|
||||||
|
} else {
|
||||||
|
// Dunno what this is.
|
||||||
|
$request_phids = array();
|
||||||
|
}
|
||||||
|
|
||||||
|
switch ($status) {
|
||||||
|
case PhabricatorAuditStatusConstants::AUDIT_REQUIRED:
|
||||||
|
case PhabricatorAuditStatusConstants::AUDIT_REQUESTED:
|
||||||
|
case PhabricatorAuditStatusConstants::CONCERNED:
|
||||||
|
$active += array_fuse($request_phids);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
$passive += array_fuse($request_phids);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// Remove "Active" users from the "Passive" list.
|
||||||
|
$passive = array_diff_key($passive, $active);
|
||||||
|
|
||||||
|
$this->activePHIDs = $active;
|
||||||
|
$this->passivePHIDs = $passive;
|
||||||
|
$this->auditRequests = $requests;
|
||||||
|
|
||||||
|
return $commit;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getOwnerPHID($object) {
|
||||||
|
return $object->getAuthorPHID();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getActiveUserPHIDs($object) {
|
||||||
|
return $this->activePHIDs;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getPassiveUserPHIDs($object) {
|
||||||
|
return $this->passivePHIDs;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getCCUserPHIDs($object) {
|
||||||
|
$ccs = array();
|
||||||
|
foreach ($this->getAuditRequests() as $request) {
|
||||||
|
if ($request->getAuditStatus() == PhabricatorAuditStatusConstants::CC) {
|
||||||
|
$ccs[] = $request->getAuditorPHID();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return $ccs;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getObjectTitle($object) {
|
||||||
|
$prefix = $this->getTitlePrefix($object);
|
||||||
|
|
||||||
|
$repository = $object->getRepository();
|
||||||
|
$name = $repository->formatCommitName($object->getCommitIdentifier());
|
||||||
|
|
||||||
|
$title = $object->getSummary();
|
||||||
|
|
||||||
|
return "{$prefix} {$name}: {$title}";
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getObjectURI($object) {
|
||||||
|
$repository = $object->getRepository();
|
||||||
|
$name = $repository->formatCommitName($object->getCommitIdentifier());
|
||||||
|
return PhabricatorEnv::getProductionURI('/'.$name);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getObjectDescription($object) {
|
||||||
|
$data = $object->loadCommitData();
|
||||||
|
if ($data) {
|
||||||
|
return $data->getCommitMessage();
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function isObjectClosed($object) {
|
||||||
|
switch ($object->getAuditStatus()) {
|
||||||
|
case PhabricatorAuditCommitStatusConstants::NEEDS_AUDIT:
|
||||||
|
case PhabricatorAuditCommitStatusConstants::CONCERN_RAISED:
|
||||||
|
case PhabricatorAuditCommitStatusConstants::PARTIALLY_AUDITED:
|
||||||
|
return false;
|
||||||
|
default:
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getResponsibilityTitle($object) {
|
||||||
|
$prefix = $this->getTitlePrefix($object);
|
||||||
|
return pht('%s Audit', $prefix);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getStoryText($object) {
|
||||||
|
$story = $this->getFeedStory();
|
||||||
|
if ($story instanceof PhabricatorFeedStoryAudit) {
|
||||||
|
$text = $story->renderForAsanaBridge();
|
||||||
|
} else {
|
||||||
|
$text = $story->renderText();
|
||||||
|
}
|
||||||
|
return $text;
|
||||||
|
}
|
||||||
|
|
||||||
|
private function getTitlePrefix(PhabricatorRepositoryCommit $commit) {
|
||||||
|
$prefix_key = 'metamta.diffusion.subject-prefix';
|
||||||
|
return PhabricatorEnv::getEnvConfig($prefix_key);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -44,4 +44,31 @@ final class PhabricatorFeedStoryAudit extends PhabricatorFeedStory {
|
||||||
|
|
||||||
return $text;
|
return $text;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// TODO: At some point, make feed rendering not terrible and remove this
|
||||||
|
// hacky mess.
|
||||||
|
public function renderForAsanaBridge() {
|
||||||
|
$data = $this->getStoryData();
|
||||||
|
$comment = $data->getValue('content');
|
||||||
|
|
||||||
|
$author_name = $this->getHandle($this->getAuthorPHID())->getName();
|
||||||
|
$action = $this->getValue('action');
|
||||||
|
$verb = PhabricatorAuditActionConstants::getActionPastTenseVerb($action);
|
||||||
|
|
||||||
|
$title = "{$author_name} {$verb} this commit.";
|
||||||
|
if (strlen($comment)) {
|
||||||
|
$engine = PhabricatorMarkupEngine::newMarkupEngine(array())
|
||||||
|
->setConfig('viewer', new PhabricatorUser())
|
||||||
|
->setMode(PhutilRemarkupEngine::MODE_TEXT);
|
||||||
|
|
||||||
|
$comment = $engine->markupText($comment);
|
||||||
|
|
||||||
|
$title .= "\n\n";
|
||||||
|
$title .= $comment;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $title;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,7 +2,8 @@
|
||||||
|
|
||||||
final class PhabricatorRepositoryCommit
|
final class PhabricatorRepositoryCommit
|
||||||
extends PhabricatorRepositoryDAO
|
extends PhabricatorRepositoryDAO
|
||||||
implements PhabricatorPolicyInterface,
|
implements
|
||||||
|
PhabricatorPolicyInterface,
|
||||||
PhabricatorTokenReceiverInterface {
|
PhabricatorTokenReceiverInterface {
|
||||||
|
|
||||||
protected $repositoryID;
|
protected $repositoryID;
|
||||||
|
|
Loading…
Reference in a new issue