private function updateAndReturnLatestCommits()
 {
     if ($lastSavedCommit = Commit::orderBy('when', 'desc')->first()) {
         $url = "https://api.github.com/repos/nodejs/node/commits?per_page=25&since=" . gmDate("Y-m-d\\TH:i:s\\Z", strtotime($lastSavedCommit->created_at));
     } else {
         $url = "https://api.github.com/repos/nodejs/node/commits?per_page=25";
     }
     $curl = curl_init();
     curl_setopt($curl, CURLOPT_URL, $url);
     curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
     curl_setopt($curl, CURLOPT_HEADER, false);
     curl_setopt($curl, CURLOPT_USERAGENT, 'Picmonic PHP Test');
     $data = curl_exec($curl);
     $data = json_decode($data);
     curl_close($curl);
     foreach ($data as $commitData) {
         $commit = new Commit();
         $commit->sha = $commitData->sha;
         $commit->name = $commitData->commit->author->name;
         $commit->message = $commitData->commit->message;
         $commit->when = $commitData->commit->committer->date;
         $commit->url = $commitData->commit->url;
         $commit->save();
     }
     return Commit::orderBy('when', 'desc')->take(25)->get();
 }
 /**
  * Grab the latest 25 commits for nodejs/node and save to commits table
  *
  * @return \Illuminate\Http\Response
  */
 public function getCommits()
 {
     //get the latest 25 commits for nodejs/node
     $client = new Client();
     $res = $client->get('https://api.github.com/repos/nodejs/node/commits');
     $commits = json_decode($res->getBody()->getContents());
     //loop through first 25 and save
     $i = 0;
     foreach ($commits as $commit) {
         $insert = Commit::firstOrCreate(['sha' => $commit->sha]);
         $insert->user = $commit->author->login;
         $insert->message = $commit->commit->message;
         $insert->sha = $commit->sha;
         $insert->url = $commit->url;
         $insert->save();
         $i++;
         if ($i >= 25) {
             break;
         }
         //only worry about first 25
     }
     return \Response::json($commits);
     //return $commits;
     //print_r($commits); exit();
 }
Ejemplo n.º 3
0
 public function show($id)
 {
     $m = array(24, 28, 30, 47, 29, 73, 37, 46, 59, 60);
     $k = array(9, 12, 55, 56, 40, 41, 93, 141, 85, 192);
     $user = User::findOrFail($id);
     $comments = Comment::latest('created_at')->paginate(20);
     $commits = Commit::latest('created_at')->get();
     return view('profile.show', compact('user', 'comments', 'commits', 'checkFriend', 'm', 'k'));
 }
Ejemplo n.º 4
0
 /**
  * Fetch and possibly update the repository commits
  */
 public function fetchCommits($perPage = 20)
 {
     if (!$this->fetched_at || $this->fetched_at <= time() - 43200) {
         $commits = GitHub::repo()->commits()->all($this->user, $this->repository, []);
         foreach ($commits as $commit) {
             $c = Commit::firstOrNew(['repository_id' => $this->id, 'sha' => $commit['sha']]);
             $c->committer = $commit['committer']['login'];
             $c->author = isset($commit['author']['login']) ? $commit['author']['login'] : (isset($commit['author']['name']) ? $commit['author']['name'] : (isset($commit['author']['email']) ? $commit['author']['email'] : '(unknown)'));
             $c->url = $commit['html_url'];
             $c->save();
             // TODO: Fetch comments
         }
         $this->update(['fetched_at' => time()]);
     }
     return $this->commits()->paginate($perPage);
 }
Ejemplo n.º 5
0
 public function saveCommits($commitsUrl, $repository)
 {
     //call gitHubClient for get stdObjects
     $commits = $this->ghc->getCommits($commitsUrl);
     // iterate over the array
     foreach ($commits as $commitValue) {
         if (isset($commitValue->commit)) {
             $commit = new Commit();
             $commit->setAuthor($commitValue->commit->author->name);
             $commit->setCommitter($commitValue->commit->committer->name);
             $commit->setMessage($commitValue->commit->message);
             $commit->setRepository($repository);
             // preparing save entity
             $this->em->persist($commit);
         }
     }
     return;
 }
 public function index()
 {
     // grab desired commits array from github. Let's try utilizing "knplabs/github-api": "~1.4" first in composer.json
     $client = new \Github\Client();
     $commits = $client->api('repo')->commits()->all('nodejs', 'node', array('sha' => 'master'));
     $numCommitsToParse = 25;
     $numCurrentCommitBeingParsed = 0;
     // save 25 most recent commits to db
     foreach ($commits as $commit) {
         if ($numCurrentCommitBeingParsed < $numCommitsToParse) {
             // grab new Commit instance
             $cm = new Commit();
             // check to see if commit hash entry already exists
             $cmchk = Commit::where('hash', '=', $commit['sha'])->first();
             // if it does not exist, save->db
             if ($cmchk == null) {
                 $cm->author = $commit['commit']['author']['name'];
                 $cm->hash = $commit['sha'];
                 $cm->msg = $commit['commit']['message'];
                 $cm->date = $commit['commit']['author']['date'];
                 // save to db
                 $cm->save();
                 $numCurrentCommitBeingParsed++;
             }
         }
     }
     /***
      *
      * Yoink 25 most recent commits FROM DB (as specified in coding challenge
      * readme)
      *
      * Normally this functionality would probably live in a method somewhere else --
      * ahhh the joys of having time to refactor :-)
      *
      */
     #$savedCommits = Commit::orderBy('date', 'desc')->take(25)->get();
     // moved 'orderBy' logic in above comment to Commit model scope
     $savedCommits = Commit::dateDescending()->take(25)->get();
     /***
      *
      * Now that we have the 25 most recent commits, we need to check to see if
      * the commit SHA (commits.hash) ends in a number, and if so, color that row
      * to light blue (#E6F1F6)
      *
      * !!!! Scratch that !!!! Let's move this functionality to the index.php angular view
      * where it should live.
      *
      */
     //        foreach ($savedCommits as $savedCommit) {
     //            // if commits.hash ends with num then color row light blue...
     //        }
     // json up the goodies and send 'em to angular
     //return Response::json(Commit::get());
     /***
      * Darn! Looks like Illuminate\Http\Response::json() is belly up.
      * Let's find something else to json encode with. Come on php, you can do it!
      */
     //        return JsonResponse::create($commits);
     //        return JsonResponse::create($tmoo);
     return JsonResponse::create($savedCommits);
 }