Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F15392025
D7802.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
2 KB
Referenced Files
None
Subscribers
None
D7802.diff
View Options
Index: src/applications/diffusion/herald/HeraldPreCommitContentAdapter.php
===================================================================
--- src/applications/diffusion/herald/HeraldPreCommitContentAdapter.php
+++ src/applications/diffusion/herald/HeraldPreCommitContentAdapter.php
@@ -38,6 +38,8 @@
return array_merge(
array(
self::FIELD_BODY,
+ self::FIELD_AUTHOR,
+ self::FIELD_COMMITTER,
self::FIELD_DIFF_FILE,
self::FIELD_DIFF_CONTENT,
self::FIELD_DIFF_ADDED_CONTENT,
@@ -87,6 +89,10 @@
switch ($field) {
case self::FIELD_BODY:
return $this->getCommitRef()->getMessage();
+ case self::FIELD_AUTHOR:
+ return $this->getAuthorPHID();
+ case self::FIELD_COMMITTER:
+ return $this->getCommitterPHID();
case self::FIELD_DIFF_FILE:
return $this->getDiffContent('name');
case self::FIELD_DIFF_CONTENT:
@@ -190,4 +196,52 @@
return $this->commitRef;
}
+ private function getAuthorPHID() {
+ $repository = $this->hookEngine->getRepository();
+ $vcs = $repository->getVersionControlSystem();
+ switch ($vcs) {
+ case PhabricatorRepositoryType::REPOSITORY_TYPE_GIT:
+ case PhabricatorRepositoryType::REPOSITORY_TYPE_MERCURIAL:
+ $ref = $this->getCommitRef();
+ $author = $ref->getAuthor();
+ if (!strlen($author)) {
+ return null;
+ }
+ return $this->lookupUser($author);
+ case PhabricatorRepositoryType::REPOSITORY_TYPE_SVN:
+ // In Subversion, the pusher is always the author.
+ return $this->hookEngine->getViewer()->getPHID();
+ }
+ }
+
+ private function getCommitterPHID() {
+ $repository = $this->hookEngine->getRepository();
+ $vcs = $repository->getVersionControlSystem();
+ switch ($vcs) {
+ case PhabricatorRepositoryType::REPOSITORY_TYPE_GIT:
+ case PhabricatorRepositoryType::REPOSITORY_TYPE_MERCURIAL:
+ // Here, if there's no committer, we're going to return the author
+ // instead.
+ $ref = $this->getCommitRef();
+ $committer = $ref->getCommitter();
+ if (!strlen($committer)) {
+ return $this->getAuthorPHID();
+ }
+ $phid = $this->lookupUser($committer);
+ if (!$phid) {
+ return $this->getAuthorPHID();
+ }
+ return $phid;
+ case PhabricatorRepositoryType::REPOSITORY_TYPE_SVN:
+ // In Subversion, the pusher is always the committer.
+ return $this->hookEngine->getViewer()->getPHID();
+ }
+ }
+
+ private function lookupUser($author) {
+ return id(new DiffusionResolveUserQuery())
+ ->withName($author)
+ ->execute();
+ }
+
}
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Sun, Mar 16, 12:54 PM (11 h, 15 m ago)
Storage Engine
blob
Storage Format
Encrypted (AES-256-CBC)
Storage Handle
7250110
Default Alt Text
D7802.diff (2 KB)
Attached To
Mode
D7802: Add "Author" and "Committer" fields to Herald pre-commit content hooks
Attached
Detach File
Event Timeline
Log In to Comment