-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathcomment.py
More file actions
53 lines (36 loc) · 1.28 KB
/
comment.py
File metadata and controls
53 lines (36 loc) · 1.28 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
from datetime import datetime
from typing import Dict, Any
from src.utils import parse_date_string
from .user import User
import copy
class Comment(object):
def __init__(self, raw_comment: Dict[str, Any]):
self._raw = copy.deepcopy(raw_comment)
def id(self) -> str:
return self._raw["id"]
def published_at(self) -> datetime:
return parse_date_string(self._raw["publishedAt"])
def body(self) -> str:
return self._raw["body"]
def body_html(self) -> str:
return self._raw["bodyHTML"]
def author_handle(self) -> str:
return self.author().login()
def author(self) -> User:
return User(self._raw["author"])
def to_raw(self) -> Dict[str, Any]:
return copy.deepcopy(self._raw)
def url(self) -> str:
return self._raw["url"]
class IssueComment(Comment):
pass
class PullRequestReviewComment(Comment):
def raw_review(self) -> dict:
return self._raw["pullRequestReview"]
def comment_factory(raw: Dict[str, Any]) -> Comment:
if raw["__typename"] == "IssueComment":
return IssueComment(raw)
elif raw["__typename"] == "PullRequestReviewComment":
return PullRequestReviewComment(raw)
else:
raise Exception(f"Unexpected type found: {raw['__typename']}")