mirror of
https://we.phorge.it/source/phorge.git
synced 2024-12-20 04:20:55 +01:00
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
This commit is contained in:
parent
3a91e64897
commit
f3f3d95702
2 changed files with 57 additions and 4 deletions
|
@ -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());
|
||||
|
|
|
@ -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 <autoauthor@example.com>';
|
||||
$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',
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue