Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

support more types of github ticket url / references #1290

Merged
merged 6 commits into from
Oct 14, 2024
Merged
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 20 additions & 16 deletions pr_agent/tools/ticket_pr_compliance_check.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@
from pr_agent.git_providers import GithubProvider
from pr_agent.log import get_logger

# Compile the regex pattern once, outside the function
GITHUB_TICKET_PATTERN = re.compile(
r'(https://github[^/]+/[^/]+/[^/]+/issues/\d+)|(\b(\w+)/(\w+)#(\d+)\b)|(#\d+)'
)


def find_jira_tickets(text):
# Regular expression patterns for JIRA tickets
Expand Down Expand Up @@ -32,27 +37,26 @@ def extract_ticket_links_from_pr_description(pr_description, repo_path):
"""
Extract all ticket links from PR description
"""
github_tickets = []
github_tickets = set()
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')

# 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}')
# Use the updated pattern to find matches
matches = GITHUB_TICKET_PATTERN.findall(pr_description)

for match in matches:
if match[0]: # Full URL match
github_tickets.add(match[0])
elif match[1]: # Shorthand notation match: owner/repo#issue_number
owner, repo, issue_number = match[2], match[3], match[4]
github_tickets.add(f'https://github.com/{owner}/{repo}/issues/{issue_number}')
else: # #123 format
issue_number = match[5][1:] # remove #
if issue_number.isdigit() and len(issue_number) < 5:
github_tickets.add(f'https://github.com/{repo_path}/issues/{issue_number}')
hussam789 marked this conversation as resolved.
Show resolved Hide resolved
hussam789 marked this conversation as resolved.
Show resolved Hide resolved
except Exception as e:
get_logger().error(f"Error extracting tickets error= {e}",
artifact={"traceback": traceback.format_exc()})

return github_tickets
return list(github_tickets)


async def extract_tickets(git_provider):
Expand Down
Loading