Created
June 25, 2014 06:42
-
-
Save balupton/aef72af134a101a8a5d8 to your computer and use it in GitHub Desktop.
Chainy: Update base files for all repos of multiple github organisations
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var util = require('util') | |
require('chainy').create().require('feed set map exec') | |
.set(['bevry', 'docpad']) | |
.addExtension('pagefeed', 'action', function(url, opts, next){ | |
url = url.replace('PER_PAGE', opts.per_page).replace('PAGE', opts.page) | |
var chain = this | |
var results = [] | |
var fetch = function(page){ | |
chain.create() | |
.set(url) | |
.feed(opts.feedOptions) | |
.done(function(err, result){ | |
// Did we fail requesting the result | |
if ( err ) return next(err) | |
// Do we want to get the results specially? | |
try { | |
if ( opts.getResult ) result = opts.getResult(result) | |
} catch (err) { | |
return next(err) | |
} | |
// Was the results actually an error? | |
if ( util.isError(result) ) { | |
return next(result) | |
} | |
if ( Array.isArray(result) === false ) { | |
err = new Error('result was of an unexpected format') | |
return next(err) | |
} | |
// Result is as expected, push it the results queue | |
results.push.apply(results, result) | |
// We do not have more results | |
if ( result.length !== opts.per_page ) return next(null, result) | |
// We do have more results | |
else repeat(page+1) | |
}) | |
} | |
fetch(opts.page) | |
}) | |
// fetch org repos in parallel | |
.map(function(org, next){ | |
this.create() | |
.set('https://api.github.com//orgs/'+org+'/repos?per_page=PER_PAGE&page=PAGE') | |
.pagefeed({ | |
per_page: 100, | |
page: 1 | |
}) | |
.done(next) | |
}, {concurrency:0}) | |
// convert an array of org repos, to an array of repos | |
.flatten() | |
// do our business on them | |
.each(function(repo, next){ | |
this.create() | |
// clone it out | |
.set('git clone '+repo.clone_url) | |
.exec() | |
// update base files | |
// restore custom entries in .npmignore, .gitignore, and CONTRIBUTING.md | |
// add new badges | |
// npm install projectz | |
// run projects compile | |
// commit it back | |
// push it up as a pull request | |
.done(next) | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment