If I was to go about displaying just MY github repositories and their contents on an external website how would i go about doing this? Are there any source code's you can provide me with, if not point me in the right direction? I'm quite a beginner to programming so any help is appreciated. Thank you everyone. Taking a glance at their website
I glanced over relevant links- but still have no clue how I would accomplish this.
-Github List all Repo's
-Github List all Repo content
How To List All Public Repositories Belonging to a User? So, to list all public repos from a user, send a GET request to https://api.github.com/users/<USER-NAME>/repos , replacing with the actual user from whom you want to retrieve the repositories.
You can use the github api for this. Hitting https://api.github.com/users/USERNAME/repos will list public repositories for the user USERNAME.
To download from GitHub, you should navigate to the top level of the project (SDN in this case) and then a green "Code" download button will be visible on the right. Choose the Download ZIP option from the Code pull-down menu. That ZIP file will contain the entire repository content, including the area you wanted.
There are two ways of looking at github content, the "raw" way and the "Web page" way. raw.githubusercontent.com returns the raw content of files stored in github, so they can be downloaded simply to your computer.
all of the previous answers are great. however if you are looking for a quick and dirty example of how to get a list of publicly available repos then check out my jsfiddle.
which uses this ajax call to list all of a users public repos:
$("#btn_get_repos").click(function() { $.ajax({ type: "GET", url: "https://api.github.com/users/google/repos", dataType: "json", success: function(result) { for(var i in result ) { $("#repo_list").append( "<li><a href='" + result[i].html_url + "' target='_blank'>" + result[i].name + "</a></li>" ); console.log("i: " + i); } console.log(result); $("#repo_count").append("Total Repos: " + result.length); } }); });
to see what kind of data is returned just check the console after clicking the button or you can install Google Chromes JSONView extension and then just visit the url that the ajax request is making i.e. https://api.github.com/users/google/repos
Here is a nice way just with the curl. You should change the $user and the $token variableso to make this script work for your case. The code is tested with a valid token so I hope it will work for you. As you could see in the comments of the code the token could be generated from your github account from here https://github.com/settings/applications
<?php // for example your user $user = 'flesheater'; // A token that you could generate from your own github // go here https://github.com/settings/applications and create a token // then replace the next string $token = 'ced38b0e522a5c5e8ab10'; // We generate the url for curl $curl_url = 'https://api.github.com/users/' . $user . '/repos'; // We generate the header part for the token $curl_token_auth = 'Authorization: token ' . $token; // We make the actuall curl initialization $ch = curl_init($curl_url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); // We set the right headers: any user agent type, and then the custom token header part that we generated curl_setopt($ch, CURLOPT_HTTPHEADER, array('User-Agent: Awesome-Octocat-App', $curl_token_auth)); // We execute the curl $output = curl_exec($ch); // And we make sure we close the curl curl_close($ch); // Then we decode the output and we could do whatever we want with it $output = json_decode($output); if (!empty($output)) { // now you could just foreach the repos and show them foreach ($output as $repo) { print '<a href="' . $repo->html_url . '">' . $repo->name . '</a><br />'; } } ?>
Also since we like github, we should cache the results in the end and fetch them once per day or so.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With