UNPKG

tooljs-github

Version:

Tooling to create GitHub repo.

48 lines (39 loc) 1.08 kB
/** * Module dependencies. */ var tool = require('tooljs-tool'); var api = require('superagent'); /** * Default token. */ var user = process.env.GITHUB_USER; var token = process.env.GITHUB_TOKEN; /** * Expose `GitHub`. */ var Github = module.exports = tool('github') .option('org', { type: 'string', required: true }) .option('repo', { type: 'string', required: true }) .option('description', { type: 'string' }) .attr('user', { type: 'string', required: true, value: token }) .attr('token', { type: 'string', required: true, value: token }) .attr('url', { type: 'string', value: 'https://api.github.com/orgs/{{ org }}/repos' }) .attr('auth', { type: 'string', value: 'token {{ token }}' }); /** * Create the GitHub repo. * * @param {Function} next * @api public */ Github.prototype.exec = function(next){ var url = this.url; var auth = this.auth; var name = this.repo; api.post(url) .set('Authorization', auth) .send({ name: name }) .end(function(res){ if (res.error) return next(res.text); next(); }); };