Skip to content

Instantly share code, notes, and snippets.

@davidpelayo
Last active September 22, 2015 08: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 davidpelayo/de4181e93584df7443c9 to your computer and use it in GitHub Desktop.
Save davidpelayo/de4181e93584df7443c9 to your computer and use it in GitHub Desktop.
Jobs generator based on forks of a certain github repo
//thanks to https://gist.github.com/joshareed/5706061
import groovy.json.JsonSlurper
def owner = "<owner>"
def project = "<project>"
// curl -k -u <user>:<token> -X GET https://api.github.com/repos/<owner>/<repo>/forks > forks.txt
def fetch(addr, params = [:]) {
def auth = "<personalAPIToken>" // see https://github.com/blog/1509-personal-api-tokens
def json = new JsonSlurper()
return json.parse(addr.toURL().newReader(requestProperties: ["Authorization": "token ${auth}".toString(), "Accept": "application/json"]))
}
def forks = fetch("https://api.github.com/repos/${owner}/${project}/forks")
forks.each {
def fork = it.full_name
def name = it.owner.login
def jobName = "${project}-${name}".replaceAll('/','-')
job(jobName) {
scm {
git {
remote {
github(fork, 'https')
credentials('<idCredentials>')
}
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment