Skip to content

Commit

Permalink
Formatted
Browse files Browse the repository at this point in the history
  • Loading branch information
nikhil25803 committed Feb 24, 2023
1 parent cdf37a1 commit efac273
Show file tree
Hide file tree
Showing 5 changed files with 259 additions and 198 deletions.
40 changes: 23 additions & 17 deletions src/scrape_up/github/issue.py
Original file line number Diff line number Diff line change
@@ -1,28 +1,32 @@
import requests
from bs4 import BeautifulSoup

class Issue:

def __init__(self, username: str, repository_name:str, issue_number:int):
class Issue:
def __init__(self, username: str, repository_name: str, issue_number: int):
self.username = username
self.repository = repository_name
self.issue_number = issue_number

def __scrape_page(self):
data = requests.get(f"https://github.com/{self.username}/{self.repository}/issues/{self.issue_number}")
data = BeautifulSoup(data.text,"html.parser")
data = requests.get(
f"https://github.com/{self.username}/{self.repository}/issues/{self.issue_number}"
)
data = BeautifulSoup(data.text, "html.parser")
return data

def assignees(self):
"""
Fetch list of assignees
"""
data = self.__scrape_page()
try:
assignees_body = data.find('span', class_='css-truncate js-issue-assignees')
assignees_body = data.find("span", class_="css-truncate js-issue-assignees")
assignees = []
for assignee in assignees_body.find_all('a', class_='assignee Link--primary css-truncate-target width-fit'):
assignees.append(assignee.text.replace('\n','').strip())
for assignee in assignees_body.find_all(
"a", class_="assignee Link--primary css-truncate-target width-fit"
):
assignees.append(assignee.text.replace("\n", "").strip())
return assignees
except:
message = "No assignees found"
Expand All @@ -34,8 +38,10 @@ def labels(self):
"""
data = self.__scrape_page()
try:
labelsDiv = data.find(class_ = "js-issue-labels d-flex flex-wrap")
allLabelsHtml = labelsDiv.find_all(class_="css-truncate css-truncate-target width-fit")
labelsDiv = data.find(class_="js-issue-labels d-flex flex-wrap")
allLabelsHtml = labelsDiv.find_all(
class_="css-truncate css-truncate-target width-fit"
)
allLabels = []
for label in allLabelsHtml:
allLabels.append(label.text)
Expand All @@ -44,36 +50,34 @@ def labels(self):
message = "No label found"
return message


def opened_by(self):
"""
Fetch the name of the user, who opened the issue
"""
data = self.__scrape_page()
author_name = data.find('a', class_='author text-bold Link--secondary').text
author_name = data.find("a", class_="author text-bold Link--secondary").text
return author_name


def title(self):
"""
Fetch title of the issue
"""
data = self.__scrape_page()
try:
title_body = data.find('bdi', class_="js-issue-title markdown-title")
title_body = data.find("bdi", class_="js-issue-title markdown-title")
title = title_body.text.strip()
return title
except:
message = "No title found"
return message

def opened_at(self):
"""
Returns a string containing the time when the issue was opened in ISO format
"""
try:
data = self.__scrape_page()
return data.find('relative-time').text
return data.find("relative-time").text
except:
message = "Unable to fetch time"
return message
Expand All @@ -84,7 +88,9 @@ def is_milestone(self):
"""
data = self.__scrape_page()
try:
milestone = data.find('a', class_='Link--secondary mt-1 d-block text-bold css-truncate').text.strip()
milestone = data.find(
"a", class_="Link--secondary mt-1 d-block text-bold css-truncate"
).text.strip()
return milestone
except:
message = "No milestone"
Expand Down
Loading

0 comments on commit efac273

Please sign in to comment.