diff --git a/pr_agent/agent/pr_agent.py b/pr_agent/agent/pr_agent.py index ea1c3f47..0eefcd74 100644 --- a/pr_agent/agent/pr_agent.py +++ b/pr_agent/agent/pr_agent.py @@ -17,21 +17,16 @@ class PRAgent: if any(cmd == action for cmd in ["/answer"]): await PRReviewer(pr_url, is_answer=True).review() elif any(cmd == action for cmd in ["/review", "/review_pr", "/reflect_and_review"]): - incremental_review = await self.parse_args(request) if settings.pr_reviewer.ask_and_reflect or "/reflect_and_review" in request: await PRInformationFromUser(pr_url).generate_questions() else: - await PRReviewer(pr_url, is_incremental=incremental_review).review() + await PRReviewer(pr_url, args=args).review() elif any(cmd == action for cmd in ["/describe", "/describe_pr"]): await PRDescription(pr_url).describe() elif any(cmd == action for cmd in ["/improve", "/improve_code"]): await PRCodeSuggestions(pr_url).suggest() elif any(cmd == action for cmd in ["/ask", "/ask_question"]): - pattern = r'(/ask|/ask_question)\s*(.*)' - matches = re.findall(pattern, request, re.IGNORECASE) - if matches: - question = matches[0][1] - await PRQuestions(pr_url, question).answer() + await PRQuestions(pr_url, args).answer() else: return False diff --git a/pr_agent/git_providers/github_provider.py b/pr_agent/git_providers/github_provider.py index 7e52df81..1f2ffec7 100644 --- a/pr_agent/git_providers/github_provider.py +++ b/pr_agent/git_providers/github_provider.py @@ -30,6 +30,9 @@ class GithubProvider(GitProvider): def is_supported(self, capability: str) -> bool: return True + def get_pr_url(self) -> str: + return f"https://github.com/{self.repo}/pull/{self.pr_num}" + def set_pr(self, pr_url: str): self.repo, self.pr_num = self._parse_pr_url(pr_url) self.pr = self._get_pr() diff --git a/pr_agent/tools/pr_questions.py b/pr_agent/tools/pr_questions.py index 08af3797..8d24c04c 100644 --- a/pr_agent/tools/pr_questions.py +++ b/pr_agent/tools/pr_questions.py @@ -12,7 +12,8 @@ from pr_agent.git_providers.git_provider import get_main_pr_language class PRQuestions: - def __init__(self, pr_url: str, question_str: str): + def __init__(self, pr_url: str, args=None): + question_str = self.parse_args(args) self.git_provider = get_git_provider()(pr_url) self.main_pr_language = get_main_pr_language( self.git_provider.get_languages(), self.git_provider.get_files() @@ -34,6 +35,13 @@ class PRQuestions: self.patches_diff = None self.prediction = None + def parse_args(self, args): + if args and len(args) > 0: + question_str = " ".join(args) + else: + question_str = "" + return question_str + async def answer(self): logging.info('Answering a PR question...') if settings.config.publish_output: diff --git a/pr_agent/tools/pr_reviewer.py b/pr_agent/tools/pr_reviewer.py index c4630b35..06b7f6bf 100644 --- a/pr_agent/tools/pr_reviewer.py +++ b/pr_agent/tools/pr_reviewer.py @@ -120,7 +120,7 @@ class PRReviewer: if self.incremental.is_incremental: # Rename title when incremental review - Add to the beginning of the dict - last_commit_url = f"{self.pr_url}/commits/{self.git_provider.incremental.first_new_commit_sha}" + last_commit_url = f"{self.git_provider.get_pr_url()}/commits/{self.git_provider.incremental.first_new_commit_sha}" data = OrderedDict(data) data.update({'Incremental PR Review': { "⏮️ Review for commits since previous PR-Agent review": f"Starting from commit {last_commit_url}"}})