Пример #1
0
 function import()
 {
     $projectId = $_REQUEST['project'];
     $stories = collection(Json::decode($_REQUEST['stories']));
     // Synchronize epics
     $epics = array_unique($stories->select('epic')->toArray());
     $existingEpics = $this->jira->query('project=' . $projectId . ' AND issuetype="Epic"', self::EPIC_NAME);
     $epicKeys = [];
     foreach ($existingEpics as $issue) {
         $epicKeys[$issue->fields->{self::EPIC_NAME}] = $issue->key;
         $foundIndex = array_search($issue->fields->{self::EPIC_NAME}, $epics);
         if ($foundIndex !== false) {
             unset($epics[$foundIndex]);
         }
     }
     foreach ($epics as $epic) {
         $result = $this->jira->post('issue', ["fields" => ["project" => ['id' => $projectId], "issuetype" => ["name" => "Epic"], "summary" => $epic, self::EPIC_NAME => $epic]]);
         $epicKeys[$epic] = $result->key;
     }
     // Create stories
     foreach ($stories as $story) {
         $result = $this->jira->post('issue', ["fields" => ["project" => ['id' => $projectId], "summary" => $story->summary, "issuetype" => ["name" => "Story"], self::EPIC_LINK => $epicKeys[$story->epic], self::POINTS => $story->points]]);
     }
     return new Dump($stories->count() . ' stories created');
 }
Пример #2
0
 public function compare($old, $new)
 {
     $diff = ['added' => array_diff_key($new, $old), 'removed' => array_diff_key($old, $new), 'changes' => [], 'values' => []];
     $format = JSON_PRETTY_PRINT ^ \JSON_UNESCAPED_SLASHES;
     foreach ($old as $key => $oldValue) {
         if (array_key_exists($key, $new) === false) {
             continue;
             // skip newly added
         }
         $oldString = Json::encode($oldValue, $format);
         $newString = Json::encode($new[$key], $format);
         if ($oldString !== $newString) {
             $diff['changes'][$key] = new ColorDiff($oldString, $newString);
             $diff['values'][$key] = $newString;
         }
     }
     return $diff;
 }
Пример #3
0
                <th width="12%">Option changed</th>
                <th width="44%" style="min-width: 250px">New Value</th>
                <th width="44%">Diff</th>
            </tr>
            </thead>
            <tbody>
            <?php 
    foreach ($changes as $key => $change) {
        ?>
                <tr>
                    <td style="white-space: nowrap"><?php 
        echo Html::escape($key);
        ?>
</td>
                    <td style="max-width: 44vw"><?php 
        $value = Json::decode($values[$key], true);
        ob_start();
        dump($value);
        $html = ob_get_clean();
        echo substr($html, strpos($html, '</div>') + 6);
        ?>
</td>
                    <td style="max-width: 44vw"><?php 
        render($change);
        ?>
</td>
                </tr>
            <?php 
    }
    ?>
            </tbody>
Пример #4
0
 /**
  * Render the $data as jsonp.
  */
 public function render()
 {
     echo $this->callback, '(';
     parent::render();
     echo ');';
 }
Пример #5
0
 /**
  * Perform the Api call
  *
  * @param type $options
  * @return type
  * @throws Exception
  */
 function api($options = [])
 {
     $start = microtime(true);
     $options[CURLOPT_USERNAME] = $this->username;
     $options[CURLOPT_PASSWORD] = $this->password;
     $options[CURLOPT_FAILONERROR] = false;
     $options[CURLOPT_RETURNTRANSFER] = true;
     $options += Curl::$defaults;
     $response = new Curl($options);
     $body = $response->getBody();
     $this->logger->append($options[CURLOPT_URL], ['relativeUrl' => substr($options[CURLOPT_URL], strlen($this->baseUrl)), 'duration' => microtime(true) - $start]);
     if (in_array($response->http_code, [200, 201])) {
         return Json::decode($body);
     }
     if (substr($body, 0, 1) === '{') {
         // looks like json?
         $json = json_decode($body);
         if (is_object($json) && isset($json->errorMessages) && count($json->errorMessages) > 0) {
             throw new Exception('[Jira] ' . $json->errorMessages[0]);
         }
         if (is_object($json) && isset($json->errors) && is_object($json->errors)) {
             throw new Exception('[Jira] ' . current(get_object_vars($json->errors)));
         }
     }
     throw new Exception('[Jira] ' . $response->http_code . ' ' . $options[CURLOPT_URL]);
 }
Пример #6
0
 /**
  * Send an message to console.error().
  *
  * @param string $message The error message
  */
 public static function error($message)
 {
     return self::send('error', Json::encode($message));
 }