GitHub API: Repositories Contributed To

后端 未结 10 1763
耶瑟儿~
耶瑟儿~ 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: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/

提交回复
热议问题