Пример #1
0
 /**
  * Factory method to be implemented from \RedmineCommand\AbstractCommand .
  *
  *
  * Must return an instance of \RedmineCommand\SlackResult .
  *
  * @see \RedmineCommand\AbstractCommand::executeImpl()
  * @return \RedmineCommand\SlackResult
  */
 protected function executeImpl()
 {
     $log = $this->log;
     $result = new SlackResult();
     $log->debug("CmdShow: Issues Id: " . implode(",", $this->cmd));
     $client = new Client($this->config->redmine_url, $this->config->redmine_api_key);
     $resultText = "[requested by " . $this->post["user_name"] . "]";
     if (empty($this->cmd)) {
         $resultText .= " Issue number required!";
     } else {
         $resultText .= " Issue Details: ";
     }
     // Fetching issues and adding them as slack attachments
     $attachments = array();
     $attachmentUnknown = null;
     foreach ($this->cmd as $issueId) {
         $log->debug("CmdShow: calling Redmine api for issue id #{$issueId}");
         $issue = $client->api('issue')->show((int) $issueId);
         $attachment = new SlackResultAttachment();
         if (!is_array($issue)) {
             if (strcmp($issue, "Syntax error") == 0) {
                 if ($attachmentUnknown == null) {
                     $attachmentUnknown = new SlackResultAttachment();
                     $attachmentUnknown->setTitle("Unknown Issues:");
                     $attachmentUnknown->setText("");
                 }
                 $log->debug("CmdShow: #{$issueId} issue unknown!");
                 $attachmentUnknown->setText($attachmentUnknown->getText() . " {$issueId}");
             }
         } else {
             $log->debug("CmdShow: #{$issueId} issue found!");
             $attachment = Util::convertIssueToAttachment($this->config->getRedmineIssuesUrl(), $issueId, $issue);
             $attachments[] = $attachment;
         }
     }
     $result->setText($resultText);
     if ($attachmentUnknown != null) {
         $attachments[] = $attachmentUnknown;
     }
     $result->setAttachmentsArray($attachments);
     return $result;
 }
Пример #2
0
 /**
  * Converts an array representation of an issue (as returned by the php-redmine-api) to an
  * instance of SlackResultAttachment to be used in messages sent to a slack incoming webhook.
  *
  * @param string $redmine_issues_url        	
  * @param string $issue_id        	
  * @param array $issue        	
  * @return \RedmineCommand\SlackResultAttachment
  * @see \RedmineCommand\SlackResultAttachment
  * @link https://github.com/kbsali/php-redmine-api
  */
 public static function convertIssueToAttachment($redmine_issues_url, $issue_id, $issue)
 {
     $attachment = new SlackResultAttachment();
     $attachment->setTitle("#" . $issue_id . " " . $issue['issue']['subject']);
     $attTitle = "[<" . $redmine_issues_url . $issue_id . "|" . $issue['issue']['tracker']['name'] . " #" . $issue_id . ">]";
     $attachment->setPretext($attTitle);
     $attachment->setTitle($issue['issue']['subject']);
     $attachment->setText($issue["issue"]["description"]);
     $fixed_version = "None";
     if (isset($issue["issue"]["fixed_version"]["name"])) {
         $fixed_version = $issue["issue"]["fixed_version"]["name"];
     }
     $estimated_hours = "None";
     if (isset($issue["issue"]["estimated_hours"])) {
         $estimated_hours = $issue["issue"]["estimated_hours"];
     }
     $assigned_to = "None";
     if (isset($issue["issue"]["assigned_to"]["name"])) {
         $assigned_to = $issue["issue"]["assigned_to"]["name"];
     }
     $fields = array();
     $fields[] = self::createField("Project", $issue["issue"]["project"]["name"]);
     $fields[] = self::createField("Version", $fixed_version);
     $fields[] = self::createField("Status", $issue["issue"]["status"]["name"]);
     $fields[] = self::createField("Priority", $issue["issue"]["priority"]["name"]);
     $fields[] = self::createField("Assigned To", $assigned_to);
     $fields[] = self::createField("Author", $issue["issue"]["author"]["name"]);
     $fields[] = self::createField("Start Date", $issue["issue"]["start_date"]);
     $fields[] = self::createField("Estimated Hours", $estimated_hours);
     $fields[] = self::createField("Done Ratio", $issue["issue"]["done_ratio"] . "%");
     $fields[] = self::createField("Spent Hours", $issue["issue"]["spent_hours"]);
     $fields[] = self::createField("Created On", $issue["issue"]["created_on"]);
     $fields[] = self::createField("Updated On", $issue["issue"]["updated_on"]);
     $attachment->setFieldsArray($fields);
     return $attachment;
 }