public static function webhookRegister($id) { $repo = \Apigenci\Model::githubRepo($id)->name; $user = \Apigenci\Model::githubLogin(); $json = \Apigenci\Model\Github::apiPost("repos/{$user}/{$repo}/hooks", trim(' { "name": "web", "active": true, "events": [ "push" ], "config": { "url": "https://apigen.ci/webhook", "content_type": "json", "insecure_ssl": "0" } } ')); }
} \Apigenci\Model\Repo::queueBuild($id); \Apigenci\Model\Github::webhookRegister($id); }); Route::post('repo/{id}/disable', function ($id) { $id = \Apigenci\Model::repoDecodeWeb($id); $repo = \Apigenci\Model\Repo::find($id); \Eloquent::unguard(); $repo->update(['enabled' => 0, 'queued' => 0, 'failed' => 0, 'built' => 0]); \Queue::pushOn('low', new \App\Jobs\Apigenci\DeleteGeneratedHtml($repo)); }); Route::get('github/{owner}/{repo}', function ($owner, $repo) { return view('apigenci.github.invite', ['owner' => $owner, 'repo' => $repo]); }); Route::get('github/{owner}/{repo}/tag/{tag}', function ($owner, $repo, $tag) { // Make sure repo exists, redirect to invite if not if (!\Apigenci\Model::localRepoExists($owner, $repo)) { return \Redirect::away("/github/{$owner}/{$repo}"); } return view('apigenci.github.tag', ['owner' => $owner, 'repo' => $repo, 'tag' => $tag]); }); Route::get('privacy', function () { return view('apigenci.privacy'); }); Route::any('webhook', function () { $raw = file_get_contents('php://input'); $id = json_decode($raw)->repository->id; // Write a log entry \Log::info("[apigen.ci] Got a webhook for repo: {$id}"); \Apigenci\Model\Repo::queueBuild($id); });
/** * * @param type $id * @return type */ public static function run($id) { $local = \Apigenci\Model::dbRepo($id); $login = \Apigenci\Model::dbUser($local->user_id)->login; $nonce = self::nonce(); if (!$local->enabled || !$local->queued) { return; } // Url to the projects source zip $wget = "https://github.com/{$login}/{$local->repo}/archive/master.zip"; // create nonce folder exec("mkdir -p /tmp/{$nonce}"); self::cmd("cd /tmp/{$nonce} ; wget {$wget} --no-check-certificate", $nonce); self::cmd("cd /tmp/{$nonce} ; unzip master.zip", $nonce); $workdir = "/tmp/{$nonce}/{$local->repo}-master"; $options = \Apigenci\Model\Build::apigenOptions($workdir); // Run apigen self::cmd("apigen generate {$options} --destination=/tmp/{$nonce}/apigen", $nonce); // Create the target folder in the webroot $public = base_path("vendor/apigen-ci/apigen-ci/public/github/{$login}/{$local->repo}"); exec("mkdir -p {$public}"); if (!file_exists("/tmp/{$nonce}/apigen/index.html")) { \DB::connection('apigenci')->table('repos')->where('id', $id)->update(['failed' => 2, 'queued' => 0, 'built' => 0]); } else { # copy docs into webroot exec("rsync -a --delete /tmp/{$nonce}/apigen/ {$public}"); // Remove queued and failed flags \DB::connection('apigenci')->table('repos')->where('id', $id)->update(['failed' => 0, 'queued' => 0, 'built' => 1]); } // Copy log into webroot exec("rsync -a /tmp/{$nonce}/log {$public}/log.txt"); // Output time into finished dir file_put_contents("{$public}/date.txt", mysqltime()); // Delete nonce folder and cache folders exec("rm -rf /tmp/{$nonce}"); exec('rm -rf /tmp/_apigen'); }
<!DOCTYPE HTML> <?php $uri = $_SERVER['REQUEST_URI']; $pages = []; $pages['/'] = \Apigenci\Model::githubLogin() ?: 'Home'; if (\Session::has('token')) { #$pages['/orgs'] = 'Organizations'; } $pages['/docs'] = 'Documentation'; #if (\Session::has('token')) { # $pages['/account'] = 'Account'; #} ?> <html lang="en"> <head> <meta charset="utf-8"> <meta name="csrf-token" content="{{ csrf_token() }}"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1"> <title>@yield('title')</title> <link rel="stylesheet" href="//maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css"> <link rel="stylesheet" href="//maxcdn.bootstrapcdn.com/font-awesome/4.2.0/css/font-awesome.min.css"> <!-- HTML5 Shim and Respond.js IE8 support of HTML5 elements and media queries --> <!-- WARNING: Respond.js doesn't work if you view the page via file:// --> <!--[if lt IE 9]> <script src="https://oss.maxcdn.com/html5shiv/3.7.2/html5shiv.min.js"></script> <script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script> <![endif]--> <script src="//code.jquery.com/jquery.js"></script> <script src="//maxcdn.bootstrapcdn.com/bootstrap/3.2.0/js/bootstrap.min.js"></script> <script>
} @keyframes spin { from { transform: scale(1) rotate(0deg);} to { transform: scale(1) rotate(360deg);} } </style> <?php $localRepos = \Apigenci\Model::dbUserRepos(\Apigenci\Model::githubId()); ?> @foreach($repos as $repo) <?php $encrypted = \Apigenci\Model::repoEncodeWeb($repo->id); $localRepo = \Apigenci\Model::dbRepo($repo->id, $localRepos); ?> <div class="container"> <div class="row"> <div class="col-lg-12"> <div class="repolist panel panel-default"> <div class="panel-body"> <div class="floatLeft"> <a target="_blank" href="{{ $repo->html_url }}"><img src="/images/github32px.png" /></a> {{ \Session::get('user')->login }} / <span class="repoName">{{ $repo->name }}</span> @if (is_object($localRepo) && $localRepo->queued) <span class="glyphicon glyphicon-refresh glyphicon-refresh-animate"></span> @endif </div>