@recaptime-dev's working patches + fork for Phorge, a community fork of Phabricator. (Upstream dev and stable branches are at upstream/main and upstream/stable respectively.) hq.recaptime.dev/wiki/Phorge
phorge phabricator
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

at recaptime-dev/main 124 lines 3.8 kB view raw
1<?php 2 3final class AuditQueryConduitAPIMethod extends AuditConduitAPIMethod { 4 5 const AUDIT_LEGACYSTATUS_ANY = 'audit-status-any'; 6 const AUDIT_LEGACYSTATUS_OPEN = 'audit-status-open'; 7 const AUDIT_LEGACYSTATUS_CONCERN = 'audit-status-concern'; 8 const AUDIT_LEGACYSTATUS_ACCEPTED = 'audit-status-accepted'; 9 const AUDIT_LEGACYSTATUS_PARTIAL = 'audit-status-partial'; 10 11 public function getAPIMethodName() { 12 return 'audit.query'; 13 } 14 15 public function getMethodDescription() { 16 return pht('Query audit requests.'); 17 } 18 19 public function getMethodStatus() { 20 return self::METHOD_STATUS_FROZEN; 21 } 22 23 public function getMethodStatusDescription() { 24 return pht( 25 'This method is frozen and will eventually be deprecated. New code '. 26 'should use "diffusion.commit.search" instead.'); 27 } 28 29 protected function defineParamTypes() { 30 $statuses = array( 31 self::AUDIT_LEGACYSTATUS_ANY, 32 self::AUDIT_LEGACYSTATUS_OPEN, 33 self::AUDIT_LEGACYSTATUS_CONCERN, 34 self::AUDIT_LEGACYSTATUS_ACCEPTED, 35 self::AUDIT_LEGACYSTATUS_PARTIAL, 36 ); 37 $status_const = $this->formatStringConstants($statuses); 38 39 return array( 40 'auditorPHIDs' => 'optional list<phid>', 41 'commitPHIDs' => 'optional list<phid>', 42 'status' => ('optional '.$status_const. 43 ' (default = "audit-status-any")'), 44 'offset' => 'optional int', 45 'limit' => 'optional int (default = 100)', 46 ); 47 } 48 49 protected function defineReturnType() { 50 return 'list<dict>'; 51 } 52 53 protected function execute(ConduitAPIRequest $request) { 54 55 $query = id(new DiffusionCommitQuery()) 56 ->setViewer($request->getUser()) 57 ->needAuditRequests(true); 58 59 $auditor_phids = $request->getValue('auditorPHIDs', array()); 60 if ($auditor_phids) { 61 $query->withAuditorPHIDs($auditor_phids); 62 } 63 64 $commit_phids = $request->getValue('commitPHIDs', array()); 65 if ($commit_phids) { 66 $query->withPHIDs($commit_phids); 67 } 68 69 $status_map = array( 70 self::AUDIT_LEGACYSTATUS_OPEN => array( 71 DiffusionCommitAuditStatus::NEEDS_AUDIT, 72 DiffusionCommitAuditStatus::CONCERN_RAISED, 73 ), 74 self::AUDIT_LEGACYSTATUS_CONCERN => array( 75 DiffusionCommitAuditStatus::CONCERN_RAISED, 76 ), 77 self::AUDIT_LEGACYSTATUS_ACCEPTED => array( 78 DiffusionCommitAuditStatus::AUDITED, 79 ), 80 self::AUDIT_LEGACYSTATUS_PARTIAL => array( 81 DiffusionCommitAuditStatus::PARTIALLY_AUDITED, 82 ), 83 ); 84 85 $status = $request->getValue('status'); 86 if ($status !== null && isset($status_map[$status])) { 87 $query->withStatuses($status_map[$status]); 88 } 89 90 // NOTE: These affect the number of commits identified, which is sort of 91 // reasonable but means the method may return an arbitrary number of 92 // actual audit requests. 93 $query->setOffset($request->getValue('offset', 0)); 94 $query->setLimit($request->getValue('limit', 100)); 95 96 $commits = $query->execute(); 97 98 $auditor_map = array_fuse($auditor_phids); 99 100 $results = array(); 101 foreach ($commits as $commit) { 102 $requests = $commit->getAudits(); 103 foreach ($requests as $request) { 104 105 // If this audit isn't triggered for one of the requested PHIDs, 106 // skip it. 107 if ($auditor_map && empty($auditor_map[$request->getAuditorPHID()])) { 108 continue; 109 } 110 111 $results[] = array( 112 'id' => $request->getID(), 113 'commitPHID' => $request->getCommitPHID(), 114 'auditorPHID' => $request->getAuditorPHID(), 115 'reasons' => array(), 116 'status' => $request->getAuditStatus(), 117 ); 118 } 119 } 120 121 return $results; 122 } 123 124}