Version 6.1 by Vincent Massol on 2011/09/20 18:33

cogUses REST and Groovy to integrate with GitHub
TypeSnippet
Category
Developed byUnknown
Rating
0 Votes
LicenseUnknown

Description

Shows how to integrate with GitHub using its REST API, using Groovy to perform the REST calls.

Usage

Use the following content in a wiki page:

{{groovy}}
import groovy.json.*

def url = "http://github.com/api/v2/json/repos/show/xwiki".toURL().text
def root = new JsonSlurper().parseText(url)

println "|=Project|=Description|=Use Wiki?|=Use Issues?"
root.repositories.each() { repo ->
    println "|[[${repo.name}>>http://github.com/xwiki/${repo.name}]]|${repo.description}|${repo.has_wiki}|${repo.has_issues}"
}
{{/groovy}}

Note: If you wish you could also use Groovy's HttpBuilder (although it's more complex but the example shows how to use the Grape's @Grab annotation):

{{cache}}
{{groovy}}
@Grab(group='org.codehaus.groovy.modules.http-builder', module='http-builder', version='0.5.1')
import groovyx.net.http.RESTClient

github = new RESTClient( 'http://github.com/api/v2/json/' )

println "|=Project|=Description|=Use Wiki?|=Use Issues?"
def response = github.get( path : 'repos/show/xwiki' )
response.data.repositories.each() { repo ->
    println "|[[${repo.name}>>http://github.com/xwiki/${repo.name}]]|${repo.description}|${repo.has_wiki}|${repo.has_issues}"
}
{{/groovy}}
{{/
cache}}

Result

github.png

Prerequisites & Installation Instructions

  • If you're using an XWiki version lower than 3.2:
    • Download the Ivy JAR and copy it in your WEB-INF/lib directory. This is needed by the Groovy @Grab directive.
  • If you're using XWiki 3.2+ then you're good to go!
     

Get Connected