Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Some Assembla crawling stuff
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");
}
});
}
@TinyExplosions
Copy link
Author

TinyExplosions commented Jan 7, 2016

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, and report.txt which is a human readable list of the Spaces and associated repositories

@TinyExplosions
Copy link
Author

TinyExplosions commented Jan 7, 2016

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