@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 DifferentialCommitsSearchEngineAttachment
4 extends PhabricatorSearchEngineAttachment {
5
6 public function getAttachmentName() {
7 return pht('Diff Commits');
8 }
9
10 public function getAttachmentDescription() {
11 return pht('Get the local commits (if any) for each diff.');
12 }
13
14 public function loadAttachmentData(array $objects, $spec) {
15 $properties = id(new DifferentialDiffProperty())->loadAllWhere(
16 'diffID IN (%Ld) AND name = %s',
17 mpull($objects, 'getID'),
18 'local:commits');
19
20 $map = array();
21 foreach ($properties as $property) {
22 $map[$property->getDiffID()] = $property->getData();
23 }
24
25 return $map;
26 }
27
28 public function getAttachmentForObject($object, $data, $spec) {
29 $diff_id = $object->getID();
30 $info = idx($data, $diff_id, array());
31
32 // NOTE: This should be similar to the information returned about commits
33 // by "diffusion.commit.search".
34
35 $list = array();
36 foreach ($info as $commit) {
37 $author_epoch = idx($commit, 'time');
38 if ($author_epoch) {
39 $author_epoch = (int)$author_epoch;
40 }
41
42 // TODO: Currently, we don't upload the raw author string from "arc".
43 // Reconstruct a plausible version of it until we begin uploading this
44 // information.
45
46 $author_name = idx($commit, 'author');
47 $author_email = idx($commit, 'authorEmail');
48 if (strlen($author_name) && strlen($author_email)) {
49 $author_raw = (string)id(new PhutilEmailAddress())
50 ->setDisplayName($author_name)
51 ->setAddress($author_email);
52 } else if (strlen($author_email)) {
53 $author_raw = $author_email;
54 } else {
55 $author_raw = $author_name;
56 }
57
58 $list[] = array(
59 'identifier' => $commit['commit'],
60 'tree' => idx($commit, 'tree'),
61 'parents' => idx($commit, 'parents', array()),
62 'author' => array(
63 'name' => $author_name,
64 'email' => $author_email,
65 'raw' => $author_raw,
66 'epoch' => $author_epoch,
67 ),
68 'message' => idx($commit, 'message'),
69 );
70 }
71
72 return array(
73 'commits' => $list,
74 );
75 }
76
77}