Page MenuHomePhabricator

D10074.id.diff
No OneTemporary

D10074.id.diff

Index: src/__phutil_library_map__.php
===================================================================
--- src/__phutil_library_map__.php
+++ src/__phutil_library_map__.php
@@ -1516,6 +1516,7 @@
'PhabricatorFeedStory' => 'applications/feed/story/PhabricatorFeedStory.php',
'PhabricatorFeedStoryAggregate' => 'applications/feed/story/PhabricatorFeedStoryAggregate.php',
'PhabricatorFeedStoryAudit' => 'applications/feed/story/PhabricatorFeedStoryAudit.php',
+ 'PhabricatorFeedStoryBuildResult' => 'applications/feed/story/PhabricatorFeedStoryBuildResult.php',
'PhabricatorFeedStoryCommit' => 'applications/feed/story/PhabricatorFeedStoryCommit.php',
'PhabricatorFeedStoryData' => 'applications/feed/storage/PhabricatorFeedStoryData.php',
'PhabricatorFeedStoryDifferential' => 'applications/feed/story/PhabricatorFeedStoryDifferential.php',
@@ -4326,6 +4327,7 @@
'PhabricatorFeedStory' => 'PhabricatorPolicyInterface',
'PhabricatorFeedStoryAggregate' => 'PhabricatorFeedStory',
'PhabricatorFeedStoryAudit' => 'PhabricatorFeedStory',
+ 'PhabricatorFeedStoryBuildResult' => 'PhabricatorFeedStory',
'PhabricatorFeedStoryCommit' => 'PhabricatorFeedStory',
'PhabricatorFeedStoryData' => 'PhabricatorFeedDAO',
'PhabricatorFeedStoryDifferential' => 'PhabricatorFeedStory',
Index: src/applications/feed/constants/PhabricatorFeedStoryTypeConstants.php
===================================================================
--- src/applications/feed/constants/PhabricatorFeedStoryTypeConstants.php
+++ src/applications/feed/constants/PhabricatorFeedStoryTypeConstants.php
@@ -6,5 +6,6 @@
const STORY_PHRICTION = 'PhabricatorFeedStoryPhriction';
const STORY_AUDIT = 'PhabricatorFeedStoryAudit';
const STORY_COMMIT = 'PhabricatorFeedStoryCommit';
+ const STORY_BUILD = 'PhabricatorFeedStoryBuildResult';
}
Index: src/applications/feed/story/PhabricatorFeedStory.php
===================================================================
--- src/applications/feed/story/PhabricatorFeedStory.php
+++ src/applications/feed/story/PhabricatorFeedStory.php
@@ -293,6 +293,20 @@
$handle->getLinkName());
}
+ final protected function linkToExternal($text, $uri, $style) {
+ return javelin_tag(
+ 'a',
+ array(
+ 'href' => $uri,
+ 'style' => $style,
+ 'target' => $this->framed ? '_top' : null,
+ 'sigil' => null,
+ 'meta' => null,
+ 'class' => null,
+ ),
+ $text);
+ }
+
final protected function renderString($str) {
switch ($this->getRenderingTarget()) {
case PhabricatorApplicationTransaction::TARGET_TEXT:
Index: src/applications/feed/story/PhabricatorFeedStoryBuildResult.php
===================================================================
--- /dev/null
+++ src/applications/feed/story/PhabricatorFeedStoryBuildResult.php
@@ -0,0 +1,88 @@
+<?php
+
+/**
+ * This is a feed story for build results.
+ * Expected story data elements are:
+ * - commitPHID: The Phabricator ID of the commit that triggered the build
+ * - buildStatus: The event for this story, one of: SUCCESS, FAILURE, UNSTABLE, BACK_NORMAL
+ * - buildURI: The external URI to the build page on a continuous integration service
+ * - buildName: The human-readable build name on a continuous integration service
+ * - summary: Custom text to display in the story, may be the commit's summary
+ *
+ * @author Laurent Wouters <laurent.wouters@cea.fr>
+ */
+
+final class PhabricatorFeedStoryBuildResult extends PhabricatorFeedStory {
+
+ public function getPrimaryObjectPHID() {
+ return $this->getValue('commitPHID');
+ }
+
+ private function getBuildColor($status) {
+ if ($status == "SUCCESS" or $status == "BACK_NORMAL") {
+ return "darkgreen";
+ } elseif ($status == "FAILURE") {
+ return "darkred";
+ } elseif ($status == "UNSTABLE") {
+ return "orange";
+ } else {
+ return "black";
+ }
+ }
+
+ private function getStoryMask($status) {
+ if ($status == "SUCCESS") {
+ return 'Build %s succeeded on commit %s';
+ } elseif ($status == "BACK_NORMAL") {
+ return 'Build %s is back to normal on %s';
+ } elseif ($status == "FAILURE") {
+ return 'Build %s failed on commit %s';
+ } elseif ($status == "UNSTABLE") {
+ return 'Build %s is unstable on commit %s';
+ } else {
+ return 'Build %s has been executed on commit %s';
+ }
+ }
+
+ public function renderView() {
+ $data = $this->getStoryData();
+
+ $build_uri = $data->getValue('buildURI');
+ $build_name = $data->getValue('buildName');
+ $build_status = $data->getValue('buildStatus');
+ $build = $this->linkToExternal($build_name, $build_uri, "color:" . $this->getBuildColor($build_status));
+
+ $commit = $this->linkTo($data->getValue('commitPHID'));
+
+ $title = pht(
+ $this->getStoryMask($build_status),
+ $build,
+ $commit);
+
+ $view = $this->newStoryView();
+ $view->setAppIcon('harbormaster-dark');
+
+ $view->setTitle($title);
+ $view->setImage($this->getHandle($data->getAuthorPHID())->getImageURI());
+
+ $content = $this->renderSummary($data->getValue('summary'));
+ $view->appendChild($content);
+
+ return $view;
+ }
+
+ public function renderText() {
+ $data = $this->getStoryData();
+
+ $build_name = $data->getValue('buildName');
+ $build_status = $data->getValue('buildStatus');
+
+ $commit_handle = $this->getHandle($this->getPrimaryObjectPHID());
+ $commit_name = $commit_handle->getLinkName();
+
+ return pht(
+ $this->getStoryMask($build_status),
+ $build_name,
+ $commit_name);
+ }
+}

File Metadata

Mime Type
text/plain
Expires
Wed, Jan 22, 12:05 PM (8 h, 44 m)
Storage Engine
blob
Storage Format
Encrypted (AES-256-CBC)
Storage Handle
7032767
Default Alt Text
D10074.id.diff (5 KB)

Event Timeline