Skip to content

Commit da79836

Browse files
committed
feat: sort contributors by role
1 parent 54e08d0 commit da79836

File tree

1 file changed

+26
-2
lines changed

1 file changed

+26
-2
lines changed

server/api/contributors.get.ts

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,24 @@ export interface GitHubContributor {
66
contributions: number
77
}
88

9+
// TODO: stub - need to fetch list of role members from somewhere to avoid hardcoding (
10+
type Role = 'stewards' | 'core' | 'maintainers'
11+
const roleMembers: Record<Role, GitHubContributor['login'][]> = {
12+
stewards: ['danielroe', 'patak-dev'],
13+
core: [],
14+
maintainers: [],
15+
}
16+
17+
function getRoleOrder(login: GitHubContributor['login']) {
18+
return roleMembers.stewards.includes(login)
19+
? 0
20+
: roleMembers.core.includes(login)
21+
? 1
22+
: roleMembers.maintainers.includes(login)
23+
? 2
24+
: 3
25+
}
26+
927
export default defineCachedEventHandler(
1028
async (): Promise<GitHubContributor[]> => {
1129
const allContributors: GitHubContributor[] = []
@@ -46,8 +64,14 @@ export default defineCachedEventHandler(
4664
page++
4765
}
4866

49-
// Filter out bots
50-
return allContributors.filter(c => !c.login.includes('[bot]'))
67+
return (
68+
allContributors
69+
// Filter out bots
70+
.filter(c => !c.login.includes('[bot]'))
71+
72+
// Sort by role (steward > core > maintainer > contributor)
73+
.sort((a, b) => getRoleOrder(a.login) - getRoleOrder(b.login))
74+
)
5175
},
5276
{
5377
maxAge: 3600, // Cache for 1 hour

0 commit comments

Comments
 (0)