2023-08-01 14:43:26 +03:00
|
|
|
import shlex
|
2023-07-06 00:21:08 +03:00
|
|
|
|
2023-08-01 14:43:26 +03:00
|
|
|
from pr_agent.algo.utils import update_settings_from_args
|
|
|
|
from pr_agent.config_loader import get_settings
|
2023-10-14 01:39:05 +03:00
|
|
|
from pr_agent.git_providers.utils import apply_repo_settings
|
2023-09-27 16:48:17 +03:00
|
|
|
from pr_agent.tools.pr_add_docs import PRAddDocs
|
2023-07-16 15:42:50 +03:00
|
|
|
from pr_agent.tools.pr_code_suggestions import PRCodeSuggestions
|
2023-10-16 14:56:00 +03:00
|
|
|
from pr_agent.tools.pr_config import PRConfig
|
2023-07-16 15:42:50 +03:00
|
|
|
from pr_agent.tools.pr_description import PRDescription
|
2023-07-17 15:49:29 +03:00
|
|
|
from pr_agent.tools.pr_information_from_user import PRInformationFromUser
|
2023-07-06 00:21:08 +03:00
|
|
|
from pr_agent.tools.pr_questions import PRQuestions
|
|
|
|
from pr_agent.tools.pr_reviewer import PRReviewer
|
2023-10-16 14:56:00 +03:00
|
|
|
from pr_agent.tools.pr_similar_issue import PRSimilarIssue
|
2023-07-26 20:05:18 +03:00
|
|
|
from pr_agent.tools.pr_update_changelog import PRUpdateChangelog
|
2023-07-06 00:21:08 +03:00
|
|
|
|
2023-08-01 14:43:26 +03:00
|
|
|
command2class = {
|
2023-08-16 16:17:00 -04:00
|
|
|
"auto_review": PRReviewer,
|
2023-08-01 14:43:26 +03:00
|
|
|
"answer": PRReviewer,
|
|
|
|
"review": PRReviewer,
|
|
|
|
"review_pr": PRReviewer,
|
|
|
|
"reflect": PRInformationFromUser,
|
|
|
|
"reflect_and_review": PRInformationFromUser,
|
|
|
|
"describe": PRDescription,
|
|
|
|
"describe_pr": PRDescription,
|
|
|
|
"improve": PRCodeSuggestions,
|
|
|
|
"improve_code": PRCodeSuggestions,
|
|
|
|
"ask": PRQuestions,
|
|
|
|
"ask_question": PRQuestions,
|
|
|
|
"update_changelog": PRUpdateChangelog,
|
2023-08-02 16:42:54 +03:00
|
|
|
"config": PRConfig,
|
|
|
|
"settings": PRConfig,
|
2023-08-20 15:01:06 +03:00
|
|
|
"similar_issue": PRSimilarIssue,
|
2023-09-27 16:48:17 +03:00
|
|
|
"add_docs": PRAddDocs,
|
2023-08-01 14:43:26 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
commands = list(command2class.keys())
|
2023-07-06 00:21:08 +03:00
|
|
|
|
|
|
|
class PRAgent:
|
2023-07-08 08:52:11 +03:00
|
|
|
def __init__(self):
|
|
|
|
pass
|
2023-07-06 00:21:08 +03:00
|
|
|
|
2023-08-07 18:09:39 +03:00
|
|
|
async def handle_request(self, pr_url, request, notify=None) -> bool:
|
2023-08-01 17:44:08 +03:00
|
|
|
# First, apply repo specific settings if exists
|
2023-10-14 01:39:05 +03:00
|
|
|
apply_repo_settings(pr_url)
|
2023-08-01 17:44:08 +03:00
|
|
|
|
|
|
|
# Then, apply user specific settings if exists
|
2023-08-01 15:58:23 +03:00
|
|
|
request = request.replace("'", "\\'")
|
2023-08-01 14:43:26 +03:00
|
|
|
lexer = shlex.shlex(request, posix=True)
|
|
|
|
lexer.whitespace_split = True
|
|
|
|
action, *args = list(lexer)
|
|
|
|
args = update_settings_from_args(args)
|
2023-08-01 17:44:08 +03:00
|
|
|
|
2023-08-01 14:43:26 +03:00
|
|
|
action = action.lstrip("/").lower()
|
2023-09-29 09:47:13 +03:00
|
|
|
if action == "reflect_and_review":
|
|
|
|
get_settings().pr_reviewer.ask_and_reflect = True
|
2023-08-01 14:43:26 +03:00
|
|
|
if action == "answer":
|
2023-08-07 18:09:39 +03:00
|
|
|
if notify:
|
|
|
|
notify()
|
2023-08-01 14:43:26 +03:00
|
|
|
await PRReviewer(pr_url, is_answer=True, args=args).run()
|
2023-08-16 16:17:00 -04:00
|
|
|
elif action == "auto_review":
|
|
|
|
await PRReviewer(pr_url, is_auto=True, args=args).run()
|
2023-08-01 14:43:26 +03:00
|
|
|
elif action in command2class:
|
2023-08-07 18:09:39 +03:00
|
|
|
if notify:
|
|
|
|
notify()
|
2023-09-06 17:43:43 +03:00
|
|
|
await command2class[action](pr_url, args=args).run()
|
2023-07-06 12:58:05 +03:00
|
|
|
else:
|
2023-07-16 15:42:50 +03:00
|
|
|
return False
|
|
|
|
return True
|
2023-10-14 01:39:05 +03:00
|
|
|
|