Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
retrieves my starred repos from Github v3 API and stores them in HSQL
@GrabResolver(name='gstorm', root='')
@GrabConfig(systemClassLoader = true) @Grab('gstorm:gstorm:0.6')
import gstorm.*
import groovy.json.*
@Grab(group='org.codehaus.groovy.modules.http-builder', module='http-builder', version='0.7.1')
@GrabExclude(group='xerces', module='xercesImpl')
import static
@Grab(group='commons-io', module='commons-io', version='2.3')
class Repo {
String starred_at, name, full_name, html_url, language, default_branch
int stargazers_count
def g = new Gstorm("/Volumes/RamDiskCache/starred")
def repo_fields = ["name" , "full_name" , "html_url" , "language" , "stargazers_count" , "default_branch"]
def user = args[0], page = 1, json = [], token = args[1]
println "fetching data from github account of ${user}"
while (json = new groovy.json.JsonSlurper().parseText(IOUtils.toString(new"${page++}&per_page=100")
.get(contentType: TEXT, headers: ["Authorization": "token ${token}", "Accept": "application/", "User-Agent": "Mozilla/5.0"])))) {
json.collect { println; r = new Repo(it.repo.subMap(repo_fields) + it.subMap(["starred_at"])); println "${} ${r.starred_at}"; }
println ""
println "Your Starred Repo's Summary"
println "="*80
// some methods are available on the class
println "Total starred Repos: " +
println "Number of Repos with more than 100 stars:" +
Repo.count("stargazers_count > 100")
// little more advanced stuff, still do'able with gstorm
println "20 top starred java repos :" +
Repo.where("language like 'Java' order by stargazers_count desc limit 20").collectEntries { [, it.stargazers_count]}
println "various default branch names that peopl use:" +
g.sql.rows("select distinct(default_branch) from repo").collect{it.default_branch}.join(", ")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment