Skip to content

Instantly share code, notes, and snippets.

@o314
Forked from jiahao/juliacontribmontage.jl
Created October 14, 2020 05:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save o314/4cfb395ca135b0d366e9bf60bdaffe21 to your computer and use it in GitHub Desktop.
Save o314/4cfb395ca135b0d366e9bf60bdaffe21 to your computer and use it in GitHub Desktop.
Creates a photo montage of Julia contributors using ImageMagick
#Working version
using JSON
auth_token= #fill in to access Github API
function getcontribs(owner, repo, auth_token)
#Download information about contributors
page, authors=0, {}
while true #Download every page
page += 1
url="https://api.github.com/repos/$owner/$repo/contributors?page=$(page)&access_token=$(auth_token)"
filename = download(url)
f=open(filename)
authorsonpage = JSON.parse(f)
close(f)
length(authorsonpage) > 0 || break
authors = [authors; authorsonpage]
end
authors
end
authors=getcontribs("JuliaLang", "julia", auth_token)
#Download everyone's gravatars
filenames = Dict()
for author in authors
filenames[author["login"]]=download(author["avatar_url"])
end
# Get info about Julia packages
jl_usr_dir="/Users/jiahao/.julia/v0.3"
Packages = {}
for dir in readdir(string(jl_usr_dir, "/METADATA"))
urlfile = string(jl_usr_dir, "/METADATA/", dir, "/url")
if isfile(urlfile)
f=open(urlfile)
url=readline(f)
close(f)
owner, repo = split(url, '/')[4:5]
repo = split(repo, ".git")[1]
push!(Packages, (owner, repo))
end
end
allpkgauthors={}
for (owner, repo) in Packages
pkgauthors=getcontribs(owner, repo, auth_token)
push!(allpkgauthors, pkgauthors...)
end
allauthlogins = union([(map(x->(x["login"],x["avatar_url"]), y))
for y in (allpkgauthors, authors)]...)
#Download more gravatars
filenames = Dict()
for (login, url) in allauthlogins
haskey(filenames, login) || (filenames[login]=download(url))
end
#Sum commits over all repos
contribcount = Dict()
for author in authors
contribcount[author["login"]] = author["contributions"]
end
for (login, url) in allauthlogins
for author in allpkgauthors
author["login"] == login || continue
if haskey(contribcount, login)
contribcount[login]+= author["contributions"]
else
contribcount[login] = author["contributions"]
end
end
end
contribcounts = collect(contribcount)
#Sort by most commits, then alphabetically
sort!(contribcounts, by=x->(x[2], x[1]), rev=true)
#Compute montage layout
aspectratio = 2//1
ntiles=sqrt(length(contribcounts)/aspectratio)
ntilesx, ntilesy = iceil(aspectratio*ntiles), iceil(ntiles)
#Run ImageMagick's montage command
cmd = `montage`
for (login, contribs) in contribcounts
cmd = `$cmd -label "$login\n($contribs)" $(filenames[login])`
end
cmd = `$cmd -geometry 64x64+16+16 -tile $(ntilesx)x$ntilesy -font Calibri montage.jpg`
run(cmd)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment