0

Hello i'm new in Laravel and programming in general.

I'm trying to do an app that tracks the commit history of my team projects on GitHub. I now that `git log` do this but the idea is to put this on a server and access from everywhere without manually executing the command (don't know if this is possible btw).

So, at the moment, for me the solution is to read the atom feed of an user member of the project. The thing is that -for obvious reasons- private repos are not accesible directly. The GitHub documentation says that them can be accessed with basic auth but at the momment i'm unable to do it. I've tried to test in on Postman even with Oath2 creating and app and conceding permissions but don't why it doesn't work.

Btw, sorry for my english. Thanks in advance :)

Dan Lowe
  • 51,713
  • 20
  • 123
  • 112
Kenny Horna
  • 13,485
  • 4
  • 44
  • 71

1 Answers1

0

Github provides a public API for retrieving user events in json format.

If you type this in a (unix) console:

curl https://api.github.com/users/sea-reel/events

…you get a list of my last public commits.

To implement this with Laravel you can simply use file_get_contents() :

Route::get('/commits/{username}', function($username)
{
    $url = "https://username:password@api.github.com/users/{$username}/events";
    $json = json_decode(file_get_contents($url),true);

    dd($json);
});

To also access commits from private repos, you can use one of the various authentication methods provided by Github's API. Here I used basic auth, but you may find more secure to use OAuth and store secret keys instead of raw passwords.

Cyril
  • 3,048
  • 4
  • 26
  • 29