-
-
Notifications
You must be signed in to change notification settings - Fork 34
/
Copy pathcontributors.ts
50 lines (41 loc) · 1.56 KB
/
contributors.ts
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
48
49
50
import { Contributor } from '../types/contributor'
const GITHUB_API_URL =
'https://api.github.com/repos/fork-commit-merge/fork-commit-merge/contributors'
const BOT_ACCOUNTS = [
'nikohoffren',
'dependabot',
'dependabot[bot]',
'snyk-bot',
'actions-user',
]
export async function getTopContributors(): Promise<Contributor[]> {
try {
const response = await fetch(GITHUB_API_URL)
if (!response.ok) throw new Error('Failed to fetch contributors')
const contributors: Contributor[] = await response.json()
return contributors
.filter(contributor => !BOT_ACCOUNTS.includes(contributor.login))
.slice(0, 3)
} catch (error) {
console.error('Error fetching top contributors:', error)
return []
}
}
export async function getOtherContributors(): Promise<Contributor[]> {
try {
const response = await fetch(GITHUB_API_URL + '?per_page=50')
if (!response.ok) throw new Error('Failed to fetch contributors')
const contributors: Contributor[] = await response.json()
console.log('Total contributors before filtering:', contributors.length)
const filteredContributors = contributors
.filter(contributor => !BOT_ACCOUNTS.includes(contributor.login))
console.log('Contributors after bot filtering:', filteredContributors.length)
//* Get exactly 24 contributors after the top 3
const result = filteredContributors.slice(3, 27)
console.log('Final contributors after slice:', result.length)
return result
} catch (error) {
console.error('Error fetching other contributors:', error)
return []
}
}