Skip to content

ENH: Add support for Github label and issue description generation in Kaizen bot #532

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

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Changes from all 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
40 changes: 40 additions & 0 deletions github_app/github_helper/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
import logging
import hmac
import hashlib
from bs4 import BeautifulSoup
from typing import List, Tuple

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -91,3 +93,41 @@ def is_github_signature_valid(headers, body):

mac = hmac.new(github_secret, msg=body, digestmod=hashlib.sha256)
return hmac.compare_digest(mac.hexdigest(), signature)


def scrape_labels(labels_url) -> List[Tuple[str, str]]:
"""
Scrape the label names and descriptions of a repository
"""
response = requests.get(labels_url)
if response.status_code == 200:
html_content = response.text
else:
logger.error(
f"Unable to fetch labels page with error: {response.status_code} url: {labels_url}"
)
soup = BeautifulSoup(html_content, 'html.parser')
label_elem = soup.find_all('div', class_='js-label-preview')
label_with_desc = []
for label in label_elem:
labels = label.find_all('span', class_='IssueLabel')
for label in labels:
name = label.text.strip()
desc_elem = label.find_text('div')
desc_str = desc_elem.text.strip()
label_desc = desc_str if desc_str else "N/A"
label_with_desc.append((name, label_desc))
return label_with_desc


def scrape_labels_all_pages(base_label_url) -> List[Tuple[str, str]]:
all_labels = []
page_number = 1
while True:
url = f"{base_label_url}?page={page_number}"
_labels = scrape_labels(url)
if not _labels:
break
all_labels += _labels
page_number += 1
return all_labels
Loading