Skip to content

Gitea provider: list_all_commits fetches repo commits instead of PR commitsΒ #2206

@hholst80

Description

@hholst80

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 wrong commit_id.
  • _get_file_content_from_latest_commit() (line 439) fetches file content from the wrong commit.
  • /review re-runs don't detect new changes β€” since last_commit SHA never changes (it's always the same default-branch commit), the persistent review thinks nothing changed and doesn't re-analyze.

Steps to Reproduce

  1. Set up PR-Agent with a Gitea instance
  2. Create a PR with one or more commits
  3. Trigger /review β€” note the commit SHA in the persistent review header
  4. Push a new commit to the PR branch
  5. Trigger /review again β€” 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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions