Skip to content

Commit 2690d27

Browse files
fix(azure-devops): fall back to full review when commit dates are unreliable
- _get_commit_range now returns None (not []) when the previous review has no timestamp, no PR commits exist, or every commit author date is None, and disables incremental so PRReviewer's existing `commits_range is None` fallback path runs a full review instead of silently exiting via the threshold check. - _get_incremental_commits short-circuits when _get_commit_range returns None, avoiding TypeError on the iteration that follows. - Wraps the over-120-char incremental-skip conditional in PRReviewer.run for ruff compliance. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
1 parent 55cd982 commit 2690d27

2 files changed

Lines changed: 22 additions & 2 deletions

File tree

pr_agent/git_providers/azuredevops_provider.py

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,8 @@ def _get_incremental_commits(self):
215215
return
216216

217217
self.incremental.commits_range = self._get_commit_range()
218+
if self.incremental.commits_range is None:
219+
return
218220
candidate_paths = []
219221
had_errors = False
220222
for commit in self.incremental.commits_range:
@@ -258,18 +260,32 @@ def _get_incremental_commits(self):
258260
def _get_commit_range(self):
259261
last_review_time = _to_naive_utc(getattr(self.previous_review, "created_at", None))
260262
if last_review_time is None or not self.pr_commits:
261-
return []
263+
get_logger().info(
264+
"Cannot compute incremental commit range "
265+
"(missing previous review timestamp or PR commits); falling back to full review."
266+
)
267+
self.incremental.is_incremental = False
268+
return None
262269
first_new_commit_index = None
270+
saw_reliable_date = False
263271
for index in range(len(self.pr_commits) - 1, -1, -1):
264272
cdate = self.pr_commits[index].commit.author.date
265273
if cdate is None:
266274
continue
275+
saw_reliable_date = True
267276
if cdate > last_review_time:
268277
self.incremental.first_new_commit = self.pr_commits[index]
269278
first_new_commit_index = index
270279
else:
271280
self.incremental.last_seen_commit = self.pr_commits[index]
272281
break
282+
if not saw_reliable_date:
283+
get_logger().info(
284+
"All PR commit author dates are missing; cannot compute incremental range. "
285+
"Falling back to full review."
286+
)
287+
self.incremental.is_incremental = False
288+
return None
273289
return self.pr_commits[first_new_commit_index:] if first_new_commit_index is not None else []
274290

275291
def get_previous_review(self, *, full: bool, incremental: bool):

pr_agent/tools/pr_reviewer.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,11 @@ async def run(self) -> None:
142142
# ticket extraction if exists
143143
await extract_and_cache_pr_tickets(self.git_provider, self.vars)
144144

145-
if self.incremental.is_incremental and hasattr(self.git_provider, "unreviewed_files_map") and not self.git_provider.unreviewed_files_map:
145+
if (
146+
self.incremental.is_incremental
147+
and hasattr(self.git_provider, "unreviewed_files_map")
148+
and not self.git_provider.unreviewed_files_map
149+
):
146150
get_logger().info(f"Incremental review is enabled for {self.pr_url} but there are no new files")
147151
previous_review_url = ""
148152
if hasattr(self.git_provider, "previous_review") and self.git_provider.previous_review is not None:

0 commit comments

Comments
 (0)