text: const { makeRequest } = require('./common')
  const config = require('./config.json')
  
  async function lookup(username) {
    const issues = await makeRequest('https://api.github.com/user/issues?filter=all&sort=created&direction=asc&state=open')
    const counts = {}
  
    issues
      .filter(x => (!x.fork && !x.draft && !x.repository.archived && x.url.indexOf(username) > -1 && x.title !== 'TODO' && x.state === 'open'))
      .forEach(x => {
        if (!counts[x.repository.full_name]) {
          counts[x.repository.full_name] = 0
        }
        counts[x.repository.full_name]++
        console.log('----------')
        console.log(x.repository.full_name)
        console.log(x.created_at)
        console.log(x.title)
        console.log(x.body)
        console.log('----------')
        console.log('\n\n')
      })
  
    console.log('summary:')
    let total = 0
    for (let key in counts) {
      total += counts[key]
      console.log(`${key}: ${counts[key]}`)
    }
  
    return {
      username,
      total
    }
  }
  
  async function main () {
    const result = await Promise.all(config.github.orgs.map(username => {
      return lookup(username)
    }))
  
    console.log(result)
  }
  
  module.exports = {
    main
  }
  
  if (require.main === module) {
    main()
  }
  