protected function __after_save__($commit) { $maintainers = C(OpenpearMaintainer)->find_all(); $packages = C(OpenpearPackage)->find_all(); $template = new Template(); $template->vars('maintainers', $maintainers); $template->vars('packages', $packages); File::write(OpenpearConfig::svn_access_file(), $template->read('files/access.txt')); }
public function create() { try { Subversion::cmd('import', array(OpenpearConfig::svn_skeleton(work_path('skeleton')), File::absolute(OpenpearConfig::svn_root(), $this->package()->name())), array('message' => sprintf('[New Package] %s (@%s)', $this->package()->name(), $this->maintainer()->name()), 'username' => OpenpearConfig::system_user('openpear'))); // $message = new OpenpearMessage(); // $message->subject('New Package is ready for your commit!'); $this->delete(); C($this)->commit(); } catch (Exception $e) { Log::error($e->getMessage()); $this->trial_count += 1; $this->save(); C($this)->commit(); } }
protected function __after_create__() { try { if ($this->mail()) { list($account, $password) = OpenpearConfig::gmail_account(); $mail = new Gmail($account, $password); $mail->to($this->maintainer_to()->mail(), str($this->maintainer_to())); $mail->from($mail->from(), 'Openpear'); $mail->subject($this->subject()); $mail->message(strip_tags($this->fm_description())); $mail->send(); } } catch (Exception $e) { Log::debug($e); } }
public function check_repo_exists() { $this->login_required(); try { $package = OpenpearPackage::get_package($this->in_vars('package_id')); $info = Subversion::cmd('info', array(File::absolute(OpenpearConfig::svn_root(), implode('/', array($package->name(), 'trunk', $this->in_vars('dir', '')))))); if (isset($info['kind']) && $info['kind'] == 'dir') { echo 'ok'; } else { throw new RuntimeException('directory is not found'); } } catch (Exception $e) { Log::debug($e); echo 'ng'; } exit; }
/** * @see vendors/org/rhaco/storage/db/Dao/Dao#__after_save__() * @const string $svn_passwd_file リポジトリにアクセスするパスワード */ protected function __after_save__($commit) { $template = new Template(); $template->vars('maintainers', C(OpenpearMaintainer)->find_all()); File::write(OpenpearConfig::svn_passwd_file(work_path('openpear.passwd')), $template->read('files/passwd.txt')); Store::delete(self::cache_key($this->id)); }
/** * ファイルアップロードからリリース * @param string $package_name パッケージ名 **/ public function package_release_by_upload($package_name) { $package = C(OpenpearPackage)->find_get(Q::eq('name', $package_name)); $package->permission($this->user()); if ($this->is_post() && $this->is_files('package_file') && $this->verify()) { try { $package_file = $this->in_files('package_file'); $package_file->generate(work_path('upload/' . $package_name . '-' . date('YmdHis') . '.tgz')); if ($package_xml = simplexml_load_file(sprintf('phar://%s/package.xml', $package_file->fullname()))) { if ($package_xml->name != $package->name()) { throw new OpenpearException(Gettext::trans('incorrect package name')); } if ($package_xml->channel != OpenpearConfig::pear_domain('openpear.org')) { $package_xml->channel = OpenpearConfig::pear_domain('openpear.org'); $pd = new PharData($package_file->fullname()); $pd->addFromString('package.xml', $package_xml->asXML()); unset($pd); } $upload_queue = new stdClass(); $upload_queue->package_id = $package->id(); $upload_queue->package_file = $package_file->fullname(); $upload_queue->maintainer_id = $this->user()->id(); $queue = new OpenpearQueue('type=upload_release'); $queue->data(serialize($upload_queue)); $queue->save(); $message = new OpenpearMessage('type=system_notice,mail=false'); $message->maintainer_to_id($this->user()->id()); $message->subject(trans('リリースキューに追加されました')); $message->description(trans('{1}のリリースを受け付けました。リリースの完了後,メールでお知らせします。', $package->name())); $message->save(); $this->redirect_by_map('dashboard'); } } catch (Exception $e) { Log::debug($e); Exceptions::add($e); } } $this->vars('package', $package); $this->vars('package_id', $package->id()); }
public static function commit_hook($path, $revision, $message) { Log::debug(sprintf('commit hook: %s %d "%s"', $path, $revision, $message)); $changed = Subversion::look('changed', array($path), array('revision' => $revision)); $author = trim(Subversion::look('author', array($path), array('revision' => $revision))); $parsed_changed = self::parse_svnlook_changed($changed); list($package_name) = explode('/', $parsed_changed[0]['path']); try { $package = C(OpenpearPackage)->find_get(Q::eq('name', $package_name)); $maintainer = null; try { if ($author == OpenpearConfig::system_user('openpear') && preg_match('/\\(@(.*?)\\)$/', trim($message), $match)) { $author = $match[1]; } $maintainer = C(OpenpearMaintainer)->find_get(Q::eq('name', $author)); } catch (Exception $e) { Log::error($e); // throw $e; } $changeset = new self(); $changeset->revision($revision); if ($maintainer instanceof OpenpearMaintainer) { $changeset->maintainer_id($maintainer->id()); } $changeset->package_id($package->id()); $changeset->changed(serialize($parsed_changed)); $changeset->save(); if ($maintainer instanceof OpenpearMaintainer) { $package->author_id($maintainer->id()); } $package->recent_changeset($changeset->revision()); $package->save(true); } catch (Exception $e) { throw $e; } try { chdir(OpenpearConfig::working_copy()); ob_start(); passthru('svn up'); ob_end_clean(); } catch (Exception $e) { } }
/** * パッケージ情報を取得する * @param int $id * @param bool $cache * @return OpenpearPackage **/ public static function get_package($id, $cache = true) { $cache_key = self::cache_key($id); if ($cache) { Log::debug('cache on'); if (isset(self::$cached_packages[$id])) { return self::$cached_packages[$id]; } else { if (Store::has($cache_key)) { $package = Store::get($cache_key); self::$cached_packages[$id] = $package; return $package; } } } $package = C(__CLASS__)->find_get(Q::eq('id', $id)); Store::set($cache_key, $package, OpenpearConfig::object_cache_timeout(3600)); return $package; }
/** * Subversion リポジトリの基本ディレクトリ構成を生成する */ public static function __setup_generate_skeleton__(Request $req) { $base_dir = $req->in_vars('path', OpenpearConfig::svn_skeleton(work_path('skeleton'))); File::mkdir($base_dir); File::mkdir(File::path($base_dir, 'doc')); File::mkdir(File::path($base_dir, 'doc/en')); File::mkdir(File::path($base_dir, 'doc/ja')); File::mkdir(File::path($base_dir, 'trunk')); File::mkdir(File::path($base_dir, 'tags')); File::mkdir(File::path($base_dir, 'branches')); File::write(File::path($base_dir, 'doc/ja/README'), text(' * Documentation このパッケージにはまだドキュメントが存在しません ')); File::write(File::path($base_dir, 'doc/en/README'), text(' * Documentation This package does not have any documents. ')); }
public final function svn_log_msg($revision) { $log = Subversion::cmd('log', array(OpenpearConfig::svn_root()), array('revision' => $revision)); return (string) $log[0]['msg']; }
/** * パッケージのビルドとリリースを行う * @return void **/ public function build() { $package = C(OpenpearPackage)->find_get(Q::eq('id', $this->package_id)); $maintainer = C(OpenpearMaintainer)->find_get(Q::eq('id', $this->maintainer_id)); $this->init_build_dir(work_path('build/' . $package->name() . '.' . date('YmdHis'))); foreach (array('desc.txt', 'notes.txt', 'summary.txt') as $filename) { File::write($this->build_dir($filename), $package->description()); } if ($package->is_external_repository()) { switch ($package->external_repository_type()) { case 'Git': $cmd = 'git clone'; break; case 'Mercurial': $cmd = 'hg clone'; break; case 'Subversion': $cmd = 'svn export'; break; default: throw new RuntimeException('unknown repository type'); } $command = new Command(sprintf('%s %s %s', $cmd, escapeshellarg($package->external_repository()), escapeshellarg($this->build_dir('tmp')))); } else { // Openpear Repository $revision = is_numeric($this->revision) && $this->revision > 0 ? intval($this->revision) : 'HEAD'; $repository_path = sprintf('%s/%s/trunk', OpenpearConfig::svn_root(), $package->name()); $command = new Command(sprintf('svn export -r %s %s %s', $revision, escapeshellarg($repository_path), escapeshellarg($this->build_dir('tmp')))); } if ($command->end_code()) { throw new RuntimeException($command->stderr()); } $build_path = $this->build_dir(implode('/', array('tmp', $this->build_path))); if (!File::exist($build_path)) { throw new RuntimeException(sprintf('build path is not found: %s', $build_path)); } $mv = new Command(sprintf('mv %s %s', escapeshellarg($build_path), escapeshellarg($this->build_dir('src')))); if ($mv->stderr() || !is_dir($this->build_dir('src'))) { throw new RuntimeException('src dir is not found'); } // ビルドする chdir($this->build_dir()); $project = PEAR_PackageProjector::singleton()->load($this->build_dir()); $project->configure($this->build_dir('build.conf')); $project->make(); // リリースしたファイルはどこ? chdir($this->build_dir('release')); foreach (glob('*.tgz') as $filename) { $package_file = $this->build_dir('release') . '/' . $filename; break; } if (!file_exists($package_file)) { throw new RuntimeException('package file is not exists: ' . $package_file); } // サーバーに追加する $cfg = (include path('channel.config.php')); $server = new PEAR_Server2($cfg); $server->addPackage($package_file); // svn tag $build_conf = parse_ini_string($this->build_conf, true); $svn = new Command(sprintf('svn copy' . ' %s/%s/trunk/%s' . ' %s/%s/tags/%s-%s-%s' . ' -m "%s (%s-%s) (@%s)"' . ' --username openpear', OpenpearConfig::svn_root(), $package->name(), $this->build_path, OpenpearConfig::svn_root(), $package->name(), $build_conf['version']['release_ver'], $build_conf['version']['release_stab'], date('YmdHis'), 'package released', $build_conf['version']['release_ver'], $build_conf['version']['release_stab'], $maintainer->name())); // これ以降はエラーが起きてもドンマイ try { $release = new OpenpearRelease(); $release->package_id($package->id()); $release->maintainer_id($maintainer->id()); $release->version($build_conf['version']['release_ver']); $release->version_stab($build_conf['version']['release_stab']); $release->notes($this->notes); $release->settings($this->build_conf); $release->save(); $package->latest_release_id($release->id()); $package->released_at(time()); $package->save(); $message_template = new Template(); $message_template->vars('t', new Templf()); $message_template->vars('package', $package); $message_template->vars('maintainer', $maintainer); $message = new OpenpearMessage('type=system'); $message->maintainer_to_id($maintainer->id()); $message->subject(trans('{1} package have been released.', $package->name())); $message->description($message_template->read('messages/released.txt')); $message->save(); } catch (Exception $e) { Log::error($e); } }