Skip to content

Commit

Permalink
refactor regex
Browse files Browse the repository at this point in the history
  • Loading branch information
hussam789 committed Oct 14, 2024
1 parent 840e8c4 commit 22bf7af
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions pr_agent/tools/ticket_pr_compliance_check.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
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)')

def find_jira_tickets(text):
# Regular expression patterns for JIRA tickets
Expand Down Expand Up @@ -35,9 +37,8 @@ def extract_ticket_links_from_pr_description(pr_description, repo_path):
github_tickets = []
try:
# Pattern to match full GitHub issue URLs and shorthand notations like owner/repo#issue_number or https://github.com/owner/repo/issues/issue_number
pattern = r'(https://github[^/]+/[^/]+/[^/]+/issues/\d+)|(\b(\w+)/(\w+)#(\d+)\b)'

matches = re.findall(pattern, pr_description)
matches = GITHUB_TICKET_PATTERN.findall(pr_description)

for match in matches:
if match[0]: # Full URL match
github_tickets.append(match[0])
Expand Down

0 comments on commit 22bf7af

Please sign in to comment.