Skip to content
Open
Show file tree
Hide file tree
Changes from 9 commits
Commits
Show all changes
17 commits
Select commit Hold shift + click to select a range
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
19 changes: 19 additions & 0 deletions docs/docs/core-abilities/fetching_ticket_context.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ This integration enriches the review process by automatically surfacing relevant

- [GitHub/Gitlab Issues](#githubgitlab-issues-integration)
- [Jira](#jira-integration)
- [Asana](#asana-integration)

**Ticket data fetched:**

Expand All @@ -30,6 +31,7 @@ Ticket Recognition Requirements:

- The PR description should contain a link to the ticket or if the branch name starts with the ticket id / number.
- For Jira tickets, you should follow the instructions in [Jira Integration](#jira-integration) in order to authenticate with Jira.
- For Asana tickets, see [Asana Integration](#asana-integration).

### Describe tool

Expand Down Expand Up @@ -92,6 +94,23 @@ This branch-name detection applies **only when the git provider is GitHub**. Sup

Since PR-Agent is integrated with GitHub, it doesn't require any additional configuration to fetch GitHub issues.

## Asana Integration

PR-Agent can detect Asana task references in PR descriptions and include them in the ticket compliance check.

**Supported reference format:**

- Full Asana URLs: `https://app.asana.com/0/{project_id}/{task_id}`

**How to link a PR to an Asana task:**

Include an Asana task URL in your PR description. PR-Agent will detect it automatically and include it in the related tickets list.

!!! note "Asana content fetching"
Asana task references are included for visibility and ticket compliance checking, but PR-Agent does **not** fetch the full task details from Asana (unlike GitHub and Jira tickets, which are fetched via API). The compliance check will note the reference and suggest reviewing the task in Asana for full context.

No additional configuration is required for Asana detection — it works out of the box.

## Jira Integration

We support both Jira Cloud and Jira Server/Data Center.
Expand Down
51 changes: 50 additions & 1 deletion pr_agent/tools/ticket_pr_compliance_check.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,29 @@ def find_jira_tickets(text):
return list(tickets)


_ASANA_TASK_URL_PATTERN = re.compile(
Comment thread
github-advanced-security[bot] marked this conversation as resolved.
Fixed
r'https://app\.asana\.com/0/(\d+)/(\d+)'
)


def find_asana_tickets(text: str) -> 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.
"""
tickets = set()
for match in _ASANA_TASK_URL_PATTERN.finditer(text):
tickets.add(match.group(0))
return sorted(tickets)


def extract_ticket_links_from_pr_description(pr_description, repo_path, base_url_html='https://github.com'):
"""
Extract all ticket links from PR description
Expand Down Expand Up @@ -123,16 +146,42 @@ async def extract_tickets(git_provider):
if link not in seen:
seen.add(link)
merged.append(link)

# Also detect Asana ticket references in the PR description
asana_tickets = find_asana_tickets(user_description)
for link in asana_tickets:
if link not in seen:
seen.add(link)
merged.append(link)
asana_links = [t for t in merged if t.startswith("https://app.asana.com/")]
github_like = [t for t in merged if not t.startswith("https://app.asana.com/")]

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Action required

1. Asana detection github-only 🐞 Bug ≡ Correctness

find_asana_tickets() is only invoked inside the isinstance(git_provider, GithubProvider) branch
of extract_tickets(), so non-GitHub providers will never include Asana references in
related_tickets. This makes Asana ticket compliance visibility silently unavailable for other
configured providers.
Agent Prompt
## Issue description
Asana ticket detection is currently executed only when `extract_tickets()` is running in the `GithubProvider` code path. For other supported git providers, `extract_tickets()` never runs the Asana scan, so Asana references in PR descriptions are not included in `related_tickets`.

## Issue Context
- The repo supports multiple git providers.
- Docs state Asana detection “works out of the box”, but the current implementation only activates for GitHub.

## Fix Focus Areas
- pr_agent/tools/ticket_pr_compliance_check.py[134-188]

### Implementation direction
- Move Asana reference extraction (`find_asana_tickets(...)`) to a provider-agnostic location in `extract_tickets()`.
  - Use the provider base API (`git_provider.get_user_description()` exists on `GitProvider`) to obtain the text.
- For providers that are not GitHub/Azure, still return Asana placeholder ticket entries when Asana URLs are present (instead of returning `None` / no tickets).
- Keep GitHub issue fetching behavior unchanged; just merge in the Asana placeholder entries regardless of provider type.
- Add/adjust a unit test to cover a non-GitHub provider scenario (can be a minimal stub implementing `get_user_description()` and `get_pr_branch()`) to ensure Asana references are returned.

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools

if len(merged) > 3:
get_logger().info(f"Too many tickets (description + branch): {len(merged)}")
tickets = merged[:3]
# Reserve at least one slot for an Asana reference when
# present so it is not systematically dropped.
asana_slot = asana_links[:1]
gh_slots = 3 - len(asana_slot)
tickets = github_like[:gh_slots] + asana_slot
else:
tickets = merged
tickets_content = []

if tickets:

for ticket in tickets:
# Skip Asana URLs — these are external references,
# included for visibility but cannot be fetched via GitHub API.
if ticket.startswith("https://app.asana.com/"):
tickets_content.append({
"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": "",
})
continue

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Action required

1. extract_tickets skips asana fetching 📎 Requirement gap ≡ Correctness

The new Asana handling explicitly avoids fetching any Asana task data and only adds a placeholder
entry, so Asana cannot be used as a real ticket provider end-to-end. This violates the requirement
to integrate an Asana Ticket Provider into the existing ticket fetching/compliance infrastructure.
Agent Prompt
## Issue description
The current Asana support only detects Asana URLs and explicitly skips fetching task details, meaning Asana is not implemented as an integrated ticket provider.

## Issue Context
PR Compliance requires Asana to be supported as a ticket provider in the same infrastructure used for other providers, so compliance checks can consume fetched Asana ticket/task data end-to-end.

## Fix Focus Areas
- pr_agent/tools/ticket_pr_compliance_check.py[150-183]
- docs/docs/core-abilities/fetching_ticket_context.md[97-112]

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


repo_name, original_issue_number = git_provider._parse_issue_url(ticket)

try:
Expand Down
145 changes: 145 additions & 0 deletions tests/unittest/test_ticket_compliance.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,145 @@
"""
Unit tests for Asana ticket detection in ticket_pr_compliance_check.py.

Tests cover:
- Full Asana URL detection
- Edge cases (mixed content, no tickets, duplicates)
"""
from pr_agent.git_providers.github_provider import GithubProvider
from pr_agent.tools.ticket_pr_compliance_check import extract_tickets, find_asana_tickets


class _Issue:
def __init__(self, number):
self.number = number
self.title = f"Issue {number}"
self.body = f"Issue {number} body"
self.labels = []


class _Repo:
def get_issue(self, number):
return _Issue(number)


class _GithubProvider(GithubProvider):
repo = "owner/repo"
base_url_html = "https://github.com"
repo_obj = _Repo()

def __init__(self, description):
self.description = description

def get_user_description(self):
return self.description

def get_pr_branch(self):
return ""

def _parse_issue_url(self, ticket):
return self.repo, int(ticket.rsplit("/", 1)[-1])

def fetch_sub_issues(self, ticket):
return []


class TestFindAsanaTickets:
"""Tests for find_asana_tickets()."""

def test_detects_full_asana_url(self):
"""Full Asana task URLs should be detected."""
text = "See https://app.asana.com/0/123456/789012 for details"
tickets = find_asana_tickets(text)
assert "https://app.asana.com/0/123456/789012" in tickets

def test_detects_multiple_urls(self):
"""Multiple Asana URLs should all be found."""
text = (
"See https://app.asana.com/0/11/111111111111"
" and https://app.asana.com/0/22/333333333333"
)
tickets = find_asana_tickets(text)
assert len(tickets) == 2

def test_deduplicates_identical_urls(self):
"""Duplicate references to the same URL should be deduplicated."""
text = (
"https://app.asana.com/0/1/123456789012"
" mentioned twice: https://app.asana.com/0/1/123456789012"
)
tickets = find_asana_tickets(text)
assert len(tickets) == 1

def test_returns_empty_for_no_tickets(self):
"""Text without Asana references returns an empty list."""
text = "No tickets here, just regular text"
tickets = find_asana_tickets(text)
assert tickets == []

def test_returns_empty_for_empty_string(self):
"""Empty string returns an empty list."""
tickets = find_asana_tickets("")
assert tickets == []

def test_ignores_github_urls(self):
"""GitHub issue URLs should not be mistaken for Asana tickets."""
text = "Fix https://github.com/owner/repo/issues/42"
tickets = find_asana_tickets(text)
assert tickets == []

def test_tickets_are_sorted(self):
"""Returned list should be sorted alphabetically."""
text = (
"https://app.asana.com/0/2/222222222222"
" https://app.asana.com/0/1/111111111111"
)
tickets = find_asana_tickets(text)
assert tickets == sorted(tickets)

def test_tickets_in_pr_description_mixed_content(self):
"""Asana tickets mixed with other content in a PR description."""
text = """## Summary
Related to https://app.asana.com/0/99/888888888888
and https://app.asana.com/0/77/777777777777

Also see GitHub issue #42
"""
tickets = find_asana_tickets(text)
assert len(tickets) == 2

async def test_extract_tickets_includes_asana_reference(self):
"""extract_tickets() should include Asana references in ticket content."""
provider = _GithubProvider(
"Related Asana task: https://app.asana.com/0/99/888888888888"
)

tickets = await extract_tickets(provider)

assert tickets == [
{
"ticket_id": "https://app.asana.com/0/99/888888888888",
"ticket_url": "https://app.asana.com/0/99/888888888888",
"title": "Asana Task: https://app.asana.com/0/99/888888888888",
"body": (
"Asana task referenced in PR description. "
"Fetch task details from Asana for full context."
),
"labels": "",
}
]

async def test_extract_tickets_reserves_slot_for_asana_when_truncated(self):
"""Asana references should not be dropped when the ticket list is capped."""
provider = _GithubProvider(
"Fixes #1 and #2 and #3. "
"Related Asana task: https://app.asana.com/0/99/888888888888"
)

tickets = await extract_tickets(provider)

assert len(tickets) == 3
asana_tickets = [
ticket for ticket in tickets
if ticket["ticket_url"].startswith("https://app.asana.com/")
]
assert len(asana_tickets) == 1
Loading