/** * @param Bundle $bundle * @param Developer $developer */ public function manageBundleRecommendation(Bundle $bundle, Developer $developer) { if ($developer->isUsingBundle($bundle)) { $activity = $this->entityManager->getRepository('Knp\\Bundle\\KnpBundlesBundle\\Entity\\Activity')->findOneBy(array('type' => Activity::ACTIVITY_TYPE_RECOMMEND, 'bundle' => $bundle, 'developer' => $developer)); if ($activity) { $this->entityManager->remove($activity); } $bundle->removeRecommender($developer); } else { $activity = new Activity(); $activity->setType(Activity::ACTIVITY_TYPE_RECOMMEND); $activity->setBundle($bundle); $activity->setDeveloper($developer); $this->entityManager->persist($activity); $bundle->addRecommender($developer); } $this->entityManager->persist($bundle); $this->entityManager->flush(); }
/** * @return boolean|Bundle */ public function tweet() { /* @var $trendingBundle Bundle*/ if (!($trendingBundle = $this->em->getRepository('KnpBundlesBundle:Bundle')->findLatestTrend($this->twitterParams['idle_period']))) { throw new TrendingBundleNotFoundException(); } $timestamp = time(); $parameters = array('oauth_consumer_key' => $this->twitterParams['oauth_client_id'], 'oauth_timestamp' => $timestamp, 'oauth_nonce' => md5(microtime() . mt_rand()), 'oauth_version' => '1.0', 'oauth_signature_method' => 'HMAC-SHA1', 'oauth_token' => $this->twitterParams['oauth_token']); $parameters['oauth_signature'] = OAuthUtils::signRequest('POST', $this->twitterApiUrl, $parameters, $this->twitterParams['oauth_client_secret'], $this->twitterParams['oauth_token_secret']); $response = $this->httpRequest($this->twitterApiUrl, $this->prepareMessage($trendingBundle), $parameters, array(), 'POST'); if ($response->isSuccessful()) { $trendingBundle->setLastTweetedAt(new \DateTime()); $this->em->persist($trendingBundle); $activity = new Activity(); $activity->setType(Activity::ACTIVITY_TYPE_TWEETED); $activity->setCreatedAt(new \DateTime()); $activity->setBundle($trendingBundle); $this->em->persist($activity); $this->em->flush(); return $trendingBundle; } return false; }
/** * Updates repo based on status from travis. * * @param Bundle $bundle * * @return boolean */ public function update(Bundle $bundle) { $this->output->write(' Travis status:'); $response = $this->browser->get('http://travis-ci.org/' . $bundle->getOwnerName() . '/' . $bundle->getName() . '.json'); $status = json_decode($response->getContent(), true); if (JSON_ERROR_NONE === json_last_error()) { $lastBuildAt = new \DateTime(); $lastBuildAt->setTimestamp(strtotime($status['last_build_finished_at'])); // Only execute if date of last build is older than last update of bundle if ($lastBuildAt < $bundle->getUpdatedAt()) { $state = Activity::STATE_UNKNOWN; if (0 === $status['last_build_status']) { $bundle->setTravisCiBuildStatus(true); $state = Activity::STATE_OPEN; $this->output->write(' success'); } elseif (1 === $status['last_build_status']) { $bundle->setTravisCiBuildStatus(false); $state = Activity::STATE_CLOSED; $this->output->write(' failed'); } if (Activity::STATE_UNKNOWN !== $state) { $activity = new Activity(); $activity->setType(Activity::ACTIVITY_TYPE_TRAVIS_BUILD); $activity->setState($state); $activity->setBundle($bundle); return true; } } else { $this->output->write(' skipped'); return true; } } $bundle->setTravisCiBuildStatus(null); $this->output->write(' error'); return false; }
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; }
protected function makeBundle($manager, Entity\Owner $owner, $i, $contributor = null) { $trilean = array(true, false, null); $bundle = new Entity\Bundle(); $bundle->fromArray(array('name' => ucfirst($owner->getName()) . $i . 'FooBundle', 'description' => $this->descriptions[mt_rand(0, 4)], 'homepage' => $i % 2 ? 'Bundle' . $i . '.com' : null, 'readme' => str_replace('__BUNDLE__', "the bundle number: {$i}", $this->readme), 'usesTravisCi' => $i % 2 ? false : true, 'composerName' => $i % 2 ? null : 'knplabs/knp-menu-bundle', 'versionsHistory' => array('symfony' => array('dev-master' => '2.1.*', '1.2.0' => '2.0.*', '1.1.0' => '2.*'), 'dependencies' => array('dev-master' => array('name' => 'friendsofsymfony/user-bundle', 'extra' => array('branch-alias' => array('dev-master' => '2.0.x-dev')), 'require' => array('php' => '>=5.3.2', 'symfony/framework-bundle' => '>=2.1,<2.3-dev', 'symfony/security-bundle' => '>=2.1,<2.3-dev'), 'require-dev' => array('twig/twig' => '*', 'doctrine/doctrine-bundle' => '*', 'swiftmailer/swiftmailer' => '*', 'willdurand/propel-typehintable-behavior' => 'dev-master', 'symfony/validator' => '2.1.*', 'symfony/yaml' => '2.1.*'), 'suggest' => array('doctrine/couchdb-odm-bundle' => '*', 'doctrine/doctrine-bundle' => '*', 'doctrine/mongodb-odm-bundle' => '*')), '1.2.x-dev' => array('name' => 'friendsofsymfony/user-bundle', 'require' => array('php' => '>=5.3.2', 'symfony/framework-bundle' => '>=2.1,<2.3-dev', 'symfony/security-bundle' => '>=2.1,<2.3-dev'), 'require-dev' => '', 'suggest' => ''))), 'state' => $this->states[mt_rand(0, 3)], 'license' => $i % 4 == 0 ? 'Some pseudo license data' : null, 'licenseType' => $i % 3 == 0 ? $this->licenses[mt_rand(0, 2)] : null, 'travisCiBuildStatus' => $i % 2 == 0 ? $trilean[$i % 3] : null, 'nbFollowers' => $i * 10, 'nbForks' => $i, 'isFork' => false, 'contributors' => $contributor ? array($contributor) : array(), 'canonicalConfig' => $i % 2 == 0 ? $this->canonicalConfigDump : null, 'nbRecommenders' => rand(0, 90))); $commits = array(array('date' => '2010-05-16T09:58:32-09:00', 'author' => $owner instanceof Entity\Developer ? $owner->getName() : 'Random Person', 'message' => 'Fix something on this Bundle'), array('date' => '2010-05-16T09:58:32-07:00', 'author' => 'Fake Name', 'message' => 'Commit something on this bundle')); foreach ($commits as $commit) { $lastCommitAt = new \DateTime(); $lastCommitAt->setTimestamp(strtotime($commit['date'])); $bundle->setLastCommitAt($lastCommitAt); $activity = new Entity\Activity(); $activity->setType(Entity\Activity::ACTIVITY_TYPE_COMMIT); $activity->setMessage(strtok($commit['message'], "\n\r")); $activity->setCreatedAt($lastCommitAt); $activity->setBundle($bundle); if ($owner->getName() == $commit['author']) { $owner->setLastCommitAt($lastCommitAt); $activity->setDeveloper($owner); $activity->setBundleOwnerName(strtolower($owner->getName())); } else { $activity->setAuthor($commit['author']); $activity->setBundleOwnerName(strtolower($commit['author'])); } $manager->persist($activity); } $owner->addBundle($bundle); return $bundle; }