Page MenuHomePhorge

D25028.1737596328.diff
No OneTemporary

D25028.1737596328.diff

diff --git a/src/__phutil_library_map__.php b/src/__phutil_library_map__.php
--- a/src/__phutil_library_map__.php
+++ b/src/__phutil_library_map__.php
@@ -487,6 +487,7 @@
'DifferentialChangesetTwoUpTestRenderer' => 'applications/differential/render/DifferentialChangesetTwoUpTestRenderer.php',
'DifferentialChangesetViewController' => 'applications/differential/controller/DifferentialChangesetViewController.php',
'DifferentialCloseConduitAPIMethod' => 'applications/differential/conduit/DifferentialCloseConduitAPIMethod.php',
+ 'DifferentialCoAuthorsCommitMessageField' => 'applications/differential/field/DifferentialCoAuthorsCommitMessageField.php',
'DifferentialCommitMessageCustomField' => 'applications/differential/field/DifferentialCommitMessageCustomField.php',
'DifferentialCommitMessageField' => 'applications/differential/field/DifferentialCommitMessageField.php',
'DifferentialCommitMessageFieldTestCase' => 'applications/differential/field/__tests__/DifferentialCommitMessageFieldTestCase.php',
@@ -6588,6 +6589,7 @@
'DifferentialChangesetTwoUpTestRenderer' => 'DifferentialChangesetTestRenderer',
'DifferentialChangesetViewController' => 'DifferentialController',
'DifferentialCloseConduitAPIMethod' => 'DifferentialConduitAPIMethod',
+ 'DifferentialCoAuthorsCommitMessageField' => 'DifferentialCommitMessageField',
'DifferentialCommitMessageCustomField' => 'DifferentialCommitMessageField',
'DifferentialCommitMessageField' => 'Phobject',
'DifferentialCommitMessageFieldTestCase' => 'PhabricatorTestCase',
diff --git a/src/applications/differential/conduit/DifferentialGetCommitMessageConduitAPIMethod.php b/src/applications/differential/conduit/DifferentialGetCommitMessageConduitAPIMethod.php
--- a/src/applications/differential/conduit/DifferentialGetCommitMessageConduitAPIMethod.php
+++ b/src/applications/differential/conduit/DifferentialGetCommitMessageConduitAPIMethod.php
@@ -95,6 +95,7 @@
}
$key_title = DifferentialTitleCommitMessageField::FIELDKEY;
+ $key_co_authors = DifferentialCoAuthorsCommitMessageField::FIELDKEY;
$commit_message = array();
foreach ($field_list as $field_key => $field) {
@@ -114,13 +115,14 @@
}
$is_title = ($field_key == $key_title);
+ $is_co_authors = ($field_key == $key_co_authors);
if (!strlen($value)) {
if ($is_template) {
$commit_message[] = $label.': ';
}
} else {
- if ($is_title) {
+ if ($is_title || $is_co_authors) {
$commit_message[] = $value;
} else {
$value = str_replace(
diff --git a/src/applications/differential/field/DifferentialCoAuthorsCommitMessageField.php b/src/applications/differential/field/DifferentialCoAuthorsCommitMessageField.php
new file mode 100644
--- /dev/null
+++ b/src/applications/differential/field/DifferentialCoAuthorsCommitMessageField.php
@@ -0,0 +1,121 @@
+<?php
+
+final class DifferentialCoAuthorsCommitMessageField
+ extends DifferentialCommitMessageField {
+
+ const FIELDKEY = 'co-authors';
+
+ /**
+ * @var array<string, string|null>
+ */
+ protected $userEmailCache = array();
+
+ /**
+ * @var string
+ */
+ protected $authorPHID = null;
+
+ /**
+ * @var string[]
+ */
+ protected $coAuthors = array();
+
+ /**
+ * @return string
+ */
+ public function getFieldName() {
+ return pht('Co-Authors');
+ }
+
+ /**
+ * @return number
+ */
+ public function getFieldOrder() {
+ return 9999999;
+ }
+
+ /**
+ * @param string $value
+ * @return bool
+ */
+ public function validateFieldValue($value) {
+ return true;
+ }
+
+ /**
+ * @return bool
+ */
+ public function isFieldEditable() {
+ return false;
+ }
+
+ /**
+ * @return bool
+ */
+ public function isTemplateField() {
+ return false;
+ }
+
+ /**
+ * @param string $email
+ *
+ * @return string|null
+ */
+ protected function getUserPHID($email) {
+ if (!array_key_exists($email, $this->userEmailCache)) {
+ $this->userEmailCache[$email] = (new DiffusionResolveUserQuery())
+ ->withName($email)
+ ->execute();
+ }
+
+ return $this->userEmailCache[$email];
+ }
+
+ /**
+ * @param DifferentialRevision<mixed> $revision
+ *
+ * @return string
+ */
+ public function readFieldValueFromObject(DifferentialRevision $revision) {
+ $this->authorPHID = $revision->getAuthorPHID();
+ $diff_properties = $revision->getActiveDiff()
+ ->getDiffAuthorshipDict()['properties'];
+
+ if (!array_key_exists('local:commits', $diff_properties)) {
+ return '';
+ }
+
+ foreach ($diff_properties['local:commits'] as $commit) {
+ $this->addCoAuthor($commit['author'], $commit['authorEmail']);
+
+ if (array_key_exists('coAuthors', $commit)) {
+ foreach ($commit['coAuthors'] as $co_author) {
+ $this->addCoAuthor($co_author['name'], $co_author['email']);
+ }
+ }
+ }
+
+ return implode("\n", $this->getCoAuthors());
+ }
+
+ /**
+ * @param string $name
+ * @param string $email
+ *
+ * @return void
+ */
+ protected function addCoAuthor($name, $email) {
+ if ($this->getUserPHID($email) === $this->authorPHID) {
+ return;
+ }
+
+ $this->coAuthors[] = pht('Co-authored-by: %s <%s>', $name, $email);
+ }
+
+ /**
+ * @return string[]
+ */
+ protected function getCoAuthors() {
+ return array_unique($this->coAuthors);
+ }
+}
diff --git a/src/applications/diffusion/query/DiffusionResolveUserQuery.php b/src/applications/diffusion/query/DiffusionResolveUserQuery.php
--- a/src/applications/diffusion/query/DiffusionResolveUserQuery.php
+++ b/src/applications/diffusion/query/DiffusionResolveUserQuery.php
@@ -9,11 +9,19 @@
private $name;
+ /**
+ * @param string $name
+ *
+ * @return self
+ */
public function withName($name) {
$this->name = $name;
return $this;
}
+ /**
+ * @return string|null
+ */
public function execute() {
return $this->findUserPHID($this->name);
}

File Metadata

Mime Type
text/plain
Expires
Thu, Jan 23, 01:38 (4 d, 15 h ago)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
1110000
Default Alt Text
D25028.1737596328.diff (5 KB)

Event Timeline