Beispiel #1
0
pivotal.getProjects = function(token, done) {
	pt.useToken(token);
	pt.getProjects(function(e, d) {
		if(e) {
			return done(e);
		}
		var projects = [];

		d.project.forEach(function(p) {
			projects.push({ id: p.id, name: p.name });
		});

		done(null, projects);
	});
};
Beispiel #2
0
exports.getProjects = function (req, res) {
  pivotal.getProjects(function (err, projects) {
    res.json(normalizePivotalResponse(projects, 'project'));
    });
};
Beispiel #3
0
	pivotalProject: function (apikey, callback) {
		var rl = readline.createInterface({
			input: process.stdin,
			output: process.stdout
		});

		pivotal.useToken(apikey);

		pivotal.getProjects(function (err, res) { 
			if(err) {
				throw err;
			}

			var projects;

			if(Object.prototype.toString.call( res.project ) === '[object Array]'){
				projects = res.project.map(function (project, index) {
					return {
						index: index + 1,
						id: ~~project.id,
						name: project.name
					}
				});
			}
			else{
				projects = [{
					index: 1,
					id: ~~res.project.id,
					name: res.project.name
				}];
			}

			if(projects.length === 0) {
				throw new Error("No projects found for " + apikey);
			}

			projects.forEach(function (project) {
				rl.write((project.index + ". " + project.name).cyan + '\n');
			});
			
			rl.question("Choose your project: ", function (answer) {
				var choice = ~~answer.trim();
				if(choice < 1 || choice > projects.length) {
					rl.write("Please enter a number between 1 and " + (projects.length) + "\n");
					rl.close();
					ask.pivotalProject(apikey, callback);
				}
				else {
					rl.close();
					exec('git config --local --replace-all pivotal.project "' + projects[choice - 1].id + '"', function (err, stdout, stderr) {
						if(err) {
							callback(new Error("Could not save to git config: " + stderr))
						}
						else {
							callback(null, projects[choice - 1].id);
						}
					});
				}
			});
		});
	},