-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Description
Bug Description
The Gitea provider's __init__ method in pr_agent/git_providers/gitea_provider.py fetches all repository commits instead of PR-specific commits, causing self.last_commit to point at the wrong commit.
Root Cause
# gitea_provider.py, lines 89-93
self.pr_commits = self.repo_api.list_all_commits(
owner=self.owner,
repo=self.repo
)
self.last_commit = self.pr_commits[-1]list_all_commits() calls GET /repos/{owner}/{repo}/commits, which returns commits from the default branch (e.g. master/main), not from the PR branch. Then [-1] picks the last element β which, since Gitea returns commits newest-first, is the oldest commit on the default branch.
Compare with the GitHub provider which correctly uses PR-specific commits:
# github_provider.py, line 53-54
self.pr_commits = list(self.pr.get_commits())
self.last_commit_id = self.pr_commits[-1]Impact
get_latest_commit_url()(line 226) returns the URL of a random default-branch commit, not the PR head.- Persistent review updates always report "updated to latest commit {wrong_sha}" β referencing a commit that has nothing to do with the PR.
publish_inline_comments()(line 317) posts inline comments against the wrongcommit_id._get_file_content_from_latest_commit()(line 439) fetches file content from the wrong commit./reviewre-runs don't detect new changes β sincelast_commitSHA never changes (it's always the same default-branch commit), the persistent review thinks nothing changed and doesn't re-analyze.
Steps to Reproduce
- Set up PR-Agent with a Gitea instance
- Create a PR with one or more commits
- Trigger
/reviewβ note the commit SHA in the persistent review header - Push a new commit to the PR branch
- Trigger
/reviewagain β the persistent review still references the same wrong commit SHA from step 3, and the review content is not updated
Suggested Fix
Replace list_all_commits(owner, repo) with a method that calls the PR-specific commits endpoint:
GET /repos/{owner}/{repo}/pulls/{pr_number}/commits
The giteapy SDK (v1.0.8) does not have a built-in method for this endpoint, so a raw call_api call is needed (following the same pattern as get_change_file_pull_request and get_pull_request_diff).
Also note that Gitea returns PR commits newest-first (unlike GitHub which returns oldest-first), so [0] should be used instead of [-1] to get the latest commit.