From 74ee9a333efcb82350aa0f7f5c5b81ae36e2bfb9 Mon Sep 17 00:00:00 2001 From: mrT23 Date: Sun, 13 Oct 2024 08:15:04 +0300 Subject: [PATCH 1/2] fix: handle missing issue body and improve error logging in ticket compliance check --- pr_agent/tools/ticket_pr_compliance_check.py | 32 ++++++++++++-------- 1 file changed, 19 insertions(+), 13 deletions(-) diff --git a/pr_agent/tools/ticket_pr_compliance_check.py b/pr_agent/tools/ticket_pr_compliance_check.py index 03fdc88b..f00e2334 100644 --- a/pr_agent/tools/ticket_pr_compliance_check.py +++ b/pr_agent/tools/ticket_pr_compliance_check.py @@ -40,14 +40,13 @@ def extract_ticket_links_from_pr_description(pr_description, repo_path): github_tickets = re.findall(pattern, pr_description) # Find all issues referenced like #123 and add them as https://github.com/{repo_path}/issues/{issue_number} - # (unneeded, since when you pull the actual comment, it appears as a full link) - # issue_number_pattern = r'#\d+' - # issue_numbers = re.findall(issue_number_pattern, pr_description) - # for issue_number in issue_numbers: - # issue_number = issue_number[1:] # remove # - # # check if issue_number is a valid number and len(issue_number) < 5 - # if issue_number.isdigit() and len(issue_number) < 5: - # github_tickets.append(f'https://github.com/{repo_path}/issues/{issue_number}') + issue_number_pattern = r'#\d+' + issue_numbers = re.findall(issue_number_pattern, pr_description) + for issue_number in issue_numbers: + issue_number = issue_number[1:] # remove # + # check if issue_number is a valid number and len(issue_number) < 5 + if issue_number.isdigit() and len(issue_number) < 5: + github_tickets.append(f'https://github.com/{repo_path}/issues/{issue_number}') return github_tickets @@ -65,12 +64,19 @@ async def extract_tickets(git_provider): repo_name, original_issue_number = git_provider._parse_issue_url(ticket) # get the ticket object - issue_main = git_provider.repo_obj.get_issue(original_issue_number) + try: + issue_main = git_provider.repo_obj.get_issue(original_issue_number) + except Exception as e: + get_logger().error(f"Error getting issue_main error= {e}", + artifact={"traceback": traceback.format_exc()}) + continue # clip issue_main.body max length - issue_body = issue_main.body - if len(issue_main.body) > MAX_TICKET_CHARACTERS: - issue_body = issue_main.body[:MAX_TICKET_CHARACTERS] + "..." + issue_body_str = issue_main.body + if not issue_body_str: + issue_body_str = "" + if len(issue_body_str) > MAX_TICKET_CHARACTERS: + issue_body_str = issue_body_str[:MAX_TICKET_CHARACTERS] + "..." # extract labels labels = [] @@ -85,7 +91,7 @@ async def extract_tickets(git_provider): artifact={"traceback": traceback.format_exc()}) tickets_content.append( {'ticket_id': issue_main.number, - 'ticket_url': ticket, 'title': issue_main.title, 'body': issue_body, + 'ticket_url': ticket, 'title': issue_main.title, 'body': issue_body_str, 'labels': ", ".join(labels)}) return tickets_content From 05827d125b93bf586fc4417f1266ed3a713bb7f3 Mon Sep 17 00:00:00 2001 From: mrT23 Date: Sun, 13 Oct 2024 08:19:14 +0300 Subject: [PATCH 2/2] fix: handle missing issue body and improve error logging in ticket compliance check --- pr_agent/tools/ticket_pr_compliance_check.py | 30 +++++++++++--------- 1 file changed, 17 insertions(+), 13 deletions(-) diff --git a/pr_agent/tools/ticket_pr_compliance_check.py b/pr_agent/tools/ticket_pr_compliance_check.py index f00e2334..5dafecc1 100644 --- a/pr_agent/tools/ticket_pr_compliance_check.py +++ b/pr_agent/tools/ticket_pr_compliance_check.py @@ -32,21 +32,25 @@ def extract_ticket_links_from_pr_description(pr_description, repo_path): """ Extract all ticket links from PR description """ + github_tickets = [] + try: + # example link to search for: https://github.com/Codium-ai/pr-agent-pro/issues/525 + pattern = r'https://github[^/]+/[^/]+/[^/]+/issues/\d+' # should support also github server (for example 'https://github.company.ai/Codium-ai/pr-agent-pro/issues/525') - # example link to search for: https://github.com/Codium-ai/pr-agent-pro/issues/525 - pattern = r'https://github[^/]+/[^/]+/[^/]+/issues/\d+' # should support also github server (for example 'https://github.company.ai/Codium-ai/pr-agent-pro/issues/525') + # Find all matches in the text + github_tickets = re.findall(pattern, pr_description) - # Find all matches in the text - github_tickets = re.findall(pattern, pr_description) - - # Find all issues referenced like #123 and add them as https://github.com/{repo_path}/issues/{issue_number} - issue_number_pattern = r'#\d+' - issue_numbers = re.findall(issue_number_pattern, pr_description) - for issue_number in issue_numbers: - issue_number = issue_number[1:] # remove # - # check if issue_number is a valid number and len(issue_number) < 5 - if issue_number.isdigit() and len(issue_number) < 5: - github_tickets.append(f'https://github.com/{repo_path}/issues/{issue_number}') + # Find all issues referenced like #123 and add them as https://github.com/{repo_path}/issues/{issue_number} + issue_number_pattern = r'#\d+' + issue_numbers = re.findall(issue_number_pattern, pr_description) + for issue_number in issue_numbers: + issue_number = issue_number[1:] # remove # + # check if issue_number is a valid number and len(issue_number) < 5 + if issue_number.isdigit() and len(issue_number) < 5: + github_tickets.append(f'https://github.com/{repo_path}/issues/{issue_number}') + except Exception as e: + get_logger().error(f"Error extracting tickets error= {e}", + artifact={"traceback": traceback.format_exc()}) return github_tickets