Last active
January 7, 2016 11:10
-
-
Save TinyExplosions/d02d2425f0873b75cc07 to your computer and use it in GitHub Desktop.
Some Assembla crawling stuff
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 fs = require('fs'), | |
request = require('request'), | |
spaces = [], | |
AssemblaApiSecret = "<API Secret>", | |
AssemblaApiKey = "<API Key>"; | |
var options = { | |
url: 'https://api.assembla.com/v1/spaces/', | |
headers: { | |
"X-Api-Secret": AssemblaApiSecret, | |
"X-Api-Key": AssemblaApiKey | |
} | |
}; | |
console.log("Getting list of spaces"); | |
request(options, function(error, response, body) { | |
if (!error && response.statusCode == 200) { | |
spaces = JSON.parse(body); | |
var endLength = spaces.length - 1; | |
console.log("Getting Repositories"); | |
for (var i = 0; i <= endLength; i++) { | |
getRepos(i, i === endLength); | |
} | |
} | |
}); | |
function getRepos(i, final) { | |
var spaceId = spaces[i].id; | |
var spaceName = spaces[i].name; | |
var options = { | |
url: 'https://api.assembla.com/v1/spaces/' + spaceId + | |
'/space_tools/repo', | |
headers: { | |
"X-Api-Secret": AssemblaApiSecret, | |
"X-Api-Key": AssemblaApiKey | |
} | |
}; | |
request(options, function(error, response, body) { | |
if (!error && response.statusCode == 200) { | |
var repos = JSON.parse(body); | |
spaces[i].repos = repos; | |
console.log(spaceName, repos.length); | |
fs.writeFileSync('./results.json', JSON.stringify(spaces), 'utf8'); | |
} else if (response.statusCode === 204) { | |
console.log("No repositories associated with the space", spaceName); | |
} else { | |
console.log("Error getting info for space", spaceName); | |
} | |
if (final) { | |
console.log("Finished getting repositories, generating report"); | |
var reportTxt = ""; | |
for (var j = 0; j < spaces.length; j++) { | |
var result = spaces[j]; | |
reportTxt += result.name.trim() + ':\n'; | |
if (result.repos) { | |
for (var k = 0; k < result.repos.length; k++) { | |
reportTxt += '\t' + result.repos[k].url + '\n'; | |
} | |
} else { | |
reportTxt += '\t_no repositories_\n'; | |
} | |
reportTxt += '\n'; | |
} | |
fs.writeFileSync('./report.txt', reportTxt, 'utf8'); | |
console.log("report.tx created"); | |
} | |
}); | |
} |
once we have a list of repos, I'm using the shell script at https://gist.github.com/markrickert/2919901 to archive each one off, it can then be saved to AWS or dropbox or whatever, and restored at a later date.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
to run this...
generate an API Key and API Secret from Assembla (https://www.assembla.com/user/edit/manage_clients), and add them to the script.
npm install request
node AssemblaCrawl.js
This outputs
results.json
which is the full list of spaces and repositories, andreport.txt
which is a human readable list of the Spaces and associated repositories