How to retrieve the list of all github repositories of a person?

穿精又带淫゛_ 提交于 2019-12-17 10:15:36

问题


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 names of all the git repositories of a particular person using his git-user name?


回答1:


You can use the github api for this. Hitting https://api.github.com/users/USERNAME/repos will list public repositories for the user USERNAME.




回答2:


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.




回答3:


Try the following curl command to list the repositories:

GHUSER=CHANGEME; curl "https://api.github.com/users/$GHUSER/repos?per_page=100" | grep -o 'git@[^"]*'

To list cloned URLs, run:

GHUSER=CHANGEME; curl -s "https://api.github.com/users/$GHUSER/repos?per_page=1000" | grep -w clone_url | grep -o '[^"]\+://.\+.git'

If it's private, you need to add your API key (access_token=GITHUB_API_TOKEN), for example:

curl "https://api.github.com/users/$GHUSER/repos?access_token=$GITHUB_API_TOKEN" | grep -w clone_url

If the user is organisation, use /orgs/:username/repos instead, to return all repositories.

To clone them, see: How to clone all repos at once from GitHub?

See also: How to download GitHub Release from private repo using command line




回答4:


If you have jq installed, you can use the following command to list all public repos of a user

curl -s https://api.github.com/users/<username>/repos | jq '.[]|.html_url'



回答5:


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>



回答6:


The NPM module repos grabs the JSON for all public repos for some user or group. You can run this directly from npx so you don't need to install anything just pick an org or user ("W3C" here):

$ npx repos W3C W3Crepos.json

This will create a file called W3Crepos.json. Grep is good enough to e.g. fetch the list of repos:

$ grep full_name W3Crepos.json

pros:

  • Works with more than 100 repos (many answers to this question don't).
  • Not much to type.

cons:

  • Requires npx (or npm if you want to install it for real).



回答7:


Paging JSON

The JS code below is meant to be used in a console.

username = "mathieucaroff";

w = window;
Promise.all(Array.from(Array(Math.ceil(1+184/30)).keys()).map(p =>
    fetch(`//api.github.com/users/{username}/repos?page=${p}`).then(r => r.json())
)).then(all => {
    w.jo = [].concat(...all);
    // w.jo.sort();
    // w.jof = w.jo.map(x => x.forks);
    // w.jow = w.jo.map(x => x.watchers)
})



回答8:


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.




回答9:


Retrieve the list of all public repositories of a GitHub user using Python:

import requests
username = input("Enter the github username:")
request = requests.get('https://api.github.com/users/'+username+'/reposper_page=1000')
json = request.json()
for i in range(0,len(json)):
  print("Project Number:",i+1)
  print("Project Name:",json[i]['name'])
  print("Project URL:",json[i]['svn_url'],"\n")

Reference




回答10:


To get the user's 100 public repositories's url:

$.getJSON("https://api.github.com/users/suhailvs/repos?per_page=100", function(json) {
  var resp = '';
  $.each(json, function(index, value) {
    resp=resp+index + ' ' + value['html_url']+ ' -';
    console.log(resp);
  });
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>



回答11:


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!');
    }
});


来源:https://stackoverflow.com/questions/8713596/how-to-retrieve-the-list-of-all-github-repositories-of-a-person

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!