tinkering

This commit is contained in:
Matthias Kretschmann 2021-02-02 22:12:57 +01:00
parent 477912857d
commit be2510d552
Signed by: m
GPG Key ID: 606EEEF3C479A91F
1 changed files with 30 additions and 8 deletions

View File

@ -6,16 +6,34 @@ const options = {
headers: { headers: {
// For getting topics, see note on https://developer.github.com/v3/search/ // For getting topics, see note on https://developer.github.com/v3/search/
// Accept: 'application/vnd.github.mercy-preview+json' // Accept: 'application/vnd.github.mercy-preview+json'
Accept: 'application/vnd.github.preview' Accept: 'application/vnd.github.preview',
Authorization: `token ${process.env.GITHUB_TOKEN}`
} }
} }
function getContributors(contributors) {
const totalArray = contributors
// filter out duplicate contribution objects based on author.login
.reduce((accumalator, current) => {
if (
!accumalator.some((item) => item.author.login === current.author.login)
) {
accumalator.push(current)
}
return accumalator
}, [])
.map((item) => item.total)
console.log(totalArray)
return arrSum(totalArray)
}
// //
// Fetch all public GitHub repos // Fetch all public GitHub repos
// //
export default async function fetchGitHubRepos() { export default async function fetchGitHubRepos() {
const url = const url =
'https://api.github.com/orgs/oceanprotocol/repos?type=public&per_page=200' 'https://api.github.com/orgs/oceanprotocol/repos?type=public&per_page=100'
const start = Date.now() const start = Date.now()
const response = await fetch(url, options) const response = await fetch(url, options)
@ -25,24 +43,28 @@ export default async function fetchGitHubRepos() {
} }
const jsonRepos = await response.json() const jsonRepos = await response.json()
// filter out forks from public repos
const jsonReposCleaned = jsonRepos.filter((repo) => repo.fork === false)
const starsArray = [] const starsArray = []
const contribArray = [] const contribArray = []
jsonRepos.forEach(async (item) => { for (let index = 0; index < jsonReposCleaned.length; index++) {
const item = jsonReposCleaned[index]
starsArray.push(item.stargazers_count) starsArray.push(item.stargazers_count)
const responseContrib = await fetch( const responseContrib = await fetch(
`https://api.github.com/orgs/oceanprotocol/${item.name}/stats/contributors`, `https://api.github.com/repos/oceanprotocol/${item.name}/stats/contributors`,
options options
) )
const jsonContrib = await responseContrib.json() const jsonContrib = await responseContrib.json()
contribArray.push(jsonContrib.total) jsonContrib && contribArray.push(jsonContrib[0])
}) }
const stars = arrSum(starsArray) const stars = arrSum(starsArray)
const repositories = jsonRepos.length const repositories = jsonReposCleaned.length
const contributors = arrSum(contribArray) const contributors = getContributors(contribArray)
log( log(
'✓ GitHub. ' + '✓ GitHub. ' +