public function add(Request $request, $org, $repo) { // Get the logged in user. $user = $request->user(); // Get a GitHub client. $client = (new GitHub())->getGitHubClient($user); // Get the actual info for the requested repo. try { $repoInfo = $client->api('repos')->show($org, $repo); } catch (Exception $e) { abort(404); } list($org, $repo) = explode('/', $repoInfo['full_name'], 2); // See if we can get the requested repository. $repositoryObject = Repository::firstOrCreate(['organization' => $org, 'name' => $repo]); // Check if the user is linked to this repository. if (empty($user->repositories->find($repositoryObject->id))) { $user->repositories()->attach($repositoryObject->id); } /* $hooksUrl = 'http://laravel-auth/hooks'; // Get a list of all the existing hooks on the repository. $hooks = $client->repository()->hooks()->all($org, $repo); // Search for our own hook. $hookId = null; foreach ($hooks as $hook) { if ($hook['config']['url'] == $hooksUrl) { $hookId = $hook['id']; } } // Create the hook on the repository. $params = [ 'name' => 'web', 'config' => [ 'url' => $hooksUrl, 'content_type' => 'json', ], 'events' => [ 'pull_request', ], 'active' => true, ]; if (!is_null($hookId)) { $client->repository()->hooks()->update($org, $repo, $hookId, $params); } else { $client->repository()->hooks()->create($org, $repo, $params); } */ return view('repositories.add')->with(['organization' => $org, 'repository' => $repo]); }
/** * Display the commits of a given repository */ public function anyCommits(Request $request) { // Repository input $user = $request->get('user', 'nodejs'); $repository = $request->get('repository', 'node'); // Pagination input $page = $request->get('page', 1); $perPage = $request->get('perPage', 20); if ($perPage > 100) { $perPage = 100; } // Cache key $key = sprintf('repository-commits-%s-%s-%s-%s', $user, $repository, $page, $perPage); // Fetch from or generate cache and return $commits = Cache::remember($key, 300, function () use($user, $repository, $page, $perPage) { $repo = Repository::firstOrCreate(['user' => $user, 'repository' => $repository]); return $repo->fetchCommits($perPage); }); // Return result return $commits; }