8000 Fix gitea get file content error by SCREEN88 · Pull Request #1852 · qodo-ai/pr-agent · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Fix gitea get file content error #1852

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jun 5, 2025

Conversation

SCREEN88
Copy link
Contributor
@SCREEN88 SCREEN88 commented Jun 5, 2025

User description

What this PR does

This PR fixes issue for gitea provider.
Example of error:

pr_agent.git_providers.gitea_provider:get_file_content:893 - Error getting file: pom.xml, content: (404)
Reason: Not Found
HTTP response headers: HTTPHeaderDict({'Server': 'nginx', 'Date': 'Wed, 04 Jun 2025 14:36:56 GMT', 'Content-Type': 'application/json;charset=utf-8', 'Content-Length': '99', 'Connection': 'keep-alive', 'Keep-Alive': 'timeout=60', 'Cache-Control': 'max-age=0, private, must-revalidate, no-transform', 'Warning': 'token and access_token API authentication is deprecated and will be removed in gitea 1.23. Please use AuthorizationHeaderToken instead. Existing queries will continue to work but without authorization.', 'X-Content-Type-Options': 'nosniff', 'X-Frame-Options': 'SAMEORIGIN'})
HTTP response body: b'{"message":"The target couldn\'t be found.","url":"https://forgejo.pyn.ru/api/swagger","errors":[]}\n'

The problem is because methods _get_file_content_from_base and _get_file_content_from_latest_commit pass branch name instead of repo name.

Also add forgejo statuses to fix "Unknown edit type" if we use forgejo


PR Type

Bug fix


Description

  • Fix incorrect parameter usage in Gitea file content retrieval

  • Add support for Forgejo-specific file status 8000 values

  • Prevent "Unknown edit type" errors for Forgejo


Changes diagram

flowchart LR
  get_file_content_from_base["get_file_content_from_base()"]
  get_file_content_from_latest_commit["get_file_content_from_latest_commit()"]
  get_diff_files["get_diff_files()"]
  repo_api["repo_api.get_file_content()"]
  edit_type["Edit type detection"]

  get_file_content_from_base -- "use correct repo param" --> repo_api
  get_file_content_from_latest_commit -- "use correct repo param" --> repo_api
  get_diff_files -- "handle Forgejo statuses" --> edit_type
Loading

Changes walkthrough 📝

Relevant files
Bug fix
gitea_provider.py
Fix file content retrieval and status handling for Gitea/Forgejo

pr_agent/git_providers/gitea_provider.py

  • Corrected repo parameter in file content retrieval methods
  • Added handling for Forgejo-specific file status values (deleted,
    changed)
  • Improved edit type detection to avoid "Unknown edit type" errors
  • +4/-4     

    Need help?
  • Type /help how to ... in the comments thread for any questions about Qodo Merge usage.
  • Check out the documentation for more information.
  • Copy link
    Contributor

    PR Reviewer Guide 🔍

    Here are some key observations to aid the review process:

    ⏱️ Estimated effort to review: 2 🔵🔵⚪⚪⚪
    🧪 No relevant tests
    🔒 No security concerns identified
    ⚡ Recommended focus areas for review

    Error Handling

    The PR fixes the parameter issue but doesn't add any error handling or logging to help diagnose similar issues in the future. Consider adding more descriptive error messages when file content retrieval fails.

    return self.repo_api.get_file_content(
        owner=self.owner,
        repo=self.repo,
        commit_sha=self.base_sha,
        filepath=filename
    )

    Copy link
    Contributor

    PR Code Suggestions ✨

    Explore these optional code suggestions:

    CategorySuggestion                                                                                                                                    Impact
    General
    Add error handling

    Add error handling for file content retrieval to prevent crashes when files
    don't exist or can't be accessed. This will make the code more robust when
    dealing with repository operations.

    pr_agent/git_providers/gitea_provider.py [409-415]

     def _get_file_content_from_base(self, filename: str) -> str:
    -    return self.repo_api.get_file_content(
    -        owner=self.owner,
    -        repo=self.repo,
    -        commit_sha=self.base_sha,
    -        filepath=filename
    -    )
    +    try:
    +        return self.repo_api.get_file_content(
    +            owner=self.owner,
    +            repo=self.repo,
    +            commit_sha=self.base_sha,
    +            filepath=filename
    +        )
    +    except Exception as e:
    +        self.logger.error(f"Error retrieving base file content for {filename}: {str(e)}")
    +        return ""
    • Apply / Chat
    Suggestion importance[1-10]: 6

    __

    Why: Valid error handling suggestion that improves robustness by preventing crashes when file retrieval fails. However, this is a defensive programming enhancement rather than fixing a critical issue.

    Low
    • More
    • Author self-review: I have reviewed the PR code suggestions, and addressed the relevant ones.

    @nicholasgribanov
    Copy link
    Contributor

    @SCREEN88 thank you for your fix !

    @mrT23 mrT23 merged commit 3b84203 into qodo-ai:main Jun 5, 2025
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Projects
    None yet
    Development

    Successfully merging this pull request may close these issues.

    3 participants
    0