Last active
January 29, 2016 19:26
-
-
Save taylorzane/3be1e73a9fbcb3de2ec4 to your computer and use it in GitHub Desktop.
Gives you a list of all starred "One Person Projects" for a particular user. (Projects that only have one contributor.)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
require 'json' | |
require 'net/http' | |
USERNAME = 'YOUR_USERNAME' | |
# ACCESS_TOKEN is not required but Github is pretty swift to rate-limit. | |
# The access token doesn't have to have access to anything. It just removes the rate-limit. | |
# Obviously if you have a private starred repo, it will not show up in your list without | |
# a properly authenticated access token. | |
ACCESS_TOKEN = 'AN_ACCESS_TOKEN' | |
STARRED_URL = "https://api.github.com/users/%<username>s/starred?access_token=#{ACCESS_TOKEN}" | |
CONTRIBUTORS_URL = "https://api.github.com/repos/%<owner_repo>s/contributors?access_token=#{ACCESS_TOKEN}" | |
USERS_URL = "https://api.github.com/users/%<repo_contributor>s?access_token=#{ACCESS_TOKEN}" | |
begin | |
starred_data = JSON.parse Net::HTTP.get URI sprintf STARRED_URL, username: USERNAME | |
rescue | |
puts $! | |
exit(1) | |
end | |
one_contributor_stars = starred_data.select do |star| | |
owner_repo = star['full_name'] | |
begin | |
star_data = JSON.parse Net::HTTP.get URI sprintf CONTRIBUTORS_URL, owner_repo: owner_repo | |
rescue | |
puts $! | |
exit(2) | |
end | |
if star_data.length == 1 | |
true | |
else | |
false | |
end | |
end | |
one_contributor_stars.each do |star| | |
begin | |
contributor_name = JSON.parse Net::HTTP.get URI sprintf USERS_URL, repo_contributor: star['owner']['login'] | |
rescue | |
puts $! | |
exit(3) | |
end | |
puts 'One Contributor Starred Projects:' | |
puts "#{contributor_name['name'] + '(' + star['owner']['login'] + ')' || star['owner']['login']}: #{star['name']}" | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment