Skip to content

Commit 945823d

Browse files
committed
feat(posts): include PR contributors between releases in contributor
list
1 parent ddd8987 commit 945823d

1 file changed

Lines changed: 30 additions & 4 deletions

File tree

website/src/lib/posts.ts

Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -123,26 +123,29 @@ export async function getPostBySlug(
123123

124124
async function fetchReleaseContributors(tag: string): Promise<string[]> {
125125
try {
126+
const headers = { Accept: "application/vnd.github+json" };
126127
const relRes = await fetch(
127128
"https://api.github.com/repos/debba/tabularis/releases?per_page=100",
128-
{ headers: { Accept: "application/vnd.github+json" } },
129+
{ headers },
129130
);
130-
const releases: { tag_name: string }[] = await relRes.json();
131+
const releases: { tag_name: string; published_at: string }[] =
132+
await relRes.json();
131133
const idx = releases.findIndex((r) => r.tag_name === tag);
132134
const prevTag =
133135
idx >= 0 && idx + 1 < releases.length
134136
? releases[idx + 1].tag_name
135137
: null;
136138
if (!prevTag) return [];
137139

140+
const users = new Set<string>();
141+
138142
const cmpRes = await fetch(
139143
`https://api.github.com/repos/debba/tabularis/compare/${prevTag}...${tag}`,
140-
{ headers: { Accept: "application/vnd.github+json" } },
144+
{ headers },
141145
);
142146
const data: {
143147
commits: { author: { login: string; type: string } | null }[];
144148
} = await cmpRes.json();
145-
const users = new Set<string>();
146149
for (const commit of data.commits ?? []) {
147150
const author = commit.author;
148151
if (
@@ -153,6 +156,29 @@ async function fetchReleaseContributors(tag: string): Promise<string[]> {
153156
users.add(author.login);
154157
}
155158
}
159+
160+
const prevDate = releases[idx + 1].published_at;
161+
const curDate = releases[idx].published_at;
162+
if (prevDate && curDate) {
163+
const prsRes = await fetch(
164+
`https://api.github.com/search/issues?q=repo:debba/tabularis+is:pr+is:merged+merged:${prevDate}..${curDate}&per_page=100`,
165+
{ headers },
166+
);
167+
const prsData: {
168+
items: { user: { login: string; type: string } | null }[];
169+
} = await prsRes.json();
170+
for (const pr of prsData.items ?? []) {
171+
const user = pr.user;
172+
if (
173+
user?.login &&
174+
user.type !== "Bot" &&
175+
!user.login.endsWith("[bot]")
176+
) {
177+
users.add(user.login);
178+
}
179+
}
180+
}
181+
156182
return Array.from(users);
157183
} catch {
158184
return [];

0 commit comments

Comments
 (0)