@recaptime-dev's working patches + fork for Phorge, a community fork of Phabricator. (Upstream dev and stable branches are at upstream/main and upstream/stable respectively.) hq.recaptime.dev/wiki/Phorge
phorge phabricator
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

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

+30 -22
+6 -10
src/applications/differential/doorkeeper/DifferentialDoorkeeperRevisionFeedStoryPublisher.php
··· 4 4 extends DoorkeeperFeedStoryPublisher { 5 5 6 6 public function canPublishStory(PhabricatorFeedStory $story, $object) { 7 - if (!($object instanceof DifferentialRevision)) { 8 - return false; 9 - } 7 + return ($object instanceof DifferentialRevision); 8 + } 10 9 11 - // Don't publish the "create" story, since pushing the object into Asana 12 - // naturally generates a notification which effectively serves the same 13 - // purpose as the "create" story. 10 + public function isStoryAboutObjectCreation($object) { 11 + $story = $this->getFeedStory(); 14 12 15 13 $action = $story->getStoryData()->getValue('action'); 16 14 switch ($action) { 17 15 case DifferentialAction::ACTION_CREATE: 18 - return false; 16 + return true; 19 17 default: 20 - break; 18 + return false; 21 19 } 22 - 23 - return true; 24 20 } 25 21 26 22 public function willPublishStory($object) {
+7
src/applications/diffusion/doorkeeper/DiffusionDoorkeeperCommitFeedStoryPublisher.php
··· 15 15 return ($object instanceof PhabricatorRepositoryCommit); 16 16 } 17 17 18 + public function isStoryAboutObjectCreation($object) { 19 + // TODO: Although creation stories exist, they currently don't have a 20 + // primary object PHID set, so they'll never make it here because they 21 + // won't pass `canPublishStory()`. 22 + return false; 23 + } 24 + 18 25 public function willPublishStory($commit) { 19 26 $requests = id(new PhabricatorAuditQuery()) 20 27 ->withCommitPHIDs(array($commit->getPHID()))
+1
src/applications/doorkeeper/engine/DoorkeeperFeedStoryPublisher.php
··· 35 35 return $object; 36 36 } 37 37 38 + abstract public function isStoryAboutObjectCreation($object); 38 39 abstract public function getOwnerPHID($object); 39 40 abstract public function getActiveUserPHIDs($object); 40 41 abstract public function getPassiveUserPHIDs($object);
+16 -12
src/applications/doorkeeper/worker/DoorkeeperFeedWorkerAsana.php
··· 476 476 477 477 $sub_editor->save(); 478 478 479 - 480 - // Post the feed story itself to the main Asana task. We do this last 481 - // because everything else is idempotent, so this is the only effect we 482 - // can't safely run more than once. 479 + // Don't publish the "create" story, since pushing the object into Asana 480 + // naturally generates a notification which effectively serves the same 481 + // purpose as the "create" story. 482 + if (!$publisher->isStoryAboutObjectCreation($object)) { 483 + // Post the feed story itself to the main Asana task. We do this last 484 + // because everything else is idempotent, so this is the only effect we 485 + // can't safely run more than once. 483 486 484 - $text = $publisher->getStoryText($object); 487 + $text = $publisher->getStoryText($object); 485 488 486 - $this->makeAsanaAPICall( 487 - $oauth_token, 488 - 'tasks/'.$parent_ref->getObjectID().'/stories', 489 - 'POST', 490 - array( 491 - 'text' => $text, 492 - )); 489 + $this->makeAsanaAPICall( 490 + $oauth_token, 491 + 'tasks/'.$parent_ref->getObjectID().'/stories', 492 + 'POST', 493 + array( 494 + 'text' => $text, 495 + )); 496 + } 493 497 } 494 498 495 499 private function lookupAsanaUserIDs($all_phids) {