async function ghAPI()

in build/generate-contributors.js [63:87]


async function ghAPI() {
  const GH_COMMITS_URL = 'https://api.github.com/repos/apache/echarts-handbook/commits?path='
  const total = paths.length
  const tasks = new Array(total)
  for (let i = 0; i < total; ++i) {
    ((i) => {
      const path = paths[i].slice(2)
      tasks[i] = fetch(GH_COMMITS_URL + path)
        .then(response => response.json())
        .then(commits => {
          const contributors = {}
          commits.forEach(({ author: { login } }) => {
            contributors[login] = (contributors[login] || 0) + 1
          })
          entries[path] = Object.keys(contributors)
            .sort((a, b) => contributors[b] - contributors[a])
        })
        .catch(e => {
          console.error('failed to fetch contributors of path', path, e)
        })
    })(i)
  }
  await Promise.allSettled(tasks)
  Object.keys(entries).length && writeToFile()
}