Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
freebsd
GitHub Repository: freebsd/phabricator
Path: blob/master/src/applications/differential/harbormaster/DifferentialBuildableEngine.php
12256 views
1
<?php
2
3
final class DifferentialBuildableEngine
4
extends HarbormasterBuildableEngine {
5
6
protected function getPublishableObject() {
7
$object = $this->getObject();
8
9
if ($object instanceof DifferentialDiff) {
10
if ($object->getRevisionID()) {
11
return $object->getRevision();
12
} else {
13
return null;
14
}
15
}
16
17
return $object;
18
}
19
20
public function publishBuildable(
21
HarbormasterBuildable $old,
22
HarbormasterBuildable $new) {
23
24
// If we're publishing to a diff that is not actually attached to a
25
// revision, we have nothing to publish to, so just bail out.
26
$revision = $this->getPublishableObject();
27
if (!$revision) {
28
return;
29
}
30
31
// Don't publish manual buildables.
32
if ($new->getIsManualBuildable()) {
33
return;
34
}
35
36
// Don't publish anything if the buildable is still building. Differential
37
// treats more buildables as "building" than Harbormaster does, but the
38
// Differential definition is a superset of the Harbormaster definition.
39
if ($new->isBuilding()) {
40
return;
41
}
42
43
$viewer = $this->getViewer();
44
45
$old_status = $revision->getBuildableStatus($new->getPHID());
46
$new_status = $revision->newBuildableStatus($viewer, $new->getPHID());
47
if ($old_status === $new_status) {
48
return;
49
}
50
51
$buildable_type = DifferentialRevisionBuildableTransaction::TRANSACTIONTYPE;
52
53
$xaction = $this->newTransaction()
54
->setMetadataValue('harbormaster:buildablePHID', $new->getPHID())
55
->setTransactionType($buildable_type)
56
->setNewValue($new_status);
57
58
$this->applyTransactions(array($xaction));
59
}
60
61
public function getAuthorIdentity() {
62
$object = $this->getObject();
63
64
if ($object instanceof DifferentialRevision) {
65
$object = $object->loadActiveDiff();
66
}
67
68
$authorship = $object->getDiffAuthorshipDict();
69
if (!isset($authorship['authorName'])) {
70
return null;
71
}
72
73
$name = $authorship['authorName'];
74
$address = idx($authorship, 'authorEmail');
75
76
$full = id(new PhutilEmailAddress())
77
->setDisplayName($name)
78
->setAddress($address);
79
80
return id(new PhabricatorRepositoryIdentity())
81
->setIdentityName((string)$full)
82
->makeEphemeral();
83
}
84
85
}
86
87