mirror of
https://we.phorge.it/source/phorge.git
synced 2024-11-10 00:42:41 +01:00
Implement "Body" field in Herald pre-commit content hooks
Summary: Ref T4195. Adds support for writing rules against commit message bodies. Test Plan: Pushed git, hg, svn commits and verified their bodies populated correctly in transcripts. Reviewers: btrahan Reviewed By: btrahan CC: aran Maniphest Tasks: T4195 Differential Revision: https://secure.phabricator.com/D7796
This commit is contained in:
parent
f37832aed7
commit
151f01ae94
3 changed files with 42 additions and 1 deletions
|
@ -934,4 +934,34 @@ final class DiffusionCommitHookEngine extends Phobject {
|
|||
return $diff->getChangesets();
|
||||
}
|
||||
|
||||
public function loadCommitRefForCommit($identifier) {
|
||||
$repository = $this->getRepository();
|
||||
$vcs = $repository->getVersionControlSystem();
|
||||
switch ($vcs) {
|
||||
case PhabricatorRepositoryType::REPOSITORY_TYPE_GIT:
|
||||
return id(new DiffusionLowLevelGitCommitQuery())
|
||||
->setRepository($repository)
|
||||
->withIdentifier($identifier)
|
||||
->execute();
|
||||
case PhabricatorRepositoryType::REPOSITORY_TYPE_MERCURIAL:
|
||||
return id(new DiffusionLowLevelMercurialCommitQuery())
|
||||
->setRepository($repository)
|
||||
->withIdentifier($identifier)
|
||||
->execute();
|
||||
case PhabricatorRepositoryType::REPOSITORY_TYPE_SVN:
|
||||
// For subversion, we need to use `svnlook`.
|
||||
list($message) = execx(
|
||||
'svnlook log -t %s %s',
|
||||
$this->subversionTransaction,
|
||||
$this->subversionRepository);
|
||||
|
||||
return id(new DiffusionCommitRef())
|
||||
->setMessage($message);
|
||||
break;
|
||||
default:
|
||||
throw new Exception(pht("Unknown VCS '%s!'", $vcs));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -5,6 +5,7 @@ final class HeraldPreCommitContentAdapter extends HeraldAdapter {
|
|||
private $log;
|
||||
private $hookEngine;
|
||||
private $changesets;
|
||||
private $commitRef;
|
||||
|
||||
public function setPushLog(PhabricatorRepositoryPushLog $log) {
|
||||
$this->log = $log;
|
||||
|
@ -84,6 +85,8 @@ final class HeraldPreCommitContentAdapter extends HeraldAdapter {
|
|||
public function getHeraldField($field) {
|
||||
$log = $this->getObject();
|
||||
switch ($field) {
|
||||
case self::FIELD_BODY:
|
||||
return $this->getCommitRef()->getMessage();
|
||||
case self::FIELD_DIFF_FILE:
|
||||
return $this->getDiffContent('name');
|
||||
case self::FIELD_DIFF_CONTENT:
|
||||
|
@ -179,4 +182,12 @@ final class HeraldPreCommitContentAdapter extends HeraldAdapter {
|
|||
return $result;
|
||||
}
|
||||
|
||||
private function getCommitRef() {
|
||||
if ($this->commitRef === null) {
|
||||
$this->commitRef = $this->hookEngine->loadCommitRefForCommit(
|
||||
$this->log->getRefNew());
|
||||
}
|
||||
return $this->commitRef;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -16,7 +16,7 @@ final class HeraldRule extends HeraldDAO
|
|||
protected $ruleType;
|
||||
protected $isDisabled = 0;
|
||||
|
||||
protected $configVersion = 18;
|
||||
protected $configVersion = 19;
|
||||
|
||||
// phids for which this rule has been applied
|
||||
private $ruleApplied = self::ATTACHABLE;
|
||||
|
|
Loading…
Reference in a new issue