master
1import { define, Repository } from '#src'
2
3export default define({
4 url: import.meta.url,
5 tiers: true,
6 badges: [
7 'stars-100',
8 'stars-500',
9 'stars-1000',
10 'stars-2000',
11 'stars-5000',
12 'stars-10000',
13 'stars-20000',
14 ] as const,
15 present(data, grant) {
16 const repos = data.repos.sort(asc).filter(withStars)
17 let totalStars = 0
18
19 for (const repo of repos) {
20 totalStars += repo.stargazers.totalCount
21 }
22
23 if (totalStars >= 100) {
24 grant('stars-100', `I collected 100 stars.`)
25 .evidence(text(repos, 100))
26 .tier(1)
27 }
28 if (totalStars >= 500) {
29 grant('stars-500', 'I collected 500 stars.')
30 .evidence(text(repos, 500))
31 .tier(2)
32 }
33 if (totalStars >= 1000) {
34 grant('stars-1000', 'I collected 1000 stars.')
35 .evidence(text(repos, 1000))
36 .tier(3)
37 }
38 if (totalStars >= 2000) {
39 grant('stars-2000', 'I collected 2000 stars.')
40 .evidence(text(repos, 2000))
41 .tier(4)
42 }
43 if (totalStars >= 5000) {
44 grant('stars-5000', 'I collected 5000 stars.')
45 .evidence(text(repos, 5000))
46 .tier(5)
47 }
48 if (totalStars >= 10_000) {
49 grant('stars-10000', 'I collected 10000 stars.')
50 .evidence(text(repos, 10_000))
51 .tier(6)
52 }
53 if (totalStars >= 20_000) {
54 grant('stars-20000', 'I collected 20000 stars.')
55 .evidence(text(repos, 20_000))
56 .tier(7)
57 }
58 },
59})
60
61function asc(a: Repository, b: Repository) {
62 return (a.stargazers.totalCount || 0) - (b.stargazers.totalCount || 0)
63}
64
65function withStars(repo: Repository) {
66 return repo.stargazers.totalCount > 0
67}
68
69function text(repos: Repository[], max: number): string {
70 const lines: string[] = []
71 let totalStars = 0
72 for (const repo of repos) {
73 totalStars += repo.stargazers.totalCount
74 lines.push(
75 `* <a href="https://github.com/${repo.owner.login}/${repo.name}">${repo.owner.login}/${repo.name}: ★${repo.stargazers.totalCount}</a>`,
76 )
77 if (totalStars >= max) break
78 }
79 return `Repos:
80
81${lines.reverse().join('\n')}
82
83<sup>I have push, maintainer or admin permissions, so I'm definitely an author.<sup>
84`
85}