2011-03-25 05:32:26 +01:00
|
|
|
<?php
|
|
|
|
|
2014-08-20 23:26:29 +02:00
|
|
|
final class HeraldDifferentialRevisionAdapter
|
2015-07-30 21:22:35 +02:00
|
|
|
extends HeraldDifferentialAdapter
|
|
|
|
implements HarbormasterBuildableAdapterInterface {
|
2011-03-25 05:32:26 +01:00
|
|
|
|
|
|
|
protected $revision;
|
|
|
|
|
2011-04-06 05:49:31 +02:00
|
|
|
protected $affectedPackages;
|
|
|
|
protected $changesets;
|
2014-04-14 21:06:26 +02:00
|
|
|
private $haveHunks;
|
2011-04-06 05:49:31 +02:00
|
|
|
|
2015-10-02 15:32:08 +02:00
|
|
|
private $buildRequests = array();
|
2015-07-30 21:22:35 +02:00
|
|
|
|
2013-10-05 00:15:48 +02:00
|
|
|
public function getAdapterApplicationClass() {
|
2014-07-23 02:03:09 +02:00
|
|
|
return 'PhabricatorDifferentialApplication';
|
2013-08-02 17:55:13 +02:00
|
|
|
}
|
|
|
|
|
2015-04-23 00:25:34 +02:00
|
|
|
protected function newObject() {
|
2015-04-22 23:01:32 +02:00
|
|
|
return new DifferentialRevision();
|
|
|
|
}
|
|
|
|
|
Make Herald test workflow modular and more clear
Summary:
Fixes T9719. Currently, the Herald "Test Console" has a big `instanceof` thing, so new adapters (like a Calendar adapter, or third-party adapters) aren't available automatically. Instead, do a standard modular thing: load the available adapters, ask which ones can test the object the user selected, then let the user pick which one they want to move forward with.
Additionally, it isn't very clear that you can't test "commit hook" rules because they rely on push state which we don't really have a good way to simulate. When the user picks a commit, we now show them the "Hook" events, but the options are disabled and explain why they can not be selected.
Test Plan:
- Ran test rules for revisions, commits, mocks, tasks, wiki documents, questions, and outbound mail.
- Plugged in a commit, got a more-helpful choice screen explaining why you do a test run of hook rules.
Reviewers: chad
Reviewed By: chad
Maniphest Tasks: T9719
Differential Revision: https://secure.phabricator.com/D16360
2016-08-01 22:29:46 +02:00
|
|
|
public function isTestAdapterForObject($object) {
|
|
|
|
return ($object instanceof DifferentialRevision);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getAdapterTestDescription() {
|
|
|
|
return pht(
|
|
|
|
'Test rules which run when a revision is created or updated.');
|
|
|
|
}
|
|
|
|
|
2016-09-09 01:08:49 +02:00
|
|
|
public function newTestAdapter(PhabricatorUser $viewer, $object) {
|
Make Herald test workflow modular and more clear
Summary:
Fixes T9719. Currently, the Herald "Test Console" has a big `instanceof` thing, so new adapters (like a Calendar adapter, or third-party adapters) aren't available automatically. Instead, do a standard modular thing: load the available adapters, ask which ones can test the object the user selected, then let the user pick which one they want to move forward with.
Additionally, it isn't very clear that you can't test "commit hook" rules because they rely on push state which we don't really have a good way to simulate. When the user picks a commit, we now show them the "Hook" events, but the options are disabled and explain why they can not be selected.
Test Plan:
- Ran test rules for revisions, commits, mocks, tasks, wiki documents, questions, and outbound mail.
- Plugged in a commit, got a more-helpful choice screen explaining why you do a test run of hook rules.
Reviewers: chad
Reviewed By: chad
Maniphest Tasks: T9719
Differential Revision: https://secure.phabricator.com/D16360
2016-08-01 22:29:46 +02:00
|
|
|
return self::newLegacyAdapter(
|
|
|
|
$object,
|
|
|
|
$object->loadActiveDiff());
|
|
|
|
}
|
|
|
|
|
2015-07-06 22:15:47 +02:00
|
|
|
protected function initializeNewAdapter() {
|
|
|
|
$this->revision = $this->newObject();
|
|
|
|
}
|
|
|
|
|
2013-10-05 21:55:34 +02:00
|
|
|
public function getObject() {
|
|
|
|
return $this->revision;
|
|
|
|
}
|
|
|
|
|
2013-08-02 17:55:13 +02:00
|
|
|
public function getAdapterContentType() {
|
|
|
|
return 'differential';
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getAdapterContentName() {
|
|
|
|
return pht('Differential Revisions');
|
|
|
|
}
|
|
|
|
|
2013-12-27 22:16:33 +01:00
|
|
|
public function getAdapterContentDescription() {
|
|
|
|
return pht(
|
|
|
|
"React to revisions being created or updated.\n".
|
|
|
|
"Revision rules can send email, flag revisions, add reviewers, ".
|
|
|
|
"and run build plans.");
|
|
|
|
}
|
|
|
|
|
2013-12-31 01:48:07 +01:00
|
|
|
public function supportsRuleType($rule_type) {
|
|
|
|
switch ($rule_type) {
|
|
|
|
case HeraldRuleTypeConfig::RULE_TYPE_GLOBAL:
|
|
|
|
case HeraldRuleTypeConfig::RULE_TYPE_PERSONAL:
|
|
|
|
return true;
|
|
|
|
case HeraldRuleTypeConfig::RULE_TYPE_OBJECT:
|
|
|
|
default:
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-08-02 21:35:33 +02:00
|
|
|
public function getRepetitionOptions() {
|
|
|
|
return array(
|
|
|
|
HeraldRepetitionPolicyConfig::EVERY,
|
|
|
|
HeraldRepetitionPolicyConfig::FIRST,
|
|
|
|
);
|
|
|
|
}
|
2013-08-02 19:25:45 +02:00
|
|
|
|
2013-08-02 17:55:13 +02:00
|
|
|
public static function newLegacyAdapter(
|
2011-04-06 05:49:31 +02:00
|
|
|
DifferentialRevision $revision,
|
|
|
|
DifferentialDiff $diff) {
|
2013-08-02 17:55:13 +02:00
|
|
|
$object = new HeraldDifferentialRevisionAdapter();
|
|
|
|
|
2013-10-05 01:30:43 +02:00
|
|
|
// Reload the revision to pick up relationship information.
|
|
|
|
$revision = id(new DifferentialRevisionQuery())
|
|
|
|
->withIDs(array($revision->getID()))
|
|
|
|
->setViewer(PhabricatorUser::getOmnipotentUser())
|
2017-03-20 22:37:24 +01:00
|
|
|
->needReviewers(true)
|
2013-10-05 01:30:43 +02:00
|
|
|
->executeOne();
|
|
|
|
|
2013-08-02 17:55:13 +02:00
|
|
|
$object->revision = $revision;
|
2015-07-08 21:25:48 +02:00
|
|
|
$object->setDiff($diff);
|
2013-08-02 17:55:13 +02:00
|
|
|
|
|
|
|
return $object;
|
2011-03-25 05:32:26 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public function getHeraldName() {
|
|
|
|
return $this->revision->getTitle();
|
|
|
|
}
|
|
|
|
|
|
|
|
protected function loadChangesets() {
|
2011-04-06 05:49:31 +02:00
|
|
|
if ($this->changesets === null) {
|
2015-07-08 21:25:48 +02:00
|
|
|
$this->changesets = $this->getDiff()->loadChangesets();
|
2011-04-06 05:49:31 +02:00
|
|
|
}
|
|
|
|
return $this->changesets;
|
|
|
|
}
|
|
|
|
|
2014-08-20 23:26:29 +02:00
|
|
|
protected function loadChangesetsWithHunks() {
|
2014-04-14 21:06:26 +02:00
|
|
|
$changesets = $this->loadChangesets();
|
|
|
|
|
|
|
|
if ($changesets && !$this->haveHunks) {
|
|
|
|
$this->haveHunks = true;
|
|
|
|
|
|
|
|
id(new DifferentialHunkQuery())
|
|
|
|
->setViewer(PhabricatorUser::getOmnipotentUser())
|
|
|
|
->withChangesets($changesets)
|
|
|
|
->needAttachToChangesets(true)
|
|
|
|
->execute();
|
|
|
|
}
|
|
|
|
|
|
|
|
return $changesets;
|
|
|
|
}
|
|
|
|
|
2011-04-06 05:49:31 +02:00
|
|
|
public function loadAffectedPackages() {
|
|
|
|
if ($this->affectedPackages === null) {
|
|
|
|
$this->affectedPackages = array();
|
|
|
|
|
|
|
|
$repository = $this->loadRepository();
|
|
|
|
if ($repository) {
|
|
|
|
$packages = PhabricatorOwnersPackage::loadAffectedPackages(
|
|
|
|
$repository,
|
|
|
|
$this->loadAffectedPaths());
|
|
|
|
$this->affectedPackages = $packages;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return $this->affectedPackages;
|
|
|
|
}
|
|
|
|
|
2015-07-08 21:25:48 +02:00
|
|
|
public function loadReviewers() {
|
2017-03-20 23:04:23 +01:00
|
|
|
return $this->getObject()->getReviewerPHIDs();
|
2013-08-02 20:32:50 +02:00
|
|
|
}
|
|
|
|
|
2015-07-30 21:22:35 +02:00
|
|
|
|
|
|
|
/* -( HarbormasterBuildableAdapterInterface )------------------------------ */
|
|
|
|
|
|
|
|
|
|
|
|
public function getHarbormasterBuildablePHID() {
|
|
|
|
return $this->getDiff()->getPHID();
|
2011-03-25 05:32:26 +01:00
|
|
|
}
|
|
|
|
|
2015-07-30 21:22:35 +02:00
|
|
|
public function getHarbormasterContainerPHID() {
|
|
|
|
return $this->getObject()->getPHID();
|
|
|
|
}
|
|
|
|
|
2015-10-02 15:32:08 +02:00
|
|
|
public function getQueuedHarbormasterBuildRequests() {
|
|
|
|
return $this->buildRequests;
|
2015-07-30 21:22:35 +02:00
|
|
|
}
|
|
|
|
|
2015-10-02 15:32:08 +02:00
|
|
|
public function queueHarbormasterBuildRequest(
|
|
|
|
HarbormasterBuildRequest $request) {
|
|
|
|
$this->buildRequests[] = $request;
|
2011-03-25 05:32:26 +01:00
|
|
|
}
|
2014-07-23 02:03:09 +02:00
|
|
|
|
2011-03-25 05:32:26 +01:00
|
|
|
}
|