Esempio n. 1
0
 public static function createFromEvent(PushReferenceEvent $event, Feed $feed)
 {
     $user = $event->getUser();
     $reference = $event->getReference();
     $defaultBranch = $event->getProject()->getDefaultBranch();
     if ($reference->isDelete()) {
         return new CloseMessage($feed, $user);
     }
     $message = new CommitMessage($feed, $user);
     $message->setForce($reference->isForce());
     if ($reference->isCreate() && $event->getReference()->getReference() === 'refs/heads/' . $defaultBranch) {
         $revision = $reference->getRevision();
         $log = $reference->getLog();
     } elseif ($reference->isCreate() && $reference->getRepository()->getReferences()->hasBranch($defaultBranch)) {
         $mergeBase = trim($reference->getRepository()->run('merge-base', array($defaultBranch, $reference->getAfter())));
         $revision = $mergeBase . '..' . $reference->getAfter();
         $log = $reference->getRepository()->getLog($revision);
     } else {
         $revision = $reference->getRevision();
         $log = $reference->getLog();
     }
     if (count($log) == 0) {
         return;
     }
     $message->setRevision($revision);
     $message->fromLog($log);
     return $message;
 }
Esempio n. 2
0
 protected function getFeed(PushReferenceEvent $event)
 {
     $em = $this->registry->getManager();
     $repo = $em->getRepository('GitonomyCoreBundle:Feed');
     $project = $event->getProject();
     $reference = $event->getReference()->getReference();
     return $repo->findOneOrCreate($project, $reference);
 }