fix: handle missing issue body and improve error logging in ticket compliance check

This commit is contained in:
mrT23
2024-10-13 08:19:14 +03:00
parent 74ee9a333e
commit 05827d125b

View File

@ -32,21 +32,25 @@ def extract_ticket_links_from_pr_description(pr_description, repo_path):
""" """
Extract all ticket links from PR description 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 # Find all matches in the text
pattern = r'https://github[^/]+/[^/]+/[^/]+/issues/\d+' # should support also github server (for example 'https://github.company.ai/Codium-ai/pr-agent-pro/issues/525') github_tickets = re.findall(pattern, pr_description)
# Find all matches in the text # Find all issues referenced like #123 and add them as https://github.com/{repo_path}/issues/{issue_number}
github_tickets = re.findall(pattern, pr_description) issue_number_pattern = r'#\d+'
issue_numbers = re.findall(issue_number_pattern, pr_description)
# Find all issues referenced like #123 and add them as https://github.com/{repo_path}/issues/{issue_number} for issue_number in issue_numbers:
issue_number_pattern = r'#\d+' issue_number = issue_number[1:] # remove #
issue_numbers = re.findall(issue_number_pattern, pr_description) # check if issue_number is a valid number and len(issue_number) < 5
for issue_number in issue_numbers: if issue_number.isdigit() and len(issue_number) < 5:
issue_number = issue_number[1:] # remove # github_tickets.append(f'https://github.com/{repo_path}/issues/{issue_number}')
# check if issue_number is a valid number and len(issue_number) < 5 except Exception as e:
if issue_number.isdigit() and len(issue_number) < 5: get_logger().error(f"Error extracting tickets error= {e}",
github_tickets.append(f'https://github.com/{repo_path}/issues/{issue_number}') artifact={"traceback": traceback.format_exc()})
return github_tickets return github_tickets