1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-09-20 09:18:48 +02:00

Publish create object stories into Asana sort of, but not really

Summary: Ref T2852. Current code works fine, but although we want to drop creation stories, we really only want to drop the story text, not the other effects of the creation story. Also generalize this mechanism so we don't have Asana-specific code in the publishers.

Test Plan: Used `bin/feed republish` to publish creation and non-creation stories. Verified creation story published no text.

Reviewers: btrahan

Reviewed By: btrahan

CC: aran

Maniphest Tasks: T2852

Differential Revision: https://secure.phabricator.com/D6639
This commit is contained in:
epriestley 2013-08-01 12:19:18 -07:00
parent 22d7b54378
commit 75e56cb25d
4 changed files with 30 additions and 22 deletions

View file

@ -4,23 +4,19 @@ final class DifferentialDoorkeeperRevisionFeedStoryPublisher
extends DoorkeeperFeedStoryPublisher { extends DoorkeeperFeedStoryPublisher {
public function canPublishStory(PhabricatorFeedStory $story, $object) { public function canPublishStory(PhabricatorFeedStory $story, $object) {
if (!($object instanceof DifferentialRevision)) { return ($object instanceof DifferentialRevision);
return false; }
}
// Don't publish the "create" story, since pushing the object into Asana public function isStoryAboutObjectCreation($object) {
// naturally generates a notification which effectively serves the same $story = $this->getFeedStory();
// purpose as the "create" story.
$action = $story->getStoryData()->getValue('action'); $action = $story->getStoryData()->getValue('action');
switch ($action) { switch ($action) {
case DifferentialAction::ACTION_CREATE: case DifferentialAction::ACTION_CREATE:
return false; return true;
default: default:
break; return false;
} }
return true;
} }
public function willPublishStory($object) { public function willPublishStory($object) {

View file

@ -15,6 +15,13 @@ final class DiffusionDoorkeeperCommitFeedStoryPublisher
return ($object instanceof PhabricatorRepositoryCommit); return ($object instanceof PhabricatorRepositoryCommit);
} }
public function isStoryAboutObjectCreation($object) {
// TODO: Although creation stories exist, they currently don't have a
// primary object PHID set, so they'll never make it here because they
// won't pass `canPublishStory()`.
return false;
}
public function willPublishStory($commit) { public function willPublishStory($commit) {
$requests = id(new PhabricatorAuditQuery()) $requests = id(new PhabricatorAuditQuery())
->withCommitPHIDs(array($commit->getPHID())) ->withCommitPHIDs(array($commit->getPHID()))

View file

@ -35,6 +35,7 @@ abstract class DoorkeeperFeedStoryPublisher {
return $object; return $object;
} }
abstract public function isStoryAboutObjectCreation($object);
abstract public function getOwnerPHID($object); abstract public function getOwnerPHID($object);
abstract public function getActiveUserPHIDs($object); abstract public function getActiveUserPHIDs($object);
abstract public function getPassiveUserPHIDs($object); abstract public function getPassiveUserPHIDs($object);

View file

@ -476,20 +476,24 @@ final class DoorkeeperFeedWorkerAsana extends FeedPushWorker {
$sub_editor->save(); $sub_editor->save();
// Don't publish the "create" story, since pushing the object into Asana
// naturally generates a notification which effectively serves the same
// purpose as the "create" story.
if (!$publisher->isStoryAboutObjectCreation($object)) {
// Post the feed story itself to the main Asana task. We do this last
// because everything else is idempotent, so this is the only effect we
// can't safely run more than once.
// Post the feed story itself to the main Asana task. We do this last $text = $publisher->getStoryText($object);
// because everything else is idempotent, so this is the only effect we
// can't safely run more than once.
$text = $publisher->getStoryText($object); $this->makeAsanaAPICall(
$oauth_token,
$this->makeAsanaAPICall( 'tasks/'.$parent_ref->getObjectID().'/stories',
$oauth_token, 'POST',
'tasks/'.$parent_ref->getObjectID().'/stories', array(
'POST', 'text' => $text,
array( ));
'text' => $text, }
));
} }
private function lookupAsanaUserIDs($all_phids) { private function lookupAsanaUserIDs($all_phids) {