mirror of
https://github.com/qodo-ai/pr-agent.git
synced 2025-07-04 12:50:38 +08:00
+ settings.github.ratelimit_retries setup in configuration.toml
This commit is contained in:
@ -10,8 +10,7 @@ from pr_agent.algo.token_handler import TokenHandler
|
|||||||
from pr_agent.algo.utils import load_large_diff
|
from pr_agent.algo.utils import load_large_diff
|
||||||
from pr_agent.config_loader import settings
|
from pr_agent.config_loader import settings
|
||||||
from pr_agent.git_providers.git_provider import GitProvider
|
from pr_agent.git_providers.git_provider import GitProvider
|
||||||
from github import GithubException
|
from git_provider import RateLimitExceeded
|
||||||
|
|
||||||
|
|
||||||
DELETED_FILES_ = "Deleted files:\n"
|
DELETED_FILES_ = "Deleted files:\n"
|
||||||
|
|
||||||
@ -43,8 +42,8 @@ def get_pr_diff(git_provider: GitProvider, token_handler: TokenHandler, model: s
|
|||||||
|
|
||||||
try:
|
try:
|
||||||
diff_files = list(git_provider.get_diff_files())
|
diff_files = list(git_provider.get_diff_files())
|
||||||
except GithubException.RateLimitExceededException as e:
|
except RateLimitExceededException as e:
|
||||||
logging.error(f"Rate limit exceeded for GitHub API. original message {e}")
|
logging.error(f"Rate limit exceeded for git provider API. original message {e}")
|
||||||
raise
|
raise
|
||||||
|
|
||||||
# get pr languages
|
# get pr languages
|
||||||
|
@ -136,3 +136,8 @@ class IncrementalPR:
|
|||||||
self.commits_range = None
|
self.commits_range = None
|
||||||
self.first_new_commit_sha = None
|
self.first_new_commit_sha = None
|
||||||
self.last_seen_commit_sha = None
|
self.last_seen_commit_sha = None
|
||||||
|
|
||||||
|
|
||||||
|
class RateLimitExceeded(Exception):
|
||||||
|
"""Raised when the git provider API rate limit has been exceeded."""
|
||||||
|
pass
|
@ -4,6 +4,7 @@ from typing import Optional, Tuple
|
|||||||
from urllib.parse import urlparse
|
from urllib.parse import urlparse
|
||||||
|
|
||||||
from github import AppAuthentication, Github, Auth, GithubException
|
from github import AppAuthentication, Github, Auth, GithubException
|
||||||
|
from git_provider import RateLimitExceeded
|
||||||
|
|
||||||
from pr_agent.config_loader import settings
|
from pr_agent.config_loader import settings
|
||||||
|
|
||||||
@ -81,26 +82,31 @@ class GithubProvider(GitProvider):
|
|||||||
@retry(exceptions=(GithubException.RateLimitExceededException),
|
@retry(exceptions=(GithubException.RateLimitExceededException),
|
||||||
tries=settings.github.ratelimit_retries, delay=2, backoff=2, jitter=(1, 3))
|
tries=settings.github.ratelimit_retries, delay=2, backoff=2, jitter=(1, 3))
|
||||||
def get_diff_files(self) -> list[FilePatchInfo]:
|
def get_diff_files(self) -> list[FilePatchInfo]:
|
||||||
files = self.get_files()
|
try:
|
||||||
diff_files = []
|
files = self.get_files()
|
||||||
for file in files:
|
diff_files = []
|
||||||
if is_valid_file(file.filename):
|
for file in files:
|
||||||
new_file_content_str = self._get_pr_file_content(file, self.pr.head.sha)
|
if is_valid_file(file.filename):
|
||||||
patch = file.patch
|
new_file_content_str = self._get_pr_file_content(file, self.pr.head.sha)
|
||||||
if self.incremental.is_incremental and self.file_set:
|
patch = file.patch
|
||||||
original_file_content_str = self._get_pr_file_content(file, self.incremental.last_seen_commit_sha)
|
if self.incremental.is_incremental and self.file_set:
|
||||||
patch = load_large_diff(file,
|
original_file_content_str = self._get_pr_file_content(file,
|
||||||
new_file_content_str,
|
self.incremental.last_seen_commit_sha)
|
||||||
original_file_content_str,
|
patch = load_large_diff(file,
|
||||||
None)
|
new_file_content_str,
|
||||||
self.file_set[file.filename] = patch
|
original_file_content_str,
|
||||||
else:
|
None)
|
||||||
original_file_content_str = self._get_pr_file_content(file, self.pr.base.sha)
|
self.file_set[file.filename] = patch
|
||||||
|
else:
|
||||||
|
original_file_content_str = self._get_pr_file_content(file, self.pr.base.sha)
|
||||||
|
|
||||||
diff_files.append(
|
diff_files.append(
|
||||||
FilePatchInfo(original_file_content_str, new_file_content_str, patch, file.filename))
|
FilePatchInfo(original_file_content_str, new_file_content_str, patch, file.filename))
|
||||||
self.diff_files = diff_files
|
self.diff_files = diff_files
|
||||||
return diff_files
|
return diff_files
|
||||||
|
except GithubException.RateLimitExceededException as e:
|
||||||
|
logging.error(f"Rate limit exceeded for GitHub API. Original message: {e}")
|
||||||
|
raise RateLimitExceeded("Rate limit exceeded for GitHub API.") from e
|
||||||
|
|
||||||
def publish_description(self, pr_title: str, pr_body: str):
|
def publish_description(self, pr_title: str, pr_body: str):
|
||||||
self.pr.edit(title=pr_title, body=pr_body)
|
self.pr.edit(title=pr_title, body=pr_body)
|
||||||
|
Reference in New Issue
Block a user