From f3f3d957021b4ab6da2256dc099e152b95720c3d Mon Sep 17 00:00:00 2001 From: epriestley Date: Wed, 14 Oct 2015 10:50:53 -0700 Subject: [PATCH] When landing revisions via repository automation, use better metadata Summary: Ref T182. Make a reasonable attempt to get the commit message, author, and committer data correct. Test Plan: BEHOLD: rGITTEST810b7f17cd0c909256a45d29a5062fcf417d0489 Reviewers: chad Reviewed By: chad Maniphest Tasks: T182 Differential Revision: https://secure.phabricator.com/D14280 --- .../differential/storage/DifferentialDiff.php | 6 ++ .../DrydockLandRepositoryOperation.php | 55 +++++++++++++++++-- 2 files changed, 57 insertions(+), 4 deletions(-) diff --git a/src/applications/differential/storage/DifferentialDiff.php b/src/applications/differential/storage/DifferentialDiff.php index 959d7f24c1..42bee674ba 100644 --- a/src/applications/differential/storage/DifferentialDiff.php +++ b/src/applications/differential/storage/DifferentialDiff.php @@ -251,6 +251,12 @@ final class DifferentialDiff $dict['changes'] = $this->buildChangesList(); + return $dict + $this->getDiffAuthorshipDict(); + } + + public function getDiffAuthorshipDict() { + $dict = array(); + $properties = id(new DifferentialDiffProperty())->loadAllWhere( 'diffID = %d', $this->getID()); diff --git a/src/applications/drydock/operation/DrydockLandRepositoryOperation.php b/src/applications/drydock/operation/DrydockLandRepositoryOperation.php index a4549e072c..a71de3fff9 100644 --- a/src/applications/drydock/operation/DrydockLandRepositoryOperation.php +++ b/src/applications/drydock/operation/DrydockLandRepositoryOperation.php @@ -48,6 +48,19 @@ final class DrydockLandRepositoryOperation $arg[] = $diff->getStagingRef(); $merge_src = $diff->getStagingRef(); + + $dict = $diff->getDiffAuthorshipDict(); + $author_name = idx($dict, 'authorName'); + $author_email = idx($dict, 'authorEmail'); + + $api_method = 'differential.getcommitmessage'; + $api_params = array( + 'revision_id' => $revision->getID(), + ); + + $commit_message = id(new ConduitCall($api_method, $api_params)) + ->setUser($viewer) + ->execute(); } else { throw new Exception( pht( @@ -71,6 +84,8 @@ final class DrydockLandRepositoryOperation $target)); } + $committer_info = $this->getCommitterInfo($operation); + $cmd[] = 'git checkout %s'; $arg[] = $merge_dst; @@ -78,10 +93,12 @@ final class DrydockLandRepositoryOperation $arg[] = $merge_src; $cmd[] = 'git -c user.name=%s -c user.email=%s commit --author %s -m %s'; - $arg[] = 'autocommitter'; - $arg[] = 'autocommitter@example.com'; - $arg[] = 'autoauthor '; - $arg[] = pht('(Automerge!)'); + + $arg[] = $committer_info['name']; + $arg[] = $committer_info['email']; + + $arg[] = "{$author_name} <{$author_email}>"; + $arg[] = $commit_message; $cmd[] = 'git push origin -- %s:%s'; $arg[] = 'HEAD'; @@ -95,4 +112,34 @@ final class DrydockLandRepositoryOperation $argv); } + private function getCommitterInfo(DrydockRepositoryOperation $operation) { + $viewer = $this->getViewer(); + + $committer_name = null; + + $author_phid = $operation->getAuthorPHID(); + $object = id(new PhabricatorObjectQuery()) + ->setViewer($viewer) + ->withPHIDs(array($author_phid)) + ->executeOne(); + + if ($object) { + if ($object instanceof PhabricatorUser) { + $committer_name = $object->getUsername(); + } + } + + if (!strlen($committer_name)) { + $committer_name = pht('autocommitter'); + } + + // TODO: Probably let users choose a VCS email address in settings. For + // now just make something up so we don't leak anyone's stuff. + + return array( + 'name' => $committer_name, + 'email' => 'autocommitter@example.com', + ); + } + }