forked from deepset-ai/haystack-home
-
Notifications
You must be signed in to change notification settings - Fork 0
/
github.js
47 lines (41 loc) · 1.42 KB
/
github.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
// Fetches star count, contributor count and top contributors from the Github API
import axios from "axios";
import parse from "parse-link-header";
const options = {
headers: { Authorization: `Bearer ${process.env.GITHUB_ACCESS_TOKEN}` },
};
export default async function handler(request, response) {
try {
// Fetch the data
const [starsData, totalContributorsData, topContributorsData] =
await Promise.all([
// Stars
axios.get("https://api.github.com/repos/deepset-ai/haystack", options),
// Total contributors
axios.get(
"https://api.github.com/repos/deepset-ai/haystack/contributors?per_page=1",
options
),
// Top 10 contributors
axios.get(
"https://api.github.com/repos/deepset-ai/haystack/contributors?per_page=10",
options
),
]);
const stars = starsData.data.stargazers_count;
const parsed = parse(totalContributorsData.headers.link); // parse link header to get total pages
const contributors = parsed.last.page;
const topContributors = topContributorsData.data.map((contrib) => ({
name: contrib.login,
image: contrib.avatar_url,
contributions: contrib.contributions,
}));
return response.status(200).json({
stars,
contributors,
top_contributors: topContributors,
});
} catch (e) {
return response.status(500).json({ message: e.message });
}
}