Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RFC: Add contributor details to package listing #2078

Merged
merged 1 commit into from
Jan 18, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
97 changes: 72 additions & 25 deletions doc/listpkg.jl
Original file line number Diff line number Diff line change
Expand Up @@ -6,60 +6,55 @@ Pkg.add("JSON")
require("JSON")
end

function gen_listpkg()
local gh_auth
try
try
global gh_auth
gh_auth = ENV["GH_AUTH"]
catch e
catch e
error ("Please provide a Github OAuth Token as environment variable GH_AUTH")
end
end

function gen_listpkg()

Pkg.update()
io=open("packages/packagelist.rst","w+");
print(io, "********************\n Available Packages \n********************\n\n")
cd(julia_pkgdir()) do
for pkg in Metadata.each_package()
for pkg in Pkg.Metadata.each_package()
print(" Processing $(pkg)\n")
url = (Metadata.pkg_url(pkg))
maxv = Metadata.versions([pkg])[end]
url = (Pkg.Metadata.pkg_url(pkg))
maxv = Pkg.Metadata.versions([pkg])[end]
url_reg = r"^(([^:/?#]+):)?(//([^/?#]*))?([^?#]*)(\?([^#]*))?(#(.*))?"
gh_path_reg_git=r"^/(.*)?/(.*)?.git$"
gh_path_reg_http=r"^/(.*)?/(.*)?$"
m=match(url_reg, url)
host=m.captures[4]
path=m.captures[5]
scheme=m.captures[2]
fullname = "Unkown"
avatar = "Not on Github"
desc = "Not provided"
homepage = nothing
html_url = url
user_url = url
u=get_user_details_default()

if ismatch(r"github\.com", host)
m2 = match(gh_path_reg_git, path)
user=m2.captures[1]
repo=m2.captures[2]
u=get_user_details_gh(user)
gh_repo_url = "https://api.github.com/repos/$(user)/$(repo)?access_token=$(gh_auth)"
gh_user_url = "https://api.github.com/users/$(user)?access_token=$(gh_auth)"
gh_contrib_url = "https://api.github.com/repos/$(user)/$(repo)/contributors?access_token=$(gh_auth)"
#print("processing $gh_repo_url")
gh_repo=JSON.parse(readall(download_file(gh_repo_url)))
#print("processing $gh_user_url")
gh_user=JSON.parse(readall(download_file(gh_user_url)))
#Sometimes name is missing, sometimes it is null in the JSON
fullname = get(gh_user, "name", user)
if fullname == nothing; fullname = user; end
avatar = gh_user["avatar_url"]
user_url = gh_user["html_url"]
gh_contrib=JSON.parse(readall(download_file(gh_contrib_url)))


desc = get(gh_repo, "description", "No description provided")
homepage = get(gh_repo, "homepage", nothing)
html_url = gh_repo["html_url"]
end
print(io, "`$(pkg) <$(html_url)>`_\n");
print(io, "_"^(length("`$(pkg) <$(html_url)>`_")) * "\n\n")
print(io, " .. image:: $(avatar)\n :height: 80px\n :width: 80px\n :align: right\n :alt: $(fullname)\n\n")
print(io, " .. image:: $(u[:avatar])\n :height: 80px\n :width: 80px\n :align: right\n :alt: $(u[:fullname])\n :target: $(u[:url])\n\n")
print(io, " Current Version: ``$(maxv.version)``\n\n");
print(io, " $(desc) \n\n")
print(io, " Maintainer: `$(fullname) <$user_url>`_\n\n")
print(io, " Maintainer: `$(u[:fullname]) <$(u[:url])>`_\n\n")

if homepage != nothing && length(chomp(homepage)) > 0
print(io, " More Info: `<$(homepage)>`_ \n\n")
Expand All @@ -68,7 +63,7 @@ function gen_listpkg()
ver_dir = "METADATA/$pkg/versions/$(maxv.version)/requires"
any_ver = "Any Version"
if isfile(ver_dir)
vset = Metadata.parse_requires(ver_dir)
vset = Pkg.Metadata.parse_requires(ver_dir)
if length(vset) > 0
for deps in vset
print(io, " $(deps.package)"); print(io, " "^(15-length(deps.package))); print(io, "$(length(deps.versions)>0 ? deps.versions : any_ver)\n")
Expand All @@ -80,9 +75,61 @@ function gen_listpkg()
print(io, " None\n")
end
print(io, "\n")
end #for

if ismatch(r"github\.com", host)
print(io, " Contributors:\n\n")
for contributor in gh_contrib
c_user = get(contributor, "login", "")
u=get_user_details_gh(c_user)
print(io, " .. image:: $(u[:avatar])\n :height: 40px\n :width: 40px\n")
print(io, " :alt: $(u[:fullname])\n :target: $(u[:url])\n\n")
end #for contributor
end

print(io, "----\n\n")
end #for pkg
end #cd
close(io)
end #function

global user_cache = Dict{String, Dict}()

function get_user_details_default()
u=Dict{Symbol, String}()
u[:login] = "Unknown"
u[:fullname] = "Unknown"
u[:avatar] = "Not provided"
u[:url] = "Not provided"

end

function get_user_details_gh(user)

if !has(user_cache, user)
gh_user_url = "https://api.github.com/users/$(user)?access_token=$(gh_auth)"
gh_user=JSON.parse(readall(download_file(gh_user_url)))
fullname = get(gh_user, "name", user)
if fullname == nothing; fullname = user; end
avatar =
user_url = gh_user["html_url"]

u=Dict{Symbol, String}()

u[:login] = user
u[:avatar] = gh_user["avatar_url"]
#Sometimes name is missing, sometimes it is null in the JSON
if get(gh_user, "name", user) == nothing
u[:fullname] = user
else
u[:fullname] = get(gh_user, "name", user)
end
u[:url] = gh_user["html_url"]

user_cache[user] = u
end

return user_cache[user]

end #function

gen_listpkg()
Loading