We are working on a project where we need to display all the projects of a person in his repository on GitHub account.
Can anyone suggest, how can I display the na
The answer is "/users/:user/repo", but I have all the code that does this in an open-source project that you can use to stand up a web-application on a server.
I stood up a GitHub project called Git-Captain that communicates with the GitHub API that lists all the repos.
It's an open-source web-application built with Node.js utilizing GitHub API to find, create, and delete a branch throughout numerous GitHub repositories.
It can be setup for organizations or a single user.
I have a step-by-step how to set it up as well in the read-me.
const request = require('request');
const config = require('config');
router.get('/github/:username', (req, res) => {
try {
const options = {
uri: `https://api.github.com/users/${req.params.username}/repos?per_page=5
&sort=created:asc
&client_id=${config.get('githubClientId')}
&client_secret=${config.get('githubSecret')}`,
method: 'GET',
headers: { 'user-agent': 'node.js' }
};
request(options, (error, response, body) => {
if (error) console.log(error);
if (response.statusCode !== 200) {
res.status(404).json({ msg: 'No Github profile found.' })
}
res.json(JSON.parse(body));
})
} catch (err) {
console.log(err.message);
res.status(500).send('Server Error!');
}
});
Use the Github API:
/users/:user/repos
This will give you all the user's public repositories. If you need to find out private repositories you will need to authenticate as the particular user. You can then use the REST call:
/user/repos
to find all the user's repos.
To do this in Python do something like:
USER='AUSER'
API_TOKEN='ATOKEN'
GIT_API_URL='https://api.github.com'
def get_api(url):
try:
request = urllib2.Request(GIT_API_URL + url)
base64string = base64.encodestring('%s/token:%s' % (USER, API_TOKEN)).replace('\n', '')
request.add_header("Authorization", "Basic %s" % base64string)
result = urllib2.urlopen(request)
result.close()
except:
print 'Failed to get api request from %s' % url
Where the url passed in to the function is the REST url as in the examples above. If you don't need to authenticate then simply modify the method to remove adding the Authorization header. You can then get any public api url using a simple GET request.
You probably need a jsonp solution:
https://api.github.com/users/[user name]/repos?callback=abc
If you use jQuery:
$.ajax({
url: "https://api.github.com/users/blackmiaool/repos",
jsonp: true,
method: "GET",
dataType: "json",
success: function(res) {
console.log(res)
}
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
Here is a full spec for the repos API:
https://developer.github.com/v3/repos/#list-repositories-for-a-user
GET /users/:username/repos
Query String Parameters:
The first 5 are documented in the API link above. The parameters for page
and per_page
which are documented elsewhere and are useful in a full description.
type
(string): Can be one of all
, owner
, member
. Default: owner
sort
(string): Can be one of created
, updated
, pushed
, full_name
. Default: full_name
direction
(string): Can be one of asc
or desc
. Default: asc
when using full_name
, otherwise desc
page
(integer): Current pageper_page
(integer): number of records per pageSince this is an HTTP GET API, in addition to cURL, you can try this out simply in the browser. For example:
https://api.github.com/users/grokify/repos?per_page=1&page=2
You can use the github api for this. Hitting https://api.github.com/users/USERNAME/repos
will list public repositories for the user USERNAME.