From f2b74b6970ce40d15c94f8af5e2511813f675410 Mon Sep 17 00:00:00 2001 From: "Hussam.lawen" Date: Tue, 18 Jul 2023 13:03:36 +0300 Subject: [PATCH 1/3] support gitlab describe function --- pr_agent/algo/pr_processing.py | 4 ++-- pr_agent/git_providers/github_provider.py | 2 +- pr_agent/git_providers/gitlab_provider.py | 7 ++++--- pr_agent/tools/pr_reviewer.py | 2 +- 4 files changed, 8 insertions(+), 7 deletions(-) diff --git a/pr_agent/algo/pr_processing.py b/pr_agent/algo/pr_processing.py index a57b0e4b..165b7de5 100644 --- a/pr_agent/algo/pr_processing.py +++ b/pr_agent/algo/pr_processing.py @@ -29,10 +29,10 @@ def get_pr_diff(git_provider: Union[GithubProvider, Any], token_handler: TokenHa global PATCH_EXTRA_LINES PATCH_EXTRA_LINES = 0 - git_provider.pr.diff_files = list(git_provider.get_diff_files()) + diff_files = list(git_provider.get_diff_files()) # get pr languages - pr_languages = sort_files_by_main_languages(git_provider.get_languages(), git_provider.pr.diff_files) + pr_languages = sort_files_by_main_languages(git_provider.get_languages(), diff_files) # generate a standard diff string, with patch extension patches_extended, total_tokens = pr_generate_extended_diff(pr_languages, token_handler, diff --git a/pr_agent/git_providers/github_provider.py b/pr_agent/git_providers/github_provider.py index 76f3a818..08b3623f 100644 --- a/pr_agent/git_providers/github_provider.py +++ b/pr_agent/git_providers/github_provider.py @@ -67,7 +67,7 @@ class GithubProvider(GitProvider): if relevant_line_in_file in line: position = i break - elif relevant_line_in_file[0] == '+' and relevant_line_in_file[1:] in line: + elif relevant_line_in_file[0] == '+' and relevant_line_in_file[1:].lstrip() in line: # The model often adds a '+' to the beginning of the relevant_line_in_file even if originally # it's a context line position = i diff --git a/pr_agent/git_providers/gitlab_provider.py b/pr_agent/git_providers/gitlab_provider.py index d83ae6d5..6c889c55 100644 --- a/pr_agent/git_providers/gitlab_provider.py +++ b/pr_agent/git_providers/gitlab_provider.py @@ -87,8 +87,9 @@ class GitLabProvider(GitProvider): return [change['new_path'] for change in self.mr.changes()['changes']] def publish_description(self, pr_title: str, pr_body: str): - logging.exception("Not implemented yet") - pass + self.mr.title = pr_title + self.mr.description = pr_body + self.mr.save() def publish_comment(self, mr_comment: str, is_temporary: bool = False): comment = self.mr.notes.create({'body': mr_comment}) @@ -181,7 +182,7 @@ class GitLabProvider(GitProvider): found = True edit_type = self.get_edit_type(line) break - elif relevant_line_in_file[0] == '+' and relevant_line_in_file[1:] in line: + elif relevant_line_in_file[0] == '+' and relevant_line_in_file[1:].lstrip() in line: # The model often adds a '+' to the beginning of the relevant_line_in_file even if originally # it's a context line found = True diff --git a/pr_agent/tools/pr_reviewer.py b/pr_agent/tools/pr_reviewer.py index ab6ffe9b..62264ec1 100644 --- a/pr_agent/tools/pr_reviewer.py +++ b/pr_agent/tools/pr_reviewer.py @@ -96,7 +96,7 @@ class PRReviewer: del data['PR Feedback']['Security concerns'] data['PR Analysis']['Security concerns'] = val - if settings.config.git_provider == 'github' and \ + if settings.config.git_provider != 'bitbucket' and \ settings.pr_reviewer.inline_code_comments and \ 'Code suggestions' in data['PR Feedback']: del data['PR Feedback']['Code suggestions'] From 8fb9affef3a02a9667215e0b5ce2713eacbd02ba Mon Sep 17 00:00:00 2001 From: "Hussam.lawen" Date: Tue, 18 Jul 2023 13:14:01 +0300 Subject: [PATCH 2/3] add try catch --- pr_agent/git_providers/gitlab_provider.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/pr_agent/git_providers/gitlab_provider.py b/pr_agent/git_providers/gitlab_provider.py index 6c889c55..b14775a5 100644 --- a/pr_agent/git_providers/gitlab_provider.py +++ b/pr_agent/git_providers/gitlab_provider.py @@ -87,9 +87,12 @@ class GitLabProvider(GitProvider): return [change['new_path'] for change in self.mr.changes()['changes']] def publish_description(self, pr_title: str, pr_body: str): - self.mr.title = pr_title - self.mr.description = pr_body - self.mr.save() + try: + self.mr.title = pr_title + self.mr.description = pr_body + self.mr.save() + except Exception as e: + logging.exception(f"Could not update merge request {self.id_mr} description: {e}") def publish_comment(self, mr_comment: str, is_temporary: bool = False): comment = self.mr.notes.create({'body': mr_comment}) From 7f0a96d8f74899fbe0346675262687eb22fed3bf Mon Sep 17 00:00:00 2001 From: "Hussam.lawen" Date: Tue, 18 Jul 2023 13:17:30 +0300 Subject: [PATCH 3/3] readme --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 5e56260a..27262326 100644 --- a/README.md +++ b/README.md @@ -76,7 +76,7 @@ To set up your own PR-Agent, see the [Quickstart](#Quickstart) section | TOOLS | Review | :white_check_mark: | :white_check_mark: | :white_check_mark: | | | ⮑ Inline review | :white_check_mark: | :white_check_mark: | | | | Ask | :white_check_mark: | :white_check_mark: | | -| | Auto-Description | :white_check_mark: | | | +| | Auto-Description | :white_check_mark: | :white_check_mark: | | | | Improve Code | :white_check_mark: | :white_check_mark: | | | | Reflect and Review | :white_check_mark: | | | | | | | | |