-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathgithub.py
More file actions
61 lines (48 loc) · 1.96 KB
/
github.py
File metadata and controls
61 lines (48 loc) · 1.96 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
import re
from typing import List
from github import Github
from datetime import datetime
from src.issue_wrapper.wrapper import Wrapper, Pagination, CommentMeta
class GitHubIssueWrapper(Wrapper):
def __init__(self, url: str):
match = re.search(r"github\.com/([^/]+)/([^/]+)/issues/(\d+)", url)
if not match:
raise ValueError("Invalid GitHub issue URL format.")
owner = match.group(1)
repo_name = match.group(2)
issue_number = int(match.group(3))
self.issue_data = (
Github().get_repo(f"{owner}/{repo_name}").get_issue(number=issue_number)
)
def issue_title(self) -> str:
return self.issue_data.title
def issue_key(self) -> str:
return str(self.issue_data.number)
def issue_description(self) -> str:
return self.issue_data.body
def issue_author(self) -> str:
return self.issue_data.user.login
def issue_created_at(self) -> datetime:
return self.issue_data.created_at
def issue_closed_at(self) -> datetime:
return self.issue_data.closed_at
def issue_comments(self, pagination: Pagination) -> List[CommentMeta]:
comments = self.issue_data.get_comments()
comments = comments[pagination.offset : pagination.offset + pagination.limit]
comment_meta_list = []
for comment in comments:
comment_meta = CommentMeta(
author=comment.user.login,
body=comment.body,
created_at=str(comment.created_at),
)
comment_meta_list.append(comment_meta)
return comment_meta_list
def issue_participants(self) -> List[str]:
participants = set()
for assignee in self.issue_data.assignees:
participants.add(assignee.login)
for comment in self.issue_data.get_comments():
participants.add(comment.user.login)
participants.add(self.issue_author())
return list(participants)