@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<?php
2
3final class DiffusionGetRecentCommitsByPathConduitAPIMethod
4 extends DiffusionConduitAPIMethod {
5
6 const DEFAULT_LIMIT = 10;
7
8 public function getAPIMethodName() {
9 return 'diffusion.getrecentcommitsbypath';
10 }
11
12 public function getMethodStatus() {
13 return self::METHOD_STATUS_DEPRECATED;
14 }
15
16 public function getMethodStatusDescription() {
17 return pht(
18 'This method has been deprecated since %s in favor of %s.',
19 '08/2018',
20 'diffusion.historyquery');
21 }
22
23 public function getMethodDescription() {
24 return pht(
25 'Get commit identifiers for recent commits affecting a given path.');
26 }
27
28 protected function defineParamTypes() {
29 return array(
30 'callsign' => 'required string',
31 'path' => 'required string',
32 'branch' => 'optional string',
33 'limit' => 'optional int',
34 );
35 }
36
37 protected function defineErrorTypes() {
38 return array(
39 'ERR_NOT_FOUND' => pht('Repository was not found.'),
40 );
41 }
42
43 protected function defineReturnType() {
44 return 'nonempty list<string>';
45 }
46
47 protected function execute(ConduitAPIRequest $request) {
48 $drequest = DiffusionRequest::newFromDictionary(
49 array(
50 'user' => $request->getUser(),
51 'callsign' => $request->getValue('callsign'),
52 'path' => $request->getValue('path'),
53 'branch' => $request->getValue('branch'),
54 ));
55
56 if ($drequest === null) {
57 throw new ConduitException('ERR_NOT_FOUND');
58 }
59
60 $limit = nonempty(
61 $request->getValue('limit'),
62 self::DEFAULT_LIMIT);
63
64 $history_result = DiffusionQuery::callConduitWithDiffusionRequest(
65 $request->getUser(),
66 $drequest,
67 'diffusion.historyquery',
68 array(
69 'commit' => $drequest->getCommit(),
70 'path' => $drequest->getPath(),
71 'offset' => 0,
72 'limit' => $limit,
73 'needDirectChanges' => true,
74 'needChildChanges' => true,
75 ));
76 $history = DiffusionPathChange::newFromConduit(
77 $history_result['pathChanges']);
78
79 $raw_commit_identifiers = mpull($history, 'getCommitIdentifier');
80 $result = array();
81 foreach ($raw_commit_identifiers as $id) {
82 $result[] = 'r'.$request->getValue('callsign').$id;
83 }
84 return $result;
85 }
86
87}