Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions scripts/update-docs-changelog.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -181,11 +181,15 @@ async function fetchMergedPRs() {
headers['Authorization'] = `Bearer ${GITHUB_TOKEN}`;
}

// Fetch recently merged PRs
const searchQuery = `repo:${REPO_OWNER}/${REPO_NAME} is:pr is:merged sort:updated-desc`;
const url = `https://api.github.com/search/issues?q=${encodeURIComponent(searchQuery)}&per_page=${PR_LIMIT}`;
// Limit to PRs merged in the last 30 days to avoid pulling in old PRs
// that were recently "updated" by bot comments or label changes
const thirtyDaysAgo = new Date(Date.now() - 30 * 24 * 60 * 60 * 1000);
const mergedSince = thirtyDaysAgo.toISOString().split('T')[0];

console.log('Fetching merged PRs...');
const searchQuery = `repo:${REPO_OWNER}/${REPO_NAME} is:pr is:merged merged:>=${mergedSince}`;
const url = `https://api.github.com/search/issues?q=${encodeURIComponent(searchQuery)}&sort=created&order=desc&per_page=${PR_LIMIT}`;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bug: The script fetches PRs sorted by creation date but then sorts by merge date. With a fixed limit of 50 PRs, recently merged but older PRs may be missed.
Severity: MEDIUM

Suggested Fix

Since the GitHub Search API does not support sorting by merge date, the script should be updated to use pagination. It should fetch all pull requests merged within the specified date range, page by page, and then perform the client-side sort by merged_at on the complete, unfiltered dataset to ensure no entries are missed.

Prompt for AI Agent
Review the code at the location below. A potential bug has been identified by an AI
agent. Verify if this is a real issue. If it is, propose a fix; if not, explain why it's
not valid.

Location: scripts/update-docs-changelog.mjs#L190

Potential issue: The script fetches the 50 most recently created pull requests from the
GitHub API using `sort=created`. However, it later sorts these results by their merge
date (`merged_at`) to generate the changelog. This mismatch can lead to incomplete
changelogs. If a pull request was created some time ago but only merged recently, it may
not be included in the initial fetch of 50 recently created PRs, even if it is one of
the most recently merged. This causes it to be silently omitted from the final
changelog.

Did we get this right? 👍 / 👎 to inform future reviews.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wrong API sort misses merges

Medium Severity

The search request sorts by created while only the first PR_LIMIT hits are kept. Among PRs matching the 30-day merged filter, that prefers newly opened PRs and can omit long-lived ones that just merged. The later merged_at sort never sees those dropped items, so the changelog can miss recent merges in a busy window.

Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit 39445cb. Configure here.


console.log(`Fetching PRs merged since ${mergedSince}...`);

const response = await fetch(url, {headers});

Expand Down
Loading