Page MenuHomePhorge

D25028.1737969742.diff
No OneTemporary

D25028.1737969742.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,92 @@
+<?php
+
+final class DifferentialCoAuthorsCommitMessageField
+ extends DifferentialCommitMessageField {
+
+ const FIELDKEY = 'co-authors';
+
+ /**
+ * @var array<string, string|null>
+ */
+ protected $userEmailCache = 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) {
+ $author_id = $revision->getAuthorPHID();
+ $diff_properties = $revision->getActiveDiff()
+ ->getDiffAuthorshipDict()['properties'];
+ $co_authors = array();
+
+ if (!array_key_exists('local:commits', $diff_properties)) {
+ return '';
+ }
+
+ foreach ($diff_properties['local:commits'] as $commit) {
+ if ($this->getUserPHID($commit['authorEmail']) === $author_id) {
+ continue;
+ }
+
+ $co_authors[] = pht(
+ 'Co-authored-by: %s <%s>',
+ $commit['author'],
+ $commit['authorEmail']);
+ }
+
+ return implode("\n", array_unique($co_authors));
+ }
+}
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
Mon, Jan 27, 09:22 (7 h, 37 m ago)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
1150517
Default Alt Text
D25028.1737969742.diff (5 KB)

Event Timeline