Knp\Bundle\KnpBundlesBundle\Github\Repo::updateFiles PHP Method

updateFiles() public method

public updateFiles ( Bundle $bundle, array $onlyFiles = null )
$bundle Knp\Bundle\KnpBundlesBundle\Entity\Bundle
$onlyFiles array
    public function updateFiles(Bundle $bundle, array $onlyFiles = null)
    {
        $this->output->write(' files');
        /** @var \Github\Api\Repository\Contents $api */
        $api = $this->github->api('repo')->contents();
        try {
            $files = $api->show($bundle->getOwnerName(), $bundle->getName());
        } catch (RuntimeException $e) {
            return false;
        }
        foreach ($files as $data) {
            switch ($data['name']) {
                case 'LICENSE':
                    if (null !== $onlyFiles && !in_array('license', $onlyFiles)) {
                        continue;
                    }
                    try {
                        $file = $api->show($bundle->getOwnerName(), $bundle->getName(), 'LICENSE');
                        $bundle->setLicense(base64_decode($file['content']));
                    } catch (RuntimeException $e) {
                    }
                    break;
                case '.travis.yml':
                    if (null !== $onlyFiles && !in_array('travis', $onlyFiles)) {
                        continue;
                    }
                    $bundle->setUsesTravisCi(true);
                    break;
                case 'composer.json':
                    if (null !== $onlyFiles && !in_array('composer', $onlyFiles)) {
                        continue;
                    }
                    try {
                        $file = $api->show($bundle->getOwnerName(), $bundle->getName(), 'composer.json');
                        $this->updateComposerFile(base64_decode($file['content']), $bundle);
                    } catch (RuntimeException $e) {
                    }
                    break;
            }
        }
        if (null === $onlyFiles || in_array('readme', $onlyFiles)) {
            try {
                $readme = $api->readme($bundle->getOwnerName(), $bundle->getName());
                if (!isset($readme['message']) && 'base64' == $readme['encoding']) {
                    $bundle->setReadme(base64_decode($readme['content']));
                }
            } catch (RuntimeException $e) {
            }
        }
        if (null === $bundle->getLicense() && (null === $onlyFiles || in_array('license', $onlyFiles))) {
            try {
                $file = $api->show($bundle->getOwnerName(), $bundle->getName(), 'Resources/meta/LICENSE');
                $bundle->setLicense(base64_decode($file['content']));
            } catch (RuntimeException $e) {
            }
        }
        if (null === $onlyFiles || in_array('configuration', $onlyFiles)) {
            try {
                $this->updateCanonicalConfigFile($bundle);
            } catch (RuntimeException $e) {
            }
        }
        try {
            $this->updateVersionsHistory($bundle);
        } catch (RuntimeException $e) {
        }
        return true;
    }

Usage Example

Exemplo n.º 1
0
 public function createMissingBundles(array $foundBundles)
 {
     $added = 0;
     /* @var $bundle Bundle */
     foreach ($foundBundles as $fullName) {
         $bundle = $this->bundleManager->createBundle($fullName);
         // It's not a valid Symfony2 Bundle or failed with our requirements (i.e: is a fork with less then 10 watchers)
         if (!$bundle) {
             $this->notifyInvalid($fullName, 'Bundle is not an valid Symfony2 Bundle or failed with our requirements, or we were not able to get such via API.');
             continue;
         }
         $this->output->write(sprintf('[%s] Discover bundle <comment>%s</comment>: ', date('d-m-y H:i:s'), $bundle->getFullName()));
         try {
             $this->githubRepoApi->updateFiles($bundle);
         } catch (\RuntimeException $e) {
             $this->output->writeln(sprintf(' <error>%s</error>', $e->getMessage()));
             continue;
         }
         $this->em->persist($bundle);
         $this->updateRepo($bundle);
         $this->output->writeln(' ADDED');
         ++$added;
     }
     $this->em->flush();
     if ($added) {
         $this->output->writeln(sprintf('[%s] Created <comment>%d</comment> new bundles', date('d-m-y H:i:s'), $added));
     }
 }