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; }
public function saveOtherData($search) { // iterate over repositories and set repository entity foreach ($this->repository as $key => $value) { $dateCreatedAt = new \DateTime($value->created_at); $dateUpdatedAt = new \DateTime($value->updated_at); $datePushedAt = new \DateTime($value->pushed_at); $repository = new Repository(); $repository->setName($value->name); $repository->setFullName($value->full_name); $repository->setHtmlUrlUser($value->owner->html_url); $repository->setHtmlUrlRepo($value->html_url); $repository->setDescription($value->description); $repository->setCreatedAt($dateCreatedAt); $repository->setUpdatedAt($dateUpdatedAt); $repository->setPushedAt($datePushedAt); $repository->setCloneUrl($value->clone_url); $repository->setDefaultBranch($value->default_branch); $repository->setSearch($search); // when options is set if ($this->options == 2) { // call save branches $this->saveBranches($value->branches_url, $repository); } elseif ($this->options == 3) { // call save branches $this->saveBranches($value->branches_url, $repository); // call save tags $this->saveTags($value->tags_url, $repository); } elseif ($this->options == 4) { // call save branches $this->saveBranches($value->branches_url, $repository); // call save tags $this->saveTags($value->tags_url, $repository); // call save commits $this->saveCommits($value->commits_url, $repository); } $this->em->persist($repository); } return; }