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

后端 未结 15 1098
一个人的身影
一个人的身影 2020-12-02 05:43

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

相关标签:
15条回答
  • 2020-12-02 06:06

    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)
    })
    
    0 讨论(0)
  • 2020-12-02 06:07

    HTML

    <div class="repositories"></div>
    

    JavaScript

    // Github repos

    If you wanted to limit the repositories list, you can just add ?per_page=3 after username/repos.

    e.g username/repos?per_page=3

    Instead of /username/, you can put any person's username on Github.

    var request = new XMLHttpRequest();
            request.open('GET','https://api.github.com/users/username/repos' , 
            true)
            request.onload = function() {
                var data = JSON.parse(this.response);
                console.log(data);
                var statusHTML = '';
                $.each(data, function(i, status){
                    statusHTML += '<div class="card"> \
                    <a href=""> \
                        <h4>' + status.name +  '</h4> \
                        <div class="state"> \
                            <span class="mr-4"><i class="fa fa-star mr-2"></i>' + status.stargazers_count +  '</span> \
                            <span class="mr-4"><i class="fa fa-code-fork mr-2"></i>' + status.forks_count + '</span> \
                        </div> \
                    </a> \
                </div>';
                });
                $('.repositories').html(statusHTML);
            }
            request.send();
    
    0 讨论(0)
  • 2020-12-02 06:07

    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>

    0 讨论(0)
  • 2020-12-02 06:09

    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'
    
    0 讨论(0)
  • 2020-12-02 06:10

    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

    0 讨论(0)
  • 2020-12-02 06:10

    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+'/repos')
    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

    0 讨论(0)
提交回复
热议问题