mirror of
https://github.com/qodo-ai/pr-agent.git
synced 2025-07-04 21:00:40 +08:00
Merge pull request #79 from patryk-kowalski-ds/deepsense.ai/gitlab-provider-file-creation-handling
Fixes 404 error on gitlab file provider happening in case a MR introduced a new file.
This commit is contained in:
@ -4,6 +4,7 @@ from typing import Optional, Tuple
|
|||||||
from urllib.parse import urlparse
|
from urllib.parse import urlparse
|
||||||
|
|
||||||
import gitlab
|
import gitlab
|
||||||
|
from gitlab import GitlabGetError
|
||||||
|
|
||||||
from pr_agent.config_loader import settings
|
from pr_agent.config_loader import settings
|
||||||
|
|
||||||
@ -42,7 +43,11 @@ class GitLabProvider(GitProvider):
|
|||||||
self.last_diff = self.mr.diffs.list()[-1]
|
self.last_diff = self.mr.diffs.list()[-1]
|
||||||
|
|
||||||
def _get_pr_file_content(self, file_path: str, branch: str) -> str:
|
def _get_pr_file_content(self, file_path: str, branch: str) -> str:
|
||||||
|
try:
|
||||||
return self.gl.projects.get(self.id_project).files.get(file_path, branch).decode()
|
return self.gl.projects.get(self.id_project).files.get(file_path, branch).decode()
|
||||||
|
except GitlabGetError:
|
||||||
|
# In case of file creation the method returns GitlabGetError (404 file not found). In this case we return an empty string for the diff.
|
||||||
|
return ''
|
||||||
|
|
||||||
def get_diff_files(self) -> list[FilePatchInfo]:
|
def get_diff_files(self) -> list[FilePatchInfo]:
|
||||||
diffs = self.mr.changes()['changes']
|
diffs = self.mr.changes()['changes']
|
||||||
@ -58,7 +63,9 @@ class GitLabProvider(GitProvider):
|
|||||||
elif diff['renamed_file']:
|
elif diff['renamed_file']:
|
||||||
edit_type = EDIT_TYPE.RENAMED
|
edit_type = EDIT_TYPE.RENAMED
|
||||||
try:
|
try:
|
||||||
|
if isinstance(original_file_content_str, bytes):
|
||||||
original_file_content_str = bytes.decode(original_file_content_str, 'utf-8')
|
original_file_content_str = bytes.decode(original_file_content_str, 'utf-8')
|
||||||
|
if isinstance(new_file_content_str, bytes):
|
||||||
new_file_content_str = bytes.decode(new_file_content_str, 'utf-8')
|
new_file_content_str = bytes.decode(new_file_content_str, 'utf-8')
|
||||||
except UnicodeDecodeError:
|
except UnicodeDecodeError:
|
||||||
logging.warning(
|
logging.warning(
|
||||||
|
Reference in New Issue
Block a user