Skip to content

Commit 75e56cb

Browse files
author
epriestley
committed
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
1 parent 22d7b54 commit 75e56cb

File tree

4 files changed

+30
-22
lines changed

4 files changed

+30
-22
lines changed

src/applications/differential/doorkeeper/DifferentialDoorkeeperRevisionFeedStoryPublisher.php

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,23 +4,19 @@ final class DifferentialDoorkeeperRevisionFeedStoryPublisher
44
extends DoorkeeperFeedStoryPublisher {
55

66
public function canPublishStory(PhabricatorFeedStory $story, $object) {
7-
if (!($object instanceof DifferentialRevision)) {
8-
return false;
9-
}
7+
return ($object instanceof DifferentialRevision);
8+
}
109

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();
1412

1513
$action = $story->getStoryData()->getValue('action');
1614
switch ($action) {
1715
case DifferentialAction::ACTION_CREATE:
18-
return false;
16+
return true;
1917
default:
20-
break;
18+
return false;
2119
}
22-
23-
return true;
2420
}
2521

2622
public function willPublishStory($object) {

src/applications/diffusion/doorkeeper/DiffusionDoorkeeperCommitFeedStoryPublisher.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,13 @@ public function canPublishStory(PhabricatorFeedStory $story, $object) {
1515
return ($object instanceof PhabricatorRepositoryCommit);
1616
}
1717

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+
1825
public function willPublishStory($commit) {
1926
$requests = id(new PhabricatorAuditQuery())
2027
->withCommitPHIDs(array($commit->getPHID()))

src/applications/doorkeeper/engine/DoorkeeperFeedStoryPublisher.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ public function willPublishStory($object) {
3535
return $object;
3636
}
3737

38+
abstract public function isStoryAboutObjectCreation($object);
3839
abstract public function getOwnerPHID($object);
3940
abstract public function getActiveUserPHIDs($object);
4041
abstract public function getPassiveUserPHIDs($object);

src/applications/doorkeeper/worker/DoorkeeperFeedWorkerAsana.php

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -476,20 +476,24 @@ protected function doWork() {
476476

477477
$sub_editor->save();
478478

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.
479486

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.
487+
$text = $publisher->getStoryText($object);
483488

484-
$text = $publisher->getStoryText($object);
485-
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+
}
493497
}
494498

495499
private function lookupAsanaUserIDs($all_phids) {

0 commit comments

Comments
 (0)