}
}
- function release($release) {
+ private function setTokenForUser($login) {
+ $relations = [
+ $this->accounts->getTokens()->getRelation("accounts"),
+ $this->accounts->getOwners()->getRelation("accounts")
+ ];
+ $tokens = $this->accounts->getTokens()->with($relations, [
+ "login=" => $login,
+ "tokens.authority=" => "github",
+ ]);
+
+ if (count($tokens)) {
+ $this->github->setToken($tokens->current()->token->get());
+ }
+ }
+
+ private function release($release) {
+ $response = $this->app->getResponse();
+
if ($release->action !== "published") {
- $response = $this->app->getResponse();
$response->setResponseCode(202);
$response->getBody()->append("Not published");
- return;
- }
- if (!empty($release->release->assets)) {
+ } elseif (!empty($release->release->assets)) {
foreach ($release->release->assets as $asset) {
if ($asset->content_type === "application/phar") {
/* we've already uploaded the asset when we created the release */
- $response = $this->app->getResponse();
$response->setResponseCode(202);
$response->getBody()->append("Already published");
return;
}
}
- $this->uploadAssetForRelease($release->release, $release->repository)->send();
+ $this->setTokenForUser($release->repository->owner->login);
+ $this->github->uploadAssetForRelease($release->release, $release->repository, function($json) use($response) {
+ $response->setResponseCode(201);
+ $response->setHeader("Location", $json->url);
+ })->send();
}
- private function uploadAssetForRelease($release, $repo) {
- $this->setTokenForUser($repo->owner->login);
- return $this->github->listHooks($repo->full_name, function($hooks) use($release, $repo) {
- $repo->hooks = $hooks;
- $asset = $this->createReleaseAsset($release, $repo);
- $name = sprintf("%s-%s.ext.phar", $repo->name, $release->tag_name);
- $url = uri_template($release->upload_url, compact("name"));
- $this->github->createReleaseAsset($url, $asset, "application/phar", function($json) use($release, $repo) {
- if ($release->draft) {
- $this->github->publishRelease($repo->full_name, $release->id, $release->tag_name, function($json) {
- $response = $this->app->getResponse();
- $response->setResponseCode(201);
- $response->setHeader("Location", $json->url);
- });
- } else {
- $response = $this->app->getResponse();
- $response->setResponseCode(201);
- $response->setHeader("Location", $json->url);
- }
- });
- });
+ private function create($create) {
+ $response = $this->app->getResponse();
+
+ if ($create->ref_type !== "tag") {
+ $response->setResponseCode(202);
+ $response->getBody()->append("Not a tag");
+ return;
+ }
+
+ $this->setTokenForUser($create->repository->owner->login);
+ $this->github->createReleaseFromTag($create->repository, $create->ref, function($json) use($response) {
+ $response->setResponseCode(201);
+ $response->setHeader("Location", $json->url);
+ })->send();
}
private function createReleaseAsset($release, $repo) {
$hook = $this->github->checkRepoHook($repo);
+ $phar = new Pharext\Package($repo->clone_url, $release->tag_name, $repo->name, $hook->config);
+ return $phar->getFile();
+
$dir = (new Task\GitClone($repo->clone_url, $release->tag_name))->run();
if (!empty($hook->config->pecl)) {
$src = new SoureDir\Pecl($dir);
$file = (new Task\PharBuild($src, $meta))->run();
return $file;
}
-
- function create($create) {
- if ($create->ref_type !== "tag") {
- $response = $this->app->getResponse();
-
- $response->setResponseCode(202);
- $response->getBody()->append("Not a tag");
- return;
- }
-
- $this->createReleaseFromTag($create->ref, $create->repository)->send();
- }
-
- private function setTokenForUser($login) {
- $relations = [
- $this->accounts->getTokens()->getRelation("accounts"),
- $this->accounts->getOwners()->getRelation("accounts")
- ];
- $tokens = $this->accounts->getTokens()->with($relations, [
- "login=" => $login,
- "tokens.authority=" => "github",
- ]);
-
- if (count($tokens)) {
- $this->github->setToken($tokens->current()->token->get());
- }
- }
-
- private function createReleaseFromTag($tag, $repo) {
- $this->setTokenForUser($repo->owner->login);
- return $this->github->createRelease($repo->full_name, $tag, function($json) use($repo) {
- $this->uploadAssetForRelease($json, $repo);
- });
- }
+
}
--- /dev/null
+<?php
+
+namespace app\Controller\Github;
+
+use app\Controller\Github;
+use app\Github\API\Repos\RepoCallback;
+
+
+class Release extends Github
+{
+ function __invoke(array $args = null) {
+ extract($args);
+ if ($this->checkToken()) {
+ list($repo) = $this->github->readRepo("$owner/$name", function($repo, $links = null) {
+ call_user_func(new RepoCallback($this->github), $repo, $links);
+
+ $this->github->listReleases($repo->full_name, null, function($releases) use($repo) {
+ $tag = $this->app->getRequest()->getForm("tag");
+ foreach ($releases as $r) {
+ if ($r->tag_name === $tag) {
+ $this->github->uploadAssetForRelease($repo, $r, function() use($repo) {
+ $this->app->redirect($this->app->getBaseUrl()->mod("./github/" . $repo->full_name));
+ });
+ return;
+ }
+ }
+
+ $this->github->createReleaseFromTag($repo, $tag, function() use($repo) {
+ $this->app->redirect($this->app->getBaseUrl()->mod("./github/" . $repo->full_name));
+ });
+ });
+ })->send();
+
+ $hook = $this->github->checkRepoHook($repo);
+
+ $this->app->getView()->addData(compact("owner", "name", "repo", "hook"));
+
+ if (($modal = $this->app->getRequest()->getQuery("modal"))) {
+ $action = $this->app->getRequest()->getQuery($modal);
+ $this->app->getView()->addData(compact("modal", "action"));
+ }
+
+ $this->app->display("github/repo");
+ }
+ }
+}
use app\Github\API;
use app\Github\Storage;
use app\Github\Exception;
+use app\Pharext;
use merry\Config;
$call = new API\Releases\ListReleaseAssets($this, compact("repo", "id"));
return $call($callback);
}
+
+ function uploadAssetForRelease($repo, $release, callable $callback) {
+ return $this->listHooks($repo->full_name, function($hooks) use($release, $repo, $callback) {
+ $repo->hooks = $hooks;
+ $hook = $this->checkRepoHook($repo);
+ $phar = new Pharext\Package($repo->clone_url, $release->tag_name, $repo->name, $hook ? $hook->config : null);
+ $name = sprintf("%s-%s.ext.phar", $repo->name, $release->tag_name);
+ $url = uri_template($release->upload_url, compact("name"));
+ $this->createReleaseAsset($url, $phar, "application/phar", function($json) use($release, $repo, $callback) {
+ if ($release->draft) {
+ $this->publishRelease($repo->full_name, $release->id, $release->tag_name, function($json) use($callback) {
+ $callback($json);
+ });
+ } else {
+ $callback($json);
+ }
+ });
+ });
+ }
+
+ function createReleaseFromTag($repo, $tag_name, callable $callback) {
+ return $this->createRelease($repo->full_name, $tag_name, function($json) use($repo, $callback) {
+ $this->uploadAssetForRelease($repo, $json, $callback);
+ });
+ }
+
}
--- /dev/null
+<?php
+
+namespace app\Pharext;
+
+use pharext\Metadata;
+use pharext\SourceDir;
+use pharext\Task;
+
+class Package
+{
+ private $file;
+
+ function __construct($git_url, $tag_name, $pkg_name, $options) {
+ $dir = (new Task\GitClone($git_url, $tag_name))->run();
+ $src = !empty($options->pecl)
+ ? new SourceDir\Pecl($dir)
+ : new SourceDir\Git($dir);
+ $meta = Metadata::all() + [
+ "name" => $pkg_name,
+ "release" => $tag_name,
+ "license" => $src->getLicense(),
+ "stub" => "pharext_installer.php",
+ "type" => !empty($options->zend) ? "zend_extension" : "extension",
+ ];
+ $this->file = (new Task\PharBuild($src, $meta))->run();
+ }
+
+ function __toString() {
+ return (string) $this->file;
+ }
+
+ function getFile() {
+ return $this->file;
+ }
+}
</ul>
</div>
<div class="col-sm-4">
- <?php if (!empty($v->release->assets)) : ?>
<ul class="list-inline pull-right">
+ <?php if (!empty($v->release->assets)) : ?>
<?php foreach ($v->release->assets as $asset) : ?>
<?php if (fnmatch("*.ext.phar", $asset->name)) : ?>
<li>
</li>
<?php endif; ?>
<?php endforeach; ?>
+ <?php else: ?>
+ <form method="post" action="<?= $baseUrl->mod("./github/repo/". $repo->full_name ."/release") ?>">
+ <input type="hidden" name="tag" value="<?= $this->e($v->tag->name) ?>">
+ <button class="btn btn-warning">
+ <span class="octicon octicon-package"></span>
+ Release PHARext package
+ </button>
+ </form>
+ <?php endif; ?>
</ul>
- <?php endif; ?>
</div>
</div>
</div>
github.hook.insecure_ssl = 0
github.storage.token.ttl = 3600
-github.storage.cache.repo.ttl = 3600
-github.storage.cache.repos.ttl = 3600
-github.storage.cache.hooks.ttl = 3600
-github.storage.cache.tags.ttl = 3600
-github.storage.cache.releases.ttl = 3600
+github.storage.cache.readrepo.ttl = 3600
+github.storage.cache.listrepos.ttl = 3600
+github.storage.cache.listhooks.ttl = 3600
+github.storage.cache.listtags.ttl = 3600
+github.storage.cache.listreleases.ttl = 3600
+github.storage.cache.listreleaseassets.ttl = 3600
github.log = github
; if the user has to re-authenticate, we'll receive a GET because of a redirect
GET[] = /github/repo/{owner}/{name}/hook/{action}
+[Github\Release]
+POST[] = /github/repo/{owner}/{name}/release
+; if the user has to re-authenticate, we'll receive a GET because of a redirect
+GET[] = /github/repo/{owner}/{name}/release
+
[Github\Signin]
GET[] = /github/signin