public function doValidate($validator, $values) { if ($values['id']) { $plugin = PluginPeer::retrieveByPk($values['id']); if (!sfContext::getInstance()->getUser()->ownsPlugin($plugin)) { throw new sfValidatorError($validator, 'You don\'t own the plugin you\'re trying to edit'); } } if (substr_count($values['repository'], '.git') > 0) { $values['repository'] = substr($values['repository'], 0, strrpos($values['repository'], '.')); } $tags = GitHubFetcher::fetchContent(sprintf('/repos/%s/%s/tags', $values['user'], $values['repository'])); if (($tagsArr = @json_decode($tags)) !== null) { foreach ((array) $tagsArr as $tag) { $this->gitTags[] = $tag->name; } usort($this->gitTags, 'version_compare'); } else { throw new sfValidatorError($validator, 'Bad GitHub response. Try again later.'); } if (empty($this->gitTags)) { throw new sfValidatorError($validator, 'GitHub repository has no tags. At least one tag is required.'); } return $values; }
public function doValidate($validator, $values) { $files = array('package.yml' => 'file', 'README.md' => 'file', 'Source' => 'dir'); // the validator just checks if files are in the repos. Because github changed // everything with version 3 this needs a complete rewrite. if (substr_count($values['repository'], '.git') > 0) { $values['repository'] = substr($values['repository'], 0, strrpos($values['repository'], '.')); } $contentList = GitHubFetcher::fetchContent(sprintf('/repos/%s/%s/contents/%s', $values['user'], $values['repository'], $file)); if (($contentList = @json_decode($contentList)) !== null) { foreach ($files as $filename => $filetype) { foreach ((array) $contentList as $contentItem) { if (isset($files[$contentItem->name]) && $files[$contentItem->name]['type'] != $contentItem->type) { $this->gitFileList[$contentItem->name] = $contentItem; } } } if (count($this->gitFileList) < count($this->gitFileList)) { throw new sfValidatorError($validator, sprintf('Could not find one of necessary files (%s) <a href="http://github.com/%s/%s/blob/master/">%s / %s</a> not found in repository root.', implode(', ', array_keys($files)), $values['user'], $values['repository'], $values['user'], $values['repository'])); } } return $values; }
/** * Step 5 * * @author Guillermo Rauch **/ public function executeAdd5(sfWebRequest $request) { if ($request->isMethod('post')) { $addid = $request->getParameter('addid'); $this->checkStep(4, $addid); $this->getUser()->getAttributeHolder()->getNames(); $user = $this->getUser()->getAttribute('github.user', null, 'plugin.add.' . $addid); $repository = $this->getUser()->getAttribute('github.repository', null, 'plugin.add.' . $addid); // the validator just checks if files are in the repos. Because github changed // everything with version 3 this needs a complete rewrite. if (substr_count($repository, '.git') > 0) { $repository = substr($repository, 0, strrpos($repository, '.')); } $gitPath = '/repos/' . $user . '/' . $repository . '/contents'; $gitTags = $this->getUser()->getAttribute('github.tags', array(), 'plugin.add.' . $addid); $readme = json_decode(GitHubFetcher::fetchContent($gitPath . '/README.md')); $readme = new ForgeMDParser(base64_decode(@$readme->content)); $manifest = json_decode(GitHubFetcher::fetchContent($gitPath . '/package.yml')); $manifest = new ForgeYamlParser(base64_decode(@$manifest->content)); $params = array('author' => $manifest->get('author'), 'arbitrarySections' => $readme->getArbitrarySections(), 'stabletag' => $manifest->get('current'), 'screenshots' => $readme->getScreenshots(), 'category' => $manifest->get('category'), 'tags' => $manifest->get('tags'), 'gitTags' => $gitTags, 'title' => $manifest->get('name'), 'screenshot' => $readme->getScreenshot(), 'docsurl' => $manifest->get('docs'), 'demourl' => $manifest->get('demo'), 'howtouse' => $readme->getSection('how-to-use'), 'description' => $readme->getDescription()); $form = new PluginAddStep5Form(); $form->bind($params); if ($form->isValid()) { $this->getUser()->setAttribute('step', 5, 'plugin.add.' . $addid); $this->getUser()->setAttribute('github.params', $form->getValues(), 'plugin.add.' . $addid); return $this->renderJson(array('success' => true, 'status' => 'Verifying JS files')); } return $this->renderJson($form->toJson()); } }
function pull() { # Tags $tags = GitHubFetcher::fetchContent(sprintf('/repos/%s/%s/tags', $this->user, $this->project)); if ($tagsArr = @json_decode($tags)) { $this->tags = array_keys((array) $tagsArr->tags); usort($this->tags, 'version_compare'); } else { throw new ForgeException('Bad GitHub response'); } if (empty($this->tags)) { throw new ForgeException('GitHub repository has no tags. At least one tag is needed for a download.'); } # Get commits for README.md $tree = ''; $commitsList = $this->fetch(sprintf('http://github.com/api/v2/json/commits/list/%s/%s/master/README.md', $this->user, $this->project)); if ($commitsArr = @json_decode($commitsList)) { $commits = (array) $commitsArr->commits; if (!empty($commits) && isset($commits[0]->tree)) { $tree = $commits[0]->tree; } } else { throw new ForgeException('Bad GitHub response'); } if (empty($tree)) { throw new ForgeException('README.md not found in repository root'); } # README.md $blob = $this->fetch(sprintf('http://github.com/api/v2/json/blob/show/%s/%s/%s/README.md', $this->user, $this->project, $tree)); if ($blobInfo = @json_decode($blob)) { $this->readme = $blobInfo->blob->data; } else { throw new ForgeException('Bad GitHub response'); } if (empty($this->readme)) { throw new ForgeException('README.md possibly empty, or some other weirdness occured.'); } # Get commits for package.yml $tree = ''; $commitsList = $this->fetch(sprintf('http://github.com/api/v2/json/commits/list/%s/%s/master/package.yml', $this->user, $this->project)); if ($commitsArr = @json_decode($commitsList)) { $commits = (array) $commitsArr->commits; if (!empty($commits) && isset($commits[0]->tree)) { $tree = $commits[0]->tree; } } else { throw new ForgeException('Bad GitHub response'); } if (empty($tree)) { throw new ForgeException('package.yml not found in repository root'); } # package.yml $blob = $this->fetch(sprintf('http://github.com/api/v2/json/blob/show/%s/%s/%s/package.yml', $this->user, $this->project, $tree)); if ($blobInfo = @json_decode($blob)) { $this->yaml = $blobInfo->blob->data; } else { throw new ForgeException('Bad GitHub response'); } if (empty($this->yaml)) { throw new ForgeException('package.yml possibly empty, or some other weirdness occured.'); } // # get the files // try { // $repo = new GitRepository(sprintf('http://github.com/%s/%s.git', $this->getUser(), $this->getProject()), ); // // if ($repo->update()){ // $files = sfFinder::type('file')->name('*.js')->in($repo->getDir()); // // foreach ($files as $file){ // // try { // $parser = new ForgeJSParser(file_get_contents($file)); // } catch (ForgeJSParserException $e){ // // } // // } // } // // } catch (GitRepositoryException $e){ // throw new ForgeException($e->getMessage()); // } // // // $this->filesMap = array(); }