Skip to content

Instantly share code, notes, and snippets.

@mojavelinux
Created February 15, 2012 22:33
Show Gist options
  • Select an option

  • Save mojavelinux/1839526 to your computer and use it in GitHub Desktop.

Select an option

Save mojavelinux/1839526 to your computer and use it in GitHub Desktop.
Create report of JBoss Community project leads
/**
* This script generates a list all the project leads of JBoss Community projects, and the
* projects which they lead, using the issue tracker as the information authority.
*
* TIP: Increase TTL in ~/.groovy/grapeConfig.xml to speed up Groovy Grapes:
*
* <ivysettings>
* <property name="ivy.cache.ttl.default" value="1440m"/>
* ...
* </ivysettings>
*/
@Grab(group='org.codehaus.groovy.modules.http-builder', module='http-builder', version='0.5.2')
import groovyx.net.http.RESTClient
import groovy.xml.MarkupBuilder
@Grab(group='commons-lang', module='commons-lang', version='2.4')
import org.apache.commons.lang.StringEscapeUtils
class Lead {
String username
String name
String lastName
String instance
String toString() {
"${name} (${username})"
}
}
class Project {
String key
String name
Lead lead
String toString() {
"${name} (${key}) led by ${lead.name}"
}
}
String JBOSS_REST_API_ROOT = 'http://issues.jboss.org/rest/api/2.0.alpha1/'
String JBOSS_GADGET_REST_API_ROOT = 'https://issues.jboss.org/rest/gadget/1.0/'
def jbossExcludeCats = [10101, 10102, 10010, 10030, 10091]
String HIBERNATE_REST_API_ROOT = 'http://hibernate.onjira.com/rest/api/2.0.alpha1/'
String HIBERNATE_GADGET_REST_API_ROOT = 'http://hibernate.onjira.com/rest/gadget/1.0/'
def hibernateActiveCat = 10030
def cli = new CliBuilder(usage: "projectleads")
// Pull from JBoss Issue Tracker
def jbossRest = new RESTClient(JBOSS_REST_API_ROOT)
def res = jbossRest.get(
path: 'project')
def keys = []
res.data.each {
if (!(it.key.startsWith('SEAM') && it.key != 'SEAM') &&
!(it.key.startsWith('WELD') && it.key != 'WELD') &&
it.key != 'JBTP' && it.key != 'EJBBOOK' && !it.name.contains('Planning')) {
keys.add(it.key)
}
}
res = new RESTClient(JBOSS_GADGET_REST_API_ROOT).get(
path: 'project/generate',
query: [projectsOrCategories: jbossExcludeCats.collect { "cat${it}" }.join('|')]
)
res.data.categories.each { c ->
c.projects.each { p ->
keys.remove(p.key)
}
}
def leads = [:]
keys.each {
res = jbossRest.get(
path : "project/${it}")
def data = res.data
def l = new Lead(username: data.lead.name, name: data.lead.displayName,
lastName: data.lead.displayName.substring(data.lead.displayName.indexOf(' ') + 1),
instance: 'jboss')
// middle name hack
if (l.lastName.startsWith('de ')) {
l.lastName = l.lastName.substring(3)
}
else if (l.lastName.startsWith('Rydahl ')) {
l.lastName = l.lastName.substring(7)
}
def p = new Project(key: data.key, name: data.name, lead: l)
if (p.name.startsWith('Seam 3')) {
p.name = 'Seam 3'
}
if (!leads.containsKey(l.username)) {
leads[l.username] = [lead: l, projects: [p]]
}
else {
leads[l.username].projects.add(p)
}
}
// Pull from Hibernate Issue Tracker
keys = []
res = new RESTClient(HIBERNATE_GADGET_REST_API_ROOT).get(
path: 'project/generate',
query: [projectsOrCategories: "cat${hibernateActiveCat}"]
)
res.data.categories.each { c ->
c.projects.each { p ->
keys.add(p.key)
}
}
def hibernateRest = new RESTClient(HIBERNATE_REST_API_ROOT)
keys.each {
res = hibernateRest.get(
path : "project/${it}")
def data = res.data
def l = new Lead(username: data.lead.name, name: data.lead.displayName,
lastName: data.lead.displayName.substring(data.lead.displayName.indexOf(' ') + 1),
instance: 'hibernate')
// middle name hack
if (l.lastName.startsWith('Rydahl ')) {
l.lastName = l.lastName.substring(7)
}
def p = new Project(key: data.key, name: data.name, lead: l)
if (!leads.containsKey(l.username)) {
leads[l.username] = [lead: l, projects: [p]]
}
else {
leads[l.username].projects.add(p)
}
}
leads.values().sort { a, b -> a.lead.lastName.toLowerCase() <=> b.lead.lastName.toLowerCase() }.each {
def projects = it.projects.collect { it.name }
println "${it.lead} leads ${projects}"
}
@LightGuard
Copy link

Haha, interesting how we both approach things differently. I would have simply done it in ruby and read in the JSON response and used that :) Though my ruby is rusty.

@mojavelinux
Copy link
Author

mojavelinux commented Feb 16, 2012 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment