Example #1
0
function auth() {
  var user = argv._[0]
  ghauth(authOptions, function (err, authData) {
    if (err) return console.error(err)
    child.exec('git config --get remote.origin.url', function(err, stdo, stde) {
      if (err || stdo.toString() === '') return console.error('Error: Could not read git remote origin from current directory')
      var parts = stdo.toString().split('/')
      var repo = parts[parts.length - 1].split('.git')[0].trim()
      collaborator(authData.token, user, repo, function(err, collaborators) {
        if (err) return console.error('Error: ' + (err.message || err))
        var collabs = collaborators.map(function(c) { return {'username': c.login, 'avatar': c.avatar_url }})

        var out = '## Collaborators\n\n'
          + repo + ' is only possible due to the excellent work of the following collaborators:\n\n'
          + makeTable(collabs)
          
        console.log(out)
      })
    })
    if(argv.npm) {
      findNPM(authData.token, user, function (err, npmName) {
        if (err) return console.error('Could not determine npm name (' +err.message+')')
        if (!npmName) return console.error('Could not determine npm name')
        child.exec('npm owner add ' + npmName + ' --quiet', function (err, stdo, stde) {
          if(err || stde.toString() != '') return console.log('Error: Could not add ' + npmName + ' on npm')
          child.exec('npm ls', function (err, stdo, stde) {
            var moduleName = stdo.toString().split('@')[0]
            console.error('Added ' + npmName + ' to module ' + moduleName)
          })
        })
      })
    }
  })
}
Example #2
0
    github : function() {

        // Authentication
        ghauth({
            configName: "nwjs-release",
            scopes: ['repo', 'public_repo'],
            note: "Allows nwjs-release to publish and upload releases",
            userAgent: "nwjs-release"
        }, function(err, data){

            // If there is an error, show the user
            if (err){
                console.log(err.data.message);
                process.exit(1);
            }

            // Set the token
            release.config.token = data.token;

            // Get the initial version
            release.version.read();

        });

    },
function collectCommitLabels (list, callback) {
  var sublist = list.filter(function (commit) {
    return typeof commit.ghIssue == 'number' && commit.ghUser && commit.ghProject
  })

  if (!sublist.length)
    return setImmediate(callback)

  ghauth(authOptions, function (err, authData) {
    if (err)
      return callback(err)
    var q = async.queue(function (commit, next) {
      function onFetch (err, issue) {
        if (err) {
          console.error('Error fetching issue #%s: %s', commit.ghIssue, err.message );
          return next()
        }

        if (issue.labels)
          commit.labels = issue.labels.map(function (label) { return label.name })
        next()
      }

      if (commit.ghUser == 'iojs')
        commit.ghUser = '******' // forcably rewrite as the GH API doesn't do it for us

      ghissues.get(authData, commit.ghUser, commit.ghProject, commit.ghIssue, onFetch)
    }, 15)
    q.drain = callback
    q.push(sublist)
  })
}
Example #4
0
module.exports.auth = function(opt, cb) {
  auth(opt, function(err, data) {
    if (err) return cb(err)
    github.authenticate({
      type: 'oauth',
      token: data.token
    })
    cb(null, data)
  })
}
Example #5
0
exports.sync = function(packageMarkdown, done) {
  const repos = categoriesToRepos(parseCategories(packageMarkdown))

  ghauth({
    configName: 'ecosystem-docs',
    userAgent: 'ecosystem-docs',
    scopes: ['user']
  }, function(err, auth) {
    if (err) return done(err)

    sync(repos, {
      data: dataLocation,
      token: auth.token
    }, done)
  })
}
function collectCommitLabels (list, callback) {
  var sublist = list.filter(function (commit) {
    return typeof commit.ghIssue == 'number' && commit.ghUser && commit.ghProject
  })

  if (!sublist.length)
    return setImmediate(callback)

  ghauth(authOptions, function (err, authData) {
    const cache = {}

    if (err)
      return callback(err)
    var q = async.queue(function (commit, next) {
      function onFetch (err, issue) {
        if (err) {
          console.error('Error fetching issue #%s: %s', commit.ghIssue, err.message );
          return next()
        }

        if (issue.labels)
          commit.labels = issue.labels.map(function (label) { return label.name })
        next()
      }

      if (commit.ghUser == 'iojs')
        commit.ghUser = '******' // forcably rewrite as the GH API doesn't do it for us

      // To prevent multiple simultaneous requests for the same issue
      // from hitting the network at the same time, immediately assign a Promise
      // to the cache that all commits with the same ghIssue value will use.
      const key = `${commit.ghUser}/${commit.ghProject}#${commit.ghIssue}`
      cache[key] = cache[key] || new Promise((resolve, reject) => {
        ghissues.get(authData, commit.ghUser, commit.ghProject, commit.ghIssue, (err, issue) => {
          if (err) return reject(err)
          resolve(issue)
        })
      })
      cache[key].then(val => onFetch(null, val), err => onFetch(err))
    }, 15)
    q.drain = callback
    q.push(sublist)
  })
}
			env.load('core', function(err, values){

				values = values || {}

				ghauth(authOptions, function (err, authData) {

					async.forEachSeries(props, function(prop, nextProp){

						if(prop.section){
							return nextProp()
						}
						else if(prop.env){
								
							read({
								prompt: prop.title + ':',
								default: values[prop.env] || prop.default
							}, function (err, val) {
								values[prop.env] = val
								nextProp()
							})							
						}
						else{
							return nextProp()
						}



					}, function(err){

						values.GITHUB_USER = authData.user
						values.GITHUB_TOKEN = authData.token

						env.save('core', values, function(){
							console.dir(values)
						})

					})
				  
				})

			})		
Example #8
0
function fetchAvatar (collaborator, callback) {
  ghusers.get(authData, collaborator.handle, (err, data) => {
    if (err)
      return callback(err)

    collaborator.avatar = data.avatar_url
    callback(null, collaborator)
  })
}


ghauth({ configName: 'collaborator-table' }, (err, _authData) => {
  if (err)
    throw err

  authData = _authData
  compile()
})


function compile () {
  fetch(readme, (err, data) => {
    if (err)
        throw err

    let collaborators = data.toString().match(new RegExp(collabRe.source, 'gm')).map((c) => {
      let m = c.match(collabRe)
      return { handle: m[1], name: m[2] }
    })
function kickOff(err) {
  if (err) throw err

  ghauth({
    configName: 'unpm',
    scopes: ['user'],
    note: 'npm data aggregation project',
    userAgent: 'unpm'
  }, function(err, authData) {
    if (err) throw err

    var stars = []
    var count = 0

    token = authData.token

    fs.createReadStream(path.join(__dirname, 'data', '_downloads.json'))
      .pipe(json.parse([true]))
      .pipe(rapid(100, grabMeta))
      .pipe(rapid(20, grabStars))
      .on('data', function(row) {
        console.log((100*(count++)/256/128).toFixed(3) + '%', row.name)
        stars.push(row)
      })
      .once('end', function() {
        fs.writeFileSync(path.join(__dirname, 'data', '_stars.json'), JSON.stringify(stars))
      })
  })

  function grabMeta(row, _, next) {
    dat.get(row.name, next)
  }

  function grabStars(pkg, _, next) {
    if (pkg._deleted) return next()
    if (!pkg['dist-tags']) return next()
    if (!pkg['dist-tags'].latest) return next()
    if (!pkg.key.indexOf('_design/')) return next()

    var name = pkg.name

    dates.get(name, function(err, date) {
      if (err) return ping(pkg)

      var since = Date.now() - new Date(date)
      if (since > WEEK * 99) return ping(pkg)

      counts.get(name, function(err, count) {
        if (err) return ping(pkg)

        next(null, {
          name: name,
          count: count
        })
      })
    })

    function ping(pkg) {
      pkg._id = pkg.name
      pkg.version = pkg['dist-tags'].latest
      pkg.repository = pkg.repository || {}

      var uri = typeof pkg.repository === 'string'
        ? pkg.repository
        : pkg.repository.type === 'git' && pkg.repository.url

      if (!uri) return submit(0)

      var info = gitInfo.fromUrl(uri)
      if (!info) return submit(0)
      if (info.type !== 'github') return submit(0)

      request.get('https://api.github.com/repos/'+info.user+'/'+info.project, {
        json: true,
        headers: {
          'Authorization': 'token ' + token,
          'User-Agent': 'unpm'
        }
      }, function(err, res, body) {
        if (err) return next(err)

        var reset  = parseInt(res.headers['x-ratelimit-reset'], 10) * 1000 || Date.now()
        var remain = parseInt(res.headers['x-ratelimit-remaining'], 10)
        var delay  = (reset - Date.now()) / remain

        delay = remain < 1500 ? delay * 30 : delay * 10

        console.log('retrieved:', name, '('+(body && body.stargazers_count)+')')
        console.log('remaining:', remain)
        console.log('limit delay:', delay)

        setTimeout(function() {
          if (err) return next(err)
          if (!body) return submit(0)
          if ('stargazers_count' in body) {
            return submit(body.stargazers_count)
          }

          if (body.message === 'Not Found') {
            return submit(0)
          }

          return next(new Error(body.message))
        }, delay)
      })

      // next()
      // request.get('https://api.github.com/repos/')
    }

    function submit(count) {
      counts.put(name, count, function(err) {
        if (err) return next(err)

        dates.put(name, Date.now(), function(err) {
          if (err) return next(err)

          next(null, {
            name: name,
            count: count
          })
        })
      })
    }
  }
}
Example #10
0
const ghauth      = require('ghauth')
    , ghrepos     = require('..')
    , authOptions = {
          configName : 'lister'
        , scopes     : [ 'user' ]
      }

ghauth(authOptions, function (err, authData) {
  ghrepos.getCommitComments(authData, 'nodejs', 'node', '75318e46b', function (err, comments) {
    if (err) throw err
    console.log(JSON.stringify(comments.map(function (i) {
      return { user: i.user.login, body: i.body }
    }), null, 2))
  })
})
ghAuth({
  configName: 'portfolios',
  scopes: ['user', 'repo']
}, (err, data) => {
  if (err) throw err

  if (argv.defaults) {
    var defFile = path.isAbsolute(argv.defaults)
      ? argv.defaults
      : path.resolve(process.cwd(), argv.defaults)
    argv.defaults = JSON.parse(fs.readFileSync(defFile, 'utf8'))
  }

  argv.token = data.token
  scrapeGhDemos(argv._, argv)
    .on('data', repo => {
      if (!repo.demo) {
        console.error('skip  =>', repo.full_name)
      }
    })
    .pipe(mapStream(filter))
    .pipe(argv.bare ? bareRepo() : through.obj())
    .pipe(stringify())
    .pipe(process.stdout)

  function filter (item, next) {
    if (argv.bare && !item.demo) return next()
    return next(null, item)
  }

  function bareRepo () {
    return through.obj(function (repo, enc, next) {
      this.push({ url: repo.demo, repository: repo.html_url, name: repo.name })
      next()
    })
  }
})
Example #12
0
var ghauth = require('ghauth')

var authOptions = {
  configName : 'create-module'

  // (optional) whatever GitHub auth scopes you require
  , scopes     : ['public_repo']

  // (optional) saved with the token on GitHub
  , note       : 'npm create-module module'

  // (optional)
  , userAgent  : 'npm create-module'
}

if(process.argv.length === 2) {
  console.log('Usage: create-module <name>')
  process.exit()
}

var argv = require('minimist')(process.argv.slice(2));

ghauth(authOptions, function (err, authData) {
  if(err) return console.error(err)
  require('./')(process.argv[2], authData.token, argv, function (err) {
    if(err) return console.error(err)
  })

})
  
Example #13
0
#!/usr/bin/env node

var ghauth = require('ghauth');
var ghpages = require('./index.js');

var authOptions = {
	configName: 'gh-pages-bootstrap',
	scopes: ['public_repo'],
	note: 'gh-pages-bootstrap',
	userAgent: 'gh-pages-bootstrap/1.0.0'
};

ghauth(authOptions, function(err, authData) {
	if (err) throw err;
	ghpages(authData.user, authData.token, function(err) {
		throw err;
	});
});
Example #14
0
#!/usr/bin/env node

var ghauth = require('ghauth')
var minimist = require('minimist')
var getIssues = require('./index.js')

var options = minimist(process.argv.slice(2))

var ghAuthOptions = {
 // ~/.config/[configName].json will store the token
configName : 'offline-issues',
// (optional) whatever GitHub auth scopes you require
scopes     : [ 'repo' ],
// (optional) saved with the token on GitHub
note       : 'This token is for the offline-issues module from NPM'
}

ghauth(ghAuthOptions, function(err, token) {
  if (err) console.log(err)
  getIssues(token, options, function(err, message) {
    if (err) console.log(err, message)
    console.log(message)
  })

  // var token = { user: '******',
  // token: 'TOKEN' }
})