Implement methods to extract urls and fetch labels

This commit is contained in:
Álison Fernandes 2025-11-17 21:53:22 +00:00
parent 9d6a4c4c18
commit 9e05a07f23
No known key found for this signature in database
GPG Key ID: B8CE98903DFC87BC
2 changed files with 36 additions and 0 deletions

View File

@ -12,6 +12,20 @@ def extract_pr_numbers(line: str) -> List[str]:
# Match PR numbers from GitHub format (#123)
return re.findall(r'#(\d+)', line)
def extract_pr_url(line: str) -> List[str]:
"""Match PR URL from GitHub format https://github.com/foo/bar/pull/123"""
return re.findall(r'https://github\.com/[\w-]+/[\w.-]+/pull/\d+', line)
def fetch_labels(github_pr_url: str) -> List[str]:
"""Fetch labels from a GitHub PR using the GitHub CLI."""
result = subprocess.run(
['gh', 'pr', 'view', github_pr_url, '--json', 'labels', '--jq', '.labels[].name'],
capture_output=True,
text=True,
check=True
)
return [label.strip() for label in result.stdout.strip().split('\n') if label.strip()]
def process_line(line: str) -> str:
"""Process a single line from release notes by removing Jira tickets, conventional commit prefixes and other common patterns.

View File

@ -51,6 +51,28 @@ class TestProcessReleaseNotes(unittest.TestCase):
result = process_line(input_text)
self.assertEqual(result, expected)
def test_extract_pr_url(self):
test_cases = [
("* Update SDK to 1.0.0-3436-2a00b727 by @bw-ghapp[bot] in https://github.com/bitwarden/android/pull/6042", ["https://github.com/bitwarden/android/pull/6042"]),
("* Bump JUnit from 6.0.0 to 6.0.1 by SaintPatrick in https://github.com/bitwarden/android/pull/6149", ["https://github.com/bitwarden/android/pull/6149"]),
("* [PM-26986] Hide select other account button if user has no other account by @aj-rosado in https://github.com/bitwarden/android/pull/6041", ["https://github.com/bitwarden/android/pull/6041"]),
]
for input_text, expected in test_cases:
with self.subTest(input_text=input_text):
result = extract_pr_url(input_text)
self.assertEqual(result, expected)
def test_fetch_labels(self):
test_cases = [
("https://github.com/bitwarden/android/pull/6042", ["automated-pr", "t:ci"]),
("https://github.com/bitwarden/android/pull/6149", ["app:authenticator","app:password-manager","t:deps"]),
("https://github.com/bitwarden/android/pull/6041", []),
]
for pr_url, expected in test_cases:
with self.subTest(pr_url=pr_url):
result = fetch_labels(pr_url)
self.assertEqual(sorted(result), sorted(expected))
def test_process_file(self):
content = """
### Features: