GitHub API: Repositories Contributed To

后端 未结 10 1732
耶瑟儿~
耶瑟儿~ 2020-12-07 09:45

Is there a way to get access to the data in the “Repositories contributed to” module on GitHub profile pages via the GitHub API? Ideally the entire list, not just the top fi

相关标签:
10条回答
  • 2020-12-07 10:27

    Using Google BigQuery with the GitHub Archive, I pulled all the repositories I made a pull request to using:

    SELECT repository_url 
    FROM [githubarchive:github.timeline]
    WHERE payload_pull_request_user_login ='rgbkrk'
    GROUP BY repository_url;
    

    You can use similar semantics to pull out just the quantities of repositories you contributed to as well as the languages they were in:

    SELECT COUNT(DISTINCT repository_url) AS count_repositories_contributed_to,
           COUNT(DISTINCT repository_language) AS count_languages_in
    FROM [githubarchive:github.timeline]
    WHERE payload_pull_request_user_login ='rgbkrk';
    

    If you're looking for overall contributions, which includes issues reported use

    SELECT COUNT(DISTINCT repository_url) AS count_repositories_contributed_to,
           COUNT(DISTINCT repository_language) AS count_languages_in
    FROM [githubarchive:github.timeline]
    WHERE actor_attributes_login = 'rgbkrk'
    GROUP BY repository_url;
    

    The difference there is actor_attributes_login which comes from the Issue Events API.

    You may also want to capture your own repos, which may not have issues or PRs filed by yourself.

    0 讨论(0)
  • 2020-12-07 10:33

    I tried implementing something like this a while ago for a Github summarizer... My steps to get the repositories the user contributed to, which they didn't own, was as follows (going to use my own user as an example):

    • Search for that last 100 closed pull requests the user submitted. Of course you could request the second page if the first page is full to get even older prs

    https://api.github.com/search/issues?q=type:pr+state:closed+author:megawac&per_page=100&page=1

    • Next I would request each of these repos contributors. If the user in question is in the contributors list we add the repo to the list. Eg:

    https://api.github.com/repos/jashkenas/underscore/contributors

    • We might also try checking all the repos the user is watching. Again we would check each repos repos/:owner/:repo/contributors

    https://api.github.com/users/megawac/subscriptions

    • In addition I would iterate all the repos of the organizations the user is in

    https://api.github.com/users/megawac/orgs
    https://api.github.com/orgs/jsdelivr/repos

    • If the user is listed as a contributor to any of the repos there we add the repo to the list (same step as above)

    This misses repos where the user has submitted no pull requests but has been added as a contributor. We can increase our odds of finding these repos by searching for

    1) any issue opened (not just closed pull requests)
    2) repos the user has starred

    Clearly, this requires many more requests than we would like to make but what can you do when they make you fudge features \o/

    0 讨论(0)
  • 2020-12-07 10:33

    As of now GitHub API v3, doesn't provide a way to get the user's current streak.

    You may use this to calculate the current streak.

    https://github.com/users/<username>/contributions.json
    
    0 讨论(0)
  • 2020-12-07 10:36

    There is a new project that claims to list all contributions:

    https://github.com/AurelienLourot/github-contribs

    It also backs a service to produce more detailed user profiles:

    https://ghuser.io/

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