protected function generateDocs(Repository $repository, Repository $docsRepository, GitSource $source) { $this->logger->debug('Generate docs'); $args = array(dirname(dirname(__DIR__)) . '/vendor/bin/apigen'); $args[] = 'generate'; foreach (array('config' => static::PARAM_SOURCE_FILE, 'template-config' => static::PARAM_SOURCE_FILE, 'extensions' => static::PARAM_STRING, 'exclude' => static::PARAM_STRING, 'skip-doc-path' => static::PARAM_STRING, 'main' => static::PARAM_STRING, 'title' => static::PARAM_STRING, 'base-url' => static::PARAM_STRING, 'google-cse-id' => static::PARAM_STRING, 'google-analytics' => static::PARAM_STRING, 'template-theme' => static::PARAM_STRING, 'groups' => static::PARAM_STRING, 'charset' => static::PARAM_STRING, 'access-levels' => static::PARAM_STRING, 'annotation-groups' => static::PARAM_STRING, 'internal' => static::PARAM_BOOL, 'php' => static::PARAM_BOOL, 'tree' => static::PARAM_BOOL, 'deprecated' => static::PARAM_BOOL, 'no-source-code' => static::PARAM_BOOL, 'todo' => static::PARAM_BOOL, 'download' => static::PARAM_BOOL) as $parameter => $type) { if (array_key_exists($parameter, $this->settings)) { $value = $this->settings[$parameter]; switch ($type) { case static::PARAM_SOURCE_FILE: $value = $repository->getSourcesPath() . '/' . ltrim($value, '/'); break; case static::PARAM_DOCS_FILE: $value = $repository->getDocsPath() . '/' . ltrim($value, '/'); break; case static::PARAM_STRING: // do nothing break; case static::PARAM_BOOL: if ($value) { $args[] = '--' . $parameter; } continue 2; default: $this->logger->warning(sprintf('Parameter %s has an illegal type %s', $parameter, $type)); // skip continue; } $args[] = '--' . $parameter; $args[] = $value; } } $args[] = '--source'; $args[] = $repository->getSourcesPath() . (array_key_exists('src-path', $this->settings) ? '/' . ltrim($this->settings['src-path'], '/') : ''); $args[] = '--destination'; $args[] = $docsRepository->getDocsPath() . (array_key_exists('docs-path', $this->settings) ? '/' . ltrim($this->settings['docs-path'], '/') : ''); $process = ProcessBuilder::create($args)->getProcess(); $process->setTimeout(null); $this->logger->debug('exec ' . $process->getCommandLine()); $process->run(); if (!$process->isSuccessful()) { throw new \RuntimeException($process->getCommandLine() . ': ' . $process->getErrorOutput() ?: $process->getOutput()); } }
protected function generateDocs(Repository $repository, Repository $docsRepository, GitSource $source) { $this->logger->debug('Generate docs'); $args = array(dirname(dirname(__DIR__)) . '/vendor/bin/phpdoc.php'); foreach (array('config' => static::PARAM_SOURCE_FILE, 'extensions' => static::PARAM_STRING, 'ignore' => static::PARAM_STRING, 'ignore-tags' => static::PARAM_STRING, 'encoding' => static::PARAM_STRING, 'title' => static::PARAM_STRING, 'defaultpackagename' => static::PARAM_STRING, 'template' => static::PARAM_STRING, 'hidden' => static::PARAM_BOOL, 'ignore-symlinks' => static::PARAM_BOOL, 'visibility' => static::PARAM_STRING, 'sourcecode' => static::PARAM_BOOL, 'parseprivate' => static::PARAM_BOOL) as $parameter => $type) { if (array_key_exists($parameter, $this->settings)) { $value = $this->settings[$parameter]; switch ($type) { case static::PARAM_SOURCE_FILE: $value = $repository->getSourcesPath() . '/' . ltrim($value, '/'); break; case static::PARAM_DOCS_FILE: $value = $repository->getDocsPath() . '/' . ltrim($value, '/'); break; case static::PARAM_STRING: // do nothing break; case static::PARAM_BOOL: if ($value) { $args[] = '--' . $parameter; } continue 2; default: $this->logger->warning(sprintf('Parameter %s has an illegal type %s', $parameter, $type)); // skip continue 2; } $args[] = '--' . $parameter . '=' . $value; } } $args[] = '--directory'; $args[] = $repository->getSourcesPath() . (array_key_exists('src-path', $this->settings) ? '/' . ltrim($this->settings['src-path'], '/') : ''); $args[] = '--target'; $args[] = $docsRepository->getDocsPath() . (array_key_exists('docs-path', $this->settings) ? '/' . ltrim($this->settings['docs-path'], '/') : ''); $args[] = '--force'; $args[] = '--no-interaction'; $process = ProcessBuilder::create($args)->getProcess(); $this->logger->debug('exec ' . $process->getCommandLine()); $process->run(); if (!$process->isSuccessful()) { throw new \RuntimeException($process->getCommandLine() . ': ' . $process->getErrorOutput() ?: $process->getOutput()); } }
protected function execute(InputInterface $input, OutputInterface $output) { $ownerName = $input->getArgument('owner'); $repositoryName = $input->getArgument('repository'); $branch = $input->getArgument('branch'); $github = $input->getOption('github'); $local = $input->getOption('local'); $repository = new Repository(); $repository->setOwnerName($ownerName); $repository->setRepositoryName($repositoryName); $repository->setMasterBranch($branch); $repository->setCommitBranch($branch); if ($github) { $url = sprintf('https://api.github.com/repos/%s/%s/commits/%s', $ownerName, $repositoryName, $branch); $client = new Client(); $request = $client->get($url); $response = $request->send(); $json = $response->json(); $repository->setCommitMessage($json['commit']['message']); $source = new GithubSource(); } else { if ($local) { $source = new LocalGitSource($local); $git = ProcessBuilder::create()->add('git')->add('show')->add('--format=%s')->add('-s')->setWorkingDirectory($source->getRepositoryUrl($repository))->getProcess(); $git->run(); if (!$git->isSuccessful()) { throw new \RuntimeException($git->getErrorOutput()); } $repository->setCommitMessage(trim($git->getOutput())); } else { throw new \InvalidArgumentException('You must specify at least one source'); } } $hook = new Hook(); $hook->run($repository, $source); }
public function run(Repository $repository, GitSource $source) { $this->logger = new Logger($repository->getRepository(), array($this->handler)); $this->logger->info(sprintf('Generate api docs for %s/%s, branch %s: %s', $repository->getOwnerName(), $repository->getRepositoryName(), $repository->getCommitBranch(), $repository->getCommitMessage())); $this->generateDocs($repository, $source); }
protected function updateHistory(Repository $repository, Repository $docsRepository, GitSource $source) { if (!array_key_exists('promoted', $this->settings) || $this->settings['promoted'] === false) { return; } $pathname = dirname(dirname(__DIR__)) . '/web/history.html'; $file = fopen($pathname, file_exists($pathname) ? 'r+' : 'w'); flock($file, LOCK_EX); $history = stream_get_contents($file); $lines = explode("\n", $history); $lines = array_map('trim', $lines); $lines = array_filter($lines); $class = new \ReflectionClass($this); $className = strtolower($class->getShortName()); array_unshift($lines, sprintf('<tr><td>%s</td><td>%s</td><td><a href="%s" target="_blank">%s</a></td></tr>', date('Y-m-d H:i:s'), $className, $source->getPagesUrl($docsRepository), $repository->getRepository())); while (count($lines) > 15) { array_pop($lines); } $history = implode("\n", $lines); ftruncate($file, 0); fwrite($file, $history); fflush($file); flock($file, LOCK_UN); fclose($file); }
/** * ApiGenerator.org * Copyright (C) 2013 Tristan Lins * * PHP version 5 * * @copyright bit3 UG 2013 * @author Tristan Lins <*****@*****.**> * @package apigenerator.org * @license LGPL-3.0+ * @filesource */ ob_start(); if (!array_key_exists('payload', $_POST)) { header("HTTP/1.1 400 Bad Request"); echo '400 Bad Request'; while (count(ob_list_handlers())) { ob_end_flush(); } exit(1); } require_once __DIR__ . '/../vendor/autoload.php'; $payload = $_POST['payload']; $payload = json_decode($payload); $repository = \ApiGeneratorOrg\Repository::createFromGithubPayload($payload); $source = new \ApiGeneratorOrg\GithubSource(); $hook = new \ApiGeneratorOrg\Hook(); $hook->run($repository, $source); while (count(ob_list_handlers())) { ob_end_flush(); }