show already uploaded asset
authorMichael Wallner <mike@php.net>
Tue, 12 May 2015 09:58:59 +0000 (11:58 +0200)
committerMichael Wallner <mike@php.net>
Tue, 12 May 2015 09:58:59 +0000 (11:58 +0200)
app/Controller/Github/Repo.php
app/Github/API.php
app/Github/API/Releases/ListReleaseAssets.php
app/views/github/repo.phtml

index bf1358a55400c035d216645784191d2ecef9c58e..32fab565a7794a3ccd4000e910cfaf4b2b87556c 100644 (file)
@@ -44,6 +44,9 @@ class Repo extends Github
                                $tag = $release->tag_name;
                                settype($repo->tags->$tag, "object");
                                $repo->tags->$tag->release = $release;
+                               $this->github->listReleaseAssets($repo->full_name, $release->id, function($assets) use($release) {
+                                       $release->assets = $assets;
+                               });
                        }
                };
        }
index 0f63a60f5b873a33abdfc07d78538de9a829ce27..d6990f257edf7fc80fa8c04961e4687d35df251d 100644 (file)
@@ -212,4 +212,9 @@ class API
                $call = new API\Releases\CreateReleaseAsset($this, compact("url", "asset", "type"));
                return $call($callback);
        }
+       
+       function listReleaseAssets($repo, $id, callable $callback) {
+               $call = new API\Releases\ListReleaseAssets($this, compact("repo", "id"));
+               return $call($callback);
+       }
 }
index b365183cd77935d8e8319796916a5e08389ed7d6..bde9096b99930fee7e0f39e93824c3cd9bfca5ea 100644 (file)
@@ -2,17 +2,22 @@
 
 namespace app\Github\API\Releases;
 
-class ListReleaseAssets extends \app\Github\API\Call
+use app\Github\API\Call;
+use app\Github\Exception\RequestException;
+use app\Github\Links;
+use http\Client\Request;
+
+class ListReleaseAssets extends Call
 {
        function enqueue(callable $callback) {
-               $url = $this->url->mod(uri_template("./repos/{+repo}/releases{/release}/assets", $this->args));
-               $request = new \http\Client\Request("GET", $url, [
+               $url = $this->url->mod(uri_template("./repos/{+repo}/releases{/id}/assets", $this->args));
+               $request = new Request("GET", $url, [
                        "Authorization" => "token ". $this->api->getToken(),
                        "Accept" => $this->config->api->accept,
                ]);
                $this->api->getClient()->enqueue($request, function($response) use($callback) {
                        if ($response->getResponseCode() >= 400 || null === ($json = json_decode($response->getBody()))) {
-                               throw new \app\Github\Exception\RequestException($response);
+                               throw new RequestException($response);
                        }
                        $links = new Links($response->getHeader("Link"));
                        $this->saveToCache([$json, $links]);
index 6000cf7e976f563952a949c8dd70876c70817960..80b5c8c1dc7021d1853d5cf2cefd327ac96848b7 100644 (file)
                </h3>
        </div>
        <div class="panel-body">
+               <div class="row">
+                       <div class="col-md-8">
                <?php if (!empty($v->release)) : ?>
                        <p><?= $this->md($v->release->body) ?></p>
                <?php endif; ?>
                                </span>
                        <?php endif; ?>
                </ul>
+                       </div>
+                       <div class="col-md-4">
+               <?php if (!empty($v->release->assets)) : ?>
+                       <ul class="list-inline pull-right">
+                               <?php foreach ($v->release->assets as $asset) : ?>
+                               <?php if (fnmatch("*.ext.phar", $asset->name)) : ?>
+                               <li>
+                                       <a class="btn btn-success" href="<?= $this->e($asset->browser_download_url) ?>">
+                                               <span class="octicon octicon-package"></span>
+                                               <?= $this->e($asset->name) ?>
+                                       </a>
+                               </li>
+                               <?php endif; ?>
+                               <?php endforeach; ?>
+                       </ul>
+               <?php endif; ?>
+                       </div>
+               </div>
        </div>
 </div>
 <?php endforeach; ?>