-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
feat: add Asana ticket detection to ticket compliance check #2430
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
Open
Oxygen56
wants to merge
17
commits into
The-PR-Agent:main
Choose a base branch
from
Oxygen56:feat/asana-ticket-provider
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+497
−12
Open
Changes from all commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
bafe543
fix: preserve original indentation character in /improve suggestions
Oxygen56 5a70b98
feat: add Asana ticket detection to ticket compliance check
Oxygen56 99b9f74
fix: align Asana ticket schema with Jinja template expectations
Oxygen56 3586598
fix: use exact dedent and preserve tab remainder in dedent_code
Oxygen56 2b76ed6
test: add unit tests for Asana ticket detection in ticket compliance …
Oxygen56 3ce5450
fix: address all bot review feedback for Asana ticket detection
Oxygen56 0573be2
Address review feedback: revert unrelated indentation changes in pr_c…
Oxygen56 4caee4c
Drop ASANA- shorthand format (keep full URL only)
Oxygen56 65460ce
test: cover Asana ticket extraction integration
Oxygen56 bc043c7
fix: harden Asana ticket extraction edge cases
Oxygen56 a096303
fix: support Asana references across providers
Oxygen56 800a5c2
refactor: append Asana references after provider fetch
Oxygen56 cf17141
fix: cap provider-agnostic Asana ticket context
Oxygen56 1c1a693
fix: make related ticket cap configurable
Oxygen56 61df3f9
fix: return empty ticket list when none found
Oxygen56 c928e6c
fix: always return ticket list
Oxygen56 557b28c
fix: backfill asana tickets after fetch failures
Oxygen56 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,8 +2,7 @@ | |
| import traceback | ||
|
|
||
| from pr_agent.config_loader import get_settings | ||
| from pr_agent.git_providers import GithubProvider | ||
| from pr_agent.git_providers import AzureDevopsProvider | ||
| from pr_agent.git_providers import AzureDevopsProvider, GithubProvider | ||
| from pr_agent.log import get_logger | ||
|
|
||
| # Compile the regex pattern once, outside the function | ||
|
|
@@ -35,6 +34,72 @@ def find_jira_tickets(text): | |
| return list(tickets) | ||
|
|
||
|
|
||
| _ASANA_TASK_URL_PATTERN = re.compile( | ||
| r"https://app\.asana\.com/0/(\d+)/(\d+)" | ||
| ) | ||
| DEFAULT_MAX_RELATED_TICKETS = 3 | ||
|
|
||
|
|
||
| def find_asana_tickets(text: str | None) -> list: | ||
| """Extract Asana task references from text. | ||
|
|
||
| Supports full Asana URLs (``https://app.asana.com/0/{project_id}/{task_id}``). | ||
| Returns a list of unique task URLs. | ||
|
|
||
| Args: | ||
| text: The text to scan for Asana task references. | ||
|
|
||
| Returns: | ||
| A list of Asana task URLs. | ||
| """ | ||
| if not isinstance(text, str) or not text: | ||
| return [] | ||
|
|
||
| tickets = set() | ||
| for match in _ASANA_TASK_URL_PATTERN.finditer(text): | ||
| tickets.add(match.group(0)) | ||
| return sorted(tickets) | ||
|
|
||
|
|
||
| def _make_asana_ticket_content(ticket: str) -> dict: | ||
| return { | ||
| "ticket_id": ticket, | ||
| "ticket_url": ticket, | ||
| "title": f"Asana Task: {ticket}", | ||
| "body": ( | ||
| "Asana task referenced in PR description. " | ||
| "Fetch task details from Asana for full context." | ||
| ), | ||
| "labels": "", | ||
| } | ||
|
|
||
|
|
||
| def _append_asana_ticket_content( | ||
| tickets_content: list, | ||
| asana_tickets: list, | ||
| max_tickets: int, | ||
| ) -> None: | ||
| seen_ticket_urls = {ticket.get("ticket_url") for ticket in tickets_content} | ||
| for ticket in asana_tickets: | ||
| if len(tickets_content) >= max_tickets: | ||
| break | ||
| if ticket not in seen_ticket_urls: | ||
| tickets_content.append(_make_asana_ticket_content(ticket)) | ||
| seen_ticket_urls.add(ticket) | ||
|
|
||
|
|
||
| def _get_max_related_tickets() -> int: | ||
| max_tickets = get_settings().get( | ||
| "pr_reviewer.max_related_tickets", | ||
| DEFAULT_MAX_RELATED_TICKETS, | ||
| ) | ||
| try: | ||
| max_tickets = int(max_tickets) | ||
| except (TypeError, ValueError): | ||
| return DEFAULT_MAX_RELATED_TICKETS | ||
| return max(max_tickets, 1) | ||
|
|
||
|
|
||
| def extract_ticket_links_from_pr_description(pr_description, repo_path, base_url_html='https://github.com'): | ||
| """ | ||
| Extract all ticket links from PR description | ||
|
|
@@ -85,7 +150,8 @@ def extract_ticket_links_from_branch_name(branch_name, repo_path, base_url_html= | |
| pattern = re.compile(custom_regex_str) | ||
| if pattern.groups < 1: | ||
| get_logger().error( | ||
| "branch_issue_regex must contain at least one capturing group for the issue number; using default pattern." | ||
| "branch_issue_regex must contain at least one capturing group for the issue number; " | ||
| "using default pattern." | ||
| ) | ||
| pattern = BRANCH_ISSUE_PATTERN | ||
| except re.error as e: | ||
|
|
@@ -107,9 +173,14 @@ def extract_ticket_links_from_branch_name(branch_name, repo_path, base_url_html= | |
|
|
||
| async def extract_tickets(git_provider): | ||
| MAX_TICKET_CHARACTERS = 10000 | ||
| max_tickets = _get_max_related_tickets() | ||
| try: | ||
| user_description = git_provider.get_user_description() | ||
| asana_tickets = find_asana_tickets(user_description) | ||
| tickets_content = [] | ||
| asana_tickets_to_include = asana_tickets | ||
|
|
||
| if isinstance(git_provider, GithubProvider): | ||
| user_description = git_provider.get_user_description() | ||
| description_tickets = extract_ticket_links_from_pr_description( | ||
| user_description, git_provider.repo, git_provider.base_url_html | ||
| ) | ||
|
|
@@ -123,12 +194,19 @@ async def extract_tickets(git_provider): | |
| if link not in seen: | ||
| seen.add(link) | ||
| merged.append(link) | ||
| if len(merged) > 3: | ||
| get_logger().info(f"Too many tickets (description + branch): {len(merged)}") | ||
| tickets = merged[:3] | ||
|
|
||
| total_tickets = len(merged) + len(asana_tickets) | ||
| if total_tickets > max_tickets: | ||
| get_logger().info( | ||
| f"Too many tickets (description + branch + Asana): {total_tickets}" | ||
| ) | ||
| # Reserve at least one slot for an Asana reference when | ||
| # present so it is not systematically dropped. | ||
| reserved_asana_slots = 1 if asana_tickets else 0 | ||
| github_slots = max_tickets - reserved_asana_slots | ||
| tickets = merged[:github_slots] | ||
| else: | ||
| tickets = merged | ||
| tickets_content = [] | ||
|
|
||
| if tickets: | ||
|
|
||
|
|
@@ -188,11 +266,8 @@ async def extract_tickets(git_provider): | |
| 'sub_issues': sub_issues_content # Store sub-issues content | ||
| }) | ||
|
|
||
| return tickets_content | ||
|
|
||
| elif isinstance(git_provider, AzureDevopsProvider): | ||
| tickets_info = git_provider.get_linked_work_items() | ||
| tickets_content = [] | ||
| for ticket in tickets_info: | ||
| try: | ||
| ticket_body_str = ticket.get("body", "") | ||
|
|
@@ -214,11 +289,20 @@ async def extract_tickets(git_provider): | |
| f"Error processing Azure DevOps ticket: {e}", | ||
| artifact={"traceback": traceback.format_exc()}, | ||
| ) | ||
| return tickets_content | ||
| azure_slots = max_tickets - (1 if asana_tickets else 0) | ||
| tickets_content = tickets_content[:azure_slots] | ||
|
|
||
| _append_asana_ticket_content( | ||
| tickets_content, | ||
| asana_tickets_to_include, | ||
| max_tickets, | ||
| ) | ||
| return tickets_content | ||
|
|
||
| except Exception as e: | ||
|
Comment on lines
+295
to
302
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 1. extract_tickets() can return none extract_tickets() only returns when tickets_content is truthy, so callers can receive None when no tickets are found or when an exception occurs. This violates the requirement to handle edge cases gracefully and can cause downstream errors when code expects a list. Agent Prompt
|
||
| get_logger().error(f"Error extracting tickets error= {e}", | ||
| artifact={"traceback": traceback.format_exc()}) | ||
| return [] | ||
|
|
||
|
|
||
| async def extract_and_cache_pr_tickets(git_provider, vars): | ||
|
|
||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.