public function getRepo() { if (file_exists($this->git_dir)) { $this->recursiveRemoveDirectory($this->git_dir); } $repo = Gitonomy\Git\Admin::cloneTo($this->git_dir, $this->git_url, false); $tags = $repo->getReferences()->getTags(); /** * If no tags, use master */ if (empty($tags)) { $commitHash = $repo->getReferences()->getBranch('master')->getCommitHash(); } else { rsort($tags); $commitHash = $tags[0]->getCommitHash(); } if ($commitHash === $this->info["last_commit"]) { // No need of update return true; } $sql = \Lobby\DB::getDBH()->prepare("UPDATE `git_cache` SET `last_commit` = ? WHERE `git_url` = ?"); $sql->execute(array($commitHash, $this->git_url)); $this->recursiveRemoveDirectory($this->git_dir . "/.git"); /** * Get screenshots */ $manifest = json_decode(file_get_contents($this->git_dir . "/manifest.json"), true); // Manifest file is invalid if (!is_array($manifest)) { return false; } if (isset($manifest["version"])) { $latestVersion = $manifest["version"]; } else { return false; } if (isset($manifest->screenshots)) { $screenshots = array(); foreach ($manifest["screenshots"] as $img) { $url = parse_url($img); if ($url["host"] === "i.imgur.com") { $path = $url["path"]; // $path has slash at beginning $headers = @get_headers("http://i.imgur.com{$path}", 1); if ($headers[0] === "HTTP/1.1 200 OK") { $screenshots[] = "//i.imgur.com{$path}"; } } } if (empty($screenshots)) { unset($screenshots); } } if (exec("cd {$this->git_dir};zip -r '{$this->git_dir}/app.zip' ./ -1 -q;") !== false) { $logo = true; if (file_exists($this->git_dir . "/src/image/logo.svg")) { $this->convertLogoToPNG(); } else { if (file_exists($this->git_dir . "/src/image/logo.png")) { copy($this->git_dir . "/src/image/logo.png", $this->git_dir . "/logo.png"); } else { $logo = false; } } $webdavPass = getenv("SKY_WEBDAV_PASS"); $settings = array('baseUri' => "https://sky-phpgeek.rhcloud.com/remote.php/webdav/Apps/{$this->id}/", 'userName' => 'lobby-apps', 'password' => $webdavPass); $client = new Client($settings); /** * Create folder */ $client->request('MKCOL'); /** * Upload files */ $client->request('PUT', "{$this->id}.zip", file_get_contents($this->git_dir . "/app.zip")); if ($logo) { $client->request('PUT', "logo.png", file_get_contents($this->git_dir . "/logo.png")); } $request = \Requests::post("https://sky-phpgeek.rhcloud.com/ocs/v1.php/apps/files_sharing/api/v1/shares?format=json", array("Content-Type" => "application/x-www-form-urlencoded"), array("path" => "Apps/{$this->id}", "shareType" => "3"), array("auth" => array("lobby-apps", $webdavPass))); $response = json_decode($request->body); $this->cloud_id = $response->ocs->data->token; $extraColumnData = array("short_description" => $manifest["short_description"]); if (isset($latestVersion)) { $extraColumnData["version"] = $latestVersion; } if (isset($screenshots)) { $extraColumnData["screenshots"] = implode("\n", $screenshots); } if (isset($manifest["require"]) && is_array($manifest["require"])) { $extraColumnData["requires"] = json_encode($manifest["require"]); } /** * Update Cloud ID and download file size */ $appInfoUpdate = array(":cloudID" => $this->cloud_id, ":downloadSize" => filesize($this->git_dir . "/app.zip"), ":appID" => $this->id); $extraColumns = ""; if (!empty($extraColumnData)) { foreach ($extraColumnData as $k => $v) { $extraColumns .= ", {$k} = :{$k}"; $appInfoUpdate[":{$k}"] = $v; } } $sql = \Lobby\DB::getDBH()->prepare("UPDATE `apps` SET `cloud_id` = :cloudID, `download_size` = :downloadSize, `updated` = NOW() {$extraColumns} WHERE `id` = :appID"); $sql->execute($appInfoUpdate); $this->recursiveRemoveDirectory($this->git_dir); return true; } return false; }
$repo = 'repos/' . $font->name . '/'; $github->authenticate(trim(file_get_contents(__DIR__ . '/token.txt')), \Github\Client::AUTH_HTTP_TOKEN); try { print $importer->log($font, 'Creating repository on GitHub…'); $github->api('repo')->create($font->getRepoName(), null, null, true, $importer->baseRepoOrg); } catch (Exception $e) { if ($e->getCode() == 401) { die('Wrong Github credentials!' . PHP_EOL); } elseif ($e->getCode() == 422) { print $importer->log($font, 'Reusing existing repository'); } else { die($e->getMessage() . PHP_EOL); } } print $importer->log($font, 'Updating local repository…'); $repository = Gitonomy\Git\Admin::init($repo, false); try { print $repository->run('remote', array('add', 'origin', $importer->getFontRepoUrl($font))); } catch (Exception $e) { print $repository->run('remote', array('set-url', 'origin', $importer->getFontRepoUrl($font))); } try { print $importer->log($font, $repository->run('pull', array('origin', 'master'))); } catch (Exception $e) { print $importer->log($font, 'Remote repository is empty'); } print $importer->log($font, 'Copying files in ' . $repo . '…'); if (!is_dir($repo)) { mkdir($repo); } array_map('unlink', glob($repo . '/*'));