getLatestActivities() public méthode

public getLatestActivities ( $type = Activity::ACTIVITY_TYPE_COMMIT )
Exemple #1
0
 public function updateCommits(Bundle $bundle)
 {
     $this->output->write(' commits');
     try {
         $commits = $this->github->api('repo')->commits()->all($bundle->getOwnerName(), $bundle->getName(), array('sha' => 'HEAD', 'per_page' => 30));
     } catch (RuntimeException $e) {
         return false;
     }
     $activities = $bundle->getLatestActivities();
     $lastEverCommitAt = $bundle->getLastCommitAt();
     /* @var $developer EntityDeveloper */
     foreach ($commits as $commit) {
         if (!isset($commit['commit']['committer'])) {
             continue;
         }
         $lastCommitAt = new \DateTime($commit['commit']['committer']['date']);
         $lastCommitAt->setTimezone(new \DateTimeZone(date_default_timezone_get()));
         $activityData = array('type' => Activity::ACTIVITY_TYPE_COMMIT, 'message' => strtok($commit['commit']['message'], "\n\r"), 'createdAt' => $lastCommitAt);
         if (!empty($activities)) {
             foreach ($activities as $registeredActivity) {
                 if ($registeredActivity->getMessage() === $activityData['message'] && $registeredActivity->getCreatedAt() == $activityData['createdAt']) {
                     continue 2;
                 }
             }
         }
         // be sure that bundle have a latest date following to latest commit
         if ($lastCommitAt > $lastEverCommitAt) {
             $lastEverCommitAt = $lastCommitAt;
         }
         $activity = new Activity();
         $activity->setType($activityData['type']);
         $activity->setMessage($activityData['message']);
         $activity->setCreatedAt($activityData['createdAt']);
         $activity->setBundle($bundle);
         if (isset($commit['committer']) && isset($commit['committer']['login'])) {
             $developer = $this->ownerManager->createOwner($commit['committer']['login'], 'developer', true);
             $developer->setLastCommitAt($lastCommitAt);
             $activity->setDeveloper($developer);
         } else {
             $activity->setAuthor($commit['commit']['committer']['name']);
         }
     }
     // update last pushed commit date
     $bundle->setLastCommitAt(clone $lastEverCommitAt);
     if ('developer' === $bundle->getOwnerType()) {
         $bundle->getOwner()->setLastCommitAt(clone $lastEverCommitAt);
     }
     unset($activities);
     return true;
 }