2021-11-09 09:36:02 +01:00
|
|
|
import axios from 'axios'
|
2020-06-16 11:12:27 +02:00
|
|
|
import { log, logError, arrSum } from '../utils'
|
2019-05-14 20:52:48 +02:00
|
|
|
|
|
|
|
// Request options for all fetch calls
|
|
|
|
const options = {
|
2020-06-16 12:32:47 +02:00
|
|
|
headers: {
|
|
|
|
// For getting topics, see note on https://developer.github.com/v3/search/
|
|
|
|
// Accept: 'application/vnd.github.mercy-preview+json'
|
|
|
|
Accept: 'application/vnd.github.preview'
|
|
|
|
}
|
2019-05-14 20:52:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// Fetch all public GitHub repos
|
|
|
|
//
|
2020-06-16 11:12:27 +02:00
|
|
|
export default async function fetchGitHubRepos() {
|
2020-06-16 12:32:47 +02:00
|
|
|
const url =
|
|
|
|
'https://api.github.com/orgs/oceanprotocol/repos?type=public&per_page=200'
|
|
|
|
const start = Date.now()
|
2021-11-09 09:36:02 +01:00
|
|
|
const response = await axios.get(url, options)
|
2019-05-14 20:52:48 +02:00
|
|
|
|
2020-06-16 12:32:47 +02:00
|
|
|
if (response.status !== 200) {
|
|
|
|
logError(`Non-200 response code from GitHub: ${response.status}`)
|
|
|
|
return null
|
|
|
|
}
|
2019-05-14 20:52:48 +02:00
|
|
|
|
2021-11-09 10:04:05 +01:00
|
|
|
const json = response.data
|
2020-06-16 16:49:17 +02:00
|
|
|
const numbers = json.map((item) => item.stargazers_count)
|
2020-06-16 12:32:47 +02:00
|
|
|
const stars = arrSum(numbers)
|
|
|
|
const repositories = json.length
|
2019-05-14 20:52:48 +02:00
|
|
|
|
2020-06-16 12:32:47 +02:00
|
|
|
log(
|
2020-06-16 15:16:31 +02:00
|
|
|
'✓ GitHub. ' +
|
2020-06-16 12:32:47 +02:00
|
|
|
`Total: ${repositories} public projects with a total of ${stars} stargazers. ` +
|
|
|
|
`Elapsed: ${new Date() - start}ms`
|
|
|
|
)
|
2019-05-14 20:52:48 +02:00
|
|
|
|
2020-06-16 12:32:47 +02:00
|
|
|
return { stars, repositories }
|
2019-05-14 20:52:48 +02:00
|
|
|
}
|