mirror of
https://we.phorge.it/source/phorge.git
synced 2024-11-27 01:02:42 +01:00
Add didParseCommit()
to DifferentialFieldSpecification
Summary: This is mostly ripped from D2721, but doesn't implement the T945 part. After we parse a commit message, give DifferentialFieldSpecifications an opportunity to react to the message as well (e.g., by updating related objects). Test Plan: Impelmented a var_dump() body, ran `reparse.php` on a commit. Reviewers: vrana, 20after4, btrahan, edward Reviewed By: 20after4 CC: aran Maniphest Tasks: T945, T1544 Differential Revision: https://secure.phabricator.com/D3444
This commit is contained in:
parent
7e1f5bc9df
commit
0736592cff
2 changed files with 54 additions and 1 deletions
|
@ -569,6 +569,25 @@ abstract class DifferentialFieldSpecification {
|
|||
}
|
||||
|
||||
|
||||
/**
|
||||
* This method allows you to take action when a commit appears in a tracked
|
||||
* branch (for example, by closing tasks associated with the commit).
|
||||
*
|
||||
* @param PhabricatorRepository The repository the commit appeared in.
|
||||
* @param PhabricatorRepositoryCommit The commit itself.
|
||||
* @param PhabricatorRepostioryCommitData Commit data.
|
||||
* @return void
|
||||
*
|
||||
* @task commit
|
||||
*/
|
||||
public function didParseCommit(
|
||||
PhabricatorRepository $repo,
|
||||
PhabricatorRepositoryCommit $commit,
|
||||
PhabricatorRepositoryCommitData $data) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
/* -( Loading Additional Data )-------------------------------------------- */
|
||||
|
||||
|
||||
|
|
|
@ -79,6 +79,8 @@ abstract class PhabricatorRepositoryCommitMessageParserWorker
|
|||
// revisit this and do something differently. (If we match several revisions
|
||||
// someone probably did something very silly, though.)
|
||||
|
||||
$revision = null;
|
||||
$should_autoclose = $repository->shouldAutocloseCommit($commit, $data);
|
||||
$revision_id = $data->getCommitDetail('differential.revisionID');
|
||||
if (!$revision_id) {
|
||||
$hashes = $this->getCommitHashes(
|
||||
|
@ -142,7 +144,7 @@ abstract class PhabricatorRepositoryCommitMessageParserWorker
|
|||
|
||||
$status_closed = ArcanistDifferentialRevisionStatus::CLOSED;
|
||||
$should_close = ($revision->getStatus() != $status_closed) &&
|
||||
$repository->shouldAutocloseCommit($commit, $data);
|
||||
$should_autoclose;
|
||||
|
||||
if ($should_close) {
|
||||
$diff = $this->attachToRevision($revision, $actor_phid);
|
||||
|
@ -172,6 +174,38 @@ abstract class PhabricatorRepositoryCommitMessageParserWorker
|
|||
}
|
||||
}
|
||||
|
||||
if ($should_autoclose && $author_phid) {
|
||||
$user = id(new PhabricatorUser())->loadOneWhere(
|
||||
'phid = %s',
|
||||
$author_phid);
|
||||
|
||||
$call = new ConduitCall(
|
||||
'differential.parsecommitmessage',
|
||||
array(
|
||||
'corpus' => $message,
|
||||
'partial' => true,
|
||||
));
|
||||
$call->setUser($user);
|
||||
$result = $call->execute();
|
||||
|
||||
$field_values = $result['fields'];
|
||||
|
||||
$fields = DifferentialFieldSelector::newSelector()
|
||||
->getFieldSpecifications();
|
||||
foreach ($fields as $key => $field) {
|
||||
if (!$field->shouldAppearOnCommitMessage()) {
|
||||
continue;
|
||||
}
|
||||
$field->setUser($user);
|
||||
$value = idx($field_values, $field->getCommitMessageKey());
|
||||
$field->setValueFromParsedCommitMessage($value);
|
||||
if ($revision) {
|
||||
$field->setRevision($revision);
|
||||
}
|
||||
$field->didParseCommit($repository, $commit, $data);
|
||||
}
|
||||
}
|
||||
|
||||
$data->save();
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue