Example #1
0
 public function run($arguments, CLImaxController $cliController)
 {
     // Set up options for search
     $config = GitPlanbox_Config::get();
     $statuses = array('completed', 'delivered', 'accepted');
     $opts = array('productid' => $config->productid(), 'timeframe' => $timeframe, 'status' => $statuses);
     // Pull in timeframe(s) if they've been specified
     if (isset($arguments[0])) {
         $opts['timeframe'] = explode(',', $arguments[0]);
     } else {
         $opts['timeframe'] = array('last', 'current', 'next');
     }
     // Create a session so we can run commands
     $session = GitPlanbox_Session::create();
     // Get a list of stories
     $stories = GitPlanbox_Search::search($session, $opts);
     if (count($stories) == 0) {
         print "There are no stories in status: " . implode(', ', $statuses) . ".\n";
         return 0;
     }
     // Format stories nicely
     print "Stories that are ready for release:\n";
     foreach ($stories as $story) {
         printf("%8s %10s - %-50s\n", "#{$story->id}", $story->status, $story->name);
     }
     print "\nHint: use `git-planbox status <storyId>` to find out what branch the story is on.\n\n";
     return 0;
 }
Example #2
0
 private function _doPost($path, $postData = array())
 {
     // Run the post
     $curl = curl_init();
     $url = GitPlanbox_Config::generateUrlForPath($path);
     $postString = http_build_query($postData);
     $cookieFile = $this->_cookieFile();
     curl_setopt($curl, CURLOPT_URL, $url);
     curl_setopt($curl, CURLOPT_HEADER, false);
     curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
     curl_setopt($curl, CURLOPT_POST, count($postData));
     curl_setopt($curl, CURLOPT_POSTFIELDS, $postString);
     curl_setopt($curl, CURLOPT_COOKIEFILE, $cookieFile);
     curl_setopt($curl, CURLOPT_COOKIEJAR, $cookieFile);
     $responseText = curl_exec($curl);
     // Get the results
     $httpCode = curl_getinfo($curl, CURLINFO_HTTP_CODE);
     $responseData = json_decode($responseText);
     // Close cURL
     curl_close($curl);
     // Handle errors
     if ($httpCode >= 400 && $httpCode) {
         $e = new GitPlanbox_HttpErrorException("Error posting to {$path}");
         $e->httpCode = $httpCode;
         throw $e;
     }
     if ($responseData->code != 'ok') {
         throw new GitPlanbox_ApplicationErrorException("Error fetching data");
     }
     return $responseData->content;
 }
Example #3
0
 public function run($arguments, CLImaxController $cliController)
 {
     // Pull in iterations if they've been specified, otherwise
     // use current as default
     $timeframe = 'current';
     if (isset($arguments[0])) {
         $timeframe = explode(',', $arguments[0]);
     }
     // Create a session so we can run commands
     $session = GitPlanbox_Session::create();
     // Get a list of stories
     $config = GitPlanbox_Config::get();
     $postData = array('product_id' => $config->productid(), 'timeframe' => $timeframe);
     if ($config->resourceid()) {
         $postData['resource_id'] = array($config->resourceid());
     }
     // Restrict list to the current user if they have specified a planbox.resourceid in gitconfig
     $stories = $session->post('get_stories', $postData);
     // Format stories nicely
     $skippedStoriesByStatus = array();
     foreach ($stories as $story) {
         // Skip stories that are done
         $statusesToSkip = array('completed', 'delivered', 'accepted', 'rejected', 'released', 'blocked');
         if (in_array($story->status, $statusesToSkip)) {
             if (!isset($skippedStoriesByStatus[$story->status])) {
                 $skippedStoriesByStatus[$story->status] = 0;
             }
             $skippedStoriesByStatus[$story->status]++;
             continue;
         }
         printf("%8s %9s %10s - %-50s\n", "#{$story->id}", $story->type, $story->status, $story->name);
     }
     if (!empty($skippedStoriesByStatus)) {
         $skippedStoryStatuses = array();
         foreach ($skippedStoriesByStatus as $status => $numSkipped) {
             array_push($skippedStoryStatuses, "{$numSkipped} {$status}");
         }
         print "...plus " . implode(', ', $skippedStoryStatuses) . " tasks that are not displayed.\n";
     }
     return 0;
 }
Example #4
0
 private function _startTimerForTask($session, $story, $taskId)
 {
     if (!$story) {
         throw new Exception("Expected story, got " . var_export($story, true));
     }
     if (!$taskId) {
         throw new Exception("Expected taskId, got " . var_export($taskId, true));
     }
     // Find the task
     $task = NULL;
     foreach ($story->tasks as $t) {
         if ($t->id == $taskId) {
             $task = $t;
             break;
         }
     }
     if (!$task) {
         throw new Exception("Couldn't find that task with id: " . var_export($taskId, true));
     }
     $postData = array('story_id' => $story->id, 'task_id' => $taskId, 'status' => 'inprogress');
     // If the task is unassigned, assign it to the current user
     if ($task->resource_id === NULL) {
         $postData['resource_id'] = GitPlanbox_Config::resourceid();
     }
     $session->post('update_task', $postData);
     print "Started timer for story #{$story->id}, task #{$taskId}.\n";
 }