Skip to content

Commit 9af675d

Browse files
committed
Fix changelog undeployed SHA pagination and cleanup
1 parent 8936d9d commit 9af675d

File tree

1 file changed

+27
-18
lines changed

1 file changed

+27
-18
lines changed

agents/changelog/generate.ts

Lines changed: 27 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -206,33 +206,42 @@ async function getUndeployedSHAs(
206206
const token = process.env.GITHUB_TOKEN;
207207
if (!token) throw new Error("GITHUB_TOKEN env var is required");
208208

209-
const url = `https://api.github.com/repos/${owner}/${repo}/compare/${productionBranch}...main`;
210-
const res = await fetch(url, {
211-
headers: {
212-
Accept: "application/vnd.github+json",
213-
Authorization: `Bearer ${token}`,
214-
"X-GitHub-Api-Version": "2022-11-28",
215-
},
216-
});
209+
const shas = new Set<string>();
217210

218-
if (!res.ok) {
219-
const body = await res.text();
220-
throw new Error(`GitHub compare API error for ${owner}/${repo}: ${res.status} ${body}`);
221-
}
211+
const perPage = 100;
212+
let page = 1;
222213

223-
const data: any = await res.json();
224-
const shas = new Set<string>();
225-
for (const commit of data.commits) {
226-
shas.add(commit.sha);
214+
while (true) {
215+
const url = `https://api.github.com/repos/${owner}/${repo}/compare/${productionBranch}...main?per_page=${perPage}&page=${page}`;
216+
const res = await fetch(url, {
217+
headers: {
218+
Accept: "application/vnd.github+json",
219+
Authorization: `Bearer ${token}`,
220+
"X-GitHub-Api-Version": "2022-11-28",
221+
},
222+
});
223+
224+
if (!res.ok) {
225+
const body = await res.text();
226+
throw new Error(`GitHub compare API error for ${owner}/${repo}: ${res.status} ${body}`);
227+
}
228+
229+
const data: any = await res.json();
230+
const commits = data.commits || [];
231+
for (const commit of commits) {
232+
shas.add(commit.sha);
233+
}
234+
235+
if (commits.length < perPage) break;
236+
page++;
227237
}
238+
228239
return shas;
229240
}
230241

231242
// --- Step 6: Format the entry ---
232243

233244
function formatEntry(date: string, entries: CategorizedPR[]): string {
234-
const privateRepos = new Set(REPOS.filter((r) => r.private).map((r) => r.repo));
235-
236245
const sorted = [...entries].sort((a, b) => a.merged_at.localeCompare(b.merged_at));
237246

238247
const grouped: Record<string, CategorizedPR[]> = {};

0 commit comments

Comments
 (0)