From 477912857d6bf6322ee19072873eb08c641ccbc3 Mon Sep 17 00:00:00 2001 From: Matthias Kretschmann Date: Tue, 2 Feb 2021 13:34:50 +0100 Subject: [PATCH] tinkering --- README.md | 3 ++- api/networks/github.js | 27 +++++++++++++++++++++------ 2 files changed, 23 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 50a305e..d6d520d 100644 --- a/README.md +++ b/README.md @@ -23,7 +23,8 @@ Endpoint: [`https://oceanprotocol-community.now.sh`](https://oceanprotocol-commu { "github": { "stars": 1000, - "repos": 1000 + "repos": 1000, + "contributors": 1000 }, "medium": { "followers": 1000 diff --git a/api/networks/github.js b/api/networks/github.js index 9d79249..d7628a8 100755 --- a/api/networks/github.js +++ b/api/networks/github.js @@ -24,16 +24,31 @@ export default async function fetchGitHubRepos() { return null } - const json = await response.json() - const numbers = json.map((item) => item.stargazers_count) - const stars = arrSum(numbers) - const repositories = json.length + const jsonRepos = await response.json() + + const starsArray = [] + const contribArray = [] + + jsonRepos.forEach(async (item) => { + starsArray.push(item.stargazers_count) + + const responseContrib = await fetch( + `https://api.github.com/orgs/oceanprotocol/${item.name}/stats/contributors`, + options + ) + const jsonContrib = await responseContrib.json() + contribArray.push(jsonContrib.total) + }) + + const stars = arrSum(starsArray) + const repositories = jsonRepos.length + const contributors = arrSum(contribArray) log( '✓ GitHub. ' + - `Total: ${repositories} public projects with a total of ${stars} stargazers. ` + + `Total: ${repositories} public projects with a total of ${stars} stargazers & ${contributors} contributors. ` + `Elapsed: ${new Date() - start}ms` ) - return { stars, repositories } + return { stars, repositories, contributors } }