start refactoring to promises
[pharext/pharext.org] / app / Github / API.php
index bd28f3ababa56d1bb711a4c32d18e8c69791cc35..8e51489872e106c0ce83e6eb290bcca82a93c72f 100644 (file)
@@ -134,7 +134,7 @@ class API
                ], 0);
        }
 
-       function fetchToken($code, $state, callable $callback) {
+       function fetchToken($code, $state) {
                if (!$this->tokens->get("state", $orig_state, true)) {
                        if (isset($orig_state)) {
                                $this->logger->notice("State expired", $orig_state);
@@ -152,12 +152,12 @@ class API
                        "client_id" => $this->config->client->id,
                        "client_secret" => $this->config->client->secret,
                ]);
-               return $call($callback);
+               return $call();
        }
        
-       function readAuthUser(callable $callback) {
+       function readAuthUser() {
                $call = new API\Users\ReadAuthUser($this);
-               return $call($callback);
+               return $call();
        }
 
        function listRepos($page, callable $callback) {
@@ -241,11 +241,11 @@ class API
                return $call($callback);
        }
 
-       function uploadAssetForRelease($repo, $release, callable $callback) {
-               return $this->listHooks($repo->full_name, function($hooks) use($release, $repo, $callback) {
+       function uploadAssetForRelease($repo, $release, $config, callable $callback) {
+               return $this->listHooks($repo->full_name, function($hooks) use($release, $repo, $config, $callback) {
                        $repo->hooks = $hooks;
                        $hook = $this->checkRepoHook($repo);
-                       $phar = new Pharext\Package($repo->clone_url, $release->tag_name, $repo->name, $hook ? $hook->config : null);
+                       $phar = new Pharext\Package($repo->clone_url, $release->tag_name, $repo->name, $config ?: $hook->config);
                        $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) {
@@ -260,9 +260,9 @@ class API
                });
        }
 
-       function createReleaseFromTag($repo, $tag_name, callable $callback) {
+       function createReleaseFromTag($repo, $tag_name, $config, callable $callback) {
                return $this->createRelease($repo->full_name, $tag_name, function($json) use($repo, $callback) {
-                       $this->uploadAssetForRelease($repo, $json, $callback);
+                       $this->uploadAssetForRelease($repo, $json, $config, $callback);
                });
        }