This repository has been archived by the owner on Mar 24, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathissues.py
63 lines (52 loc) · 2.2 KB
/
issues.py
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
62
63
# bot modules
from bot.question.base import Question, QuestionOriginNotSet
from bot.database.sqlite import Database
class IssueQuestion(Question):
"""Question originating from GitHube issues"""
def __init__(
self, question_text=None, start_idx=None, end_idx=None, question_id=None
):
super().__init__(question_text, start_idx, end_idx, question_id, "issue")
def set_origin_id(self, origin_id):
"""
Sets the origin id of a given question.
Possible origins:
- email_id
- issue_id
- comment_id
<!> Note: Ids from different origin left None.
:param origin_id : id of a given question's origin
"""
self.email_id = None
self.issue_id = origin_id
self.comment_id = None
def find_context_from_table(self, db=Database, table_name="issues"):
"""
Depending on the question's origin, find the corresponding
context based on the appropriate table.
- issues : The context are the bodies of the comments under
the issue.
<!> Note: The origin_id of the issue needs to have been set by
calling set_origin_id() before using this method.
:param db : <bot.database obj>
:param table_name : name of the table where the context exists
"""
if self.issue_id is not None:
self.clean_body, self.num_comments = db.query(
f"""SELECT clean_body, comments
FROM {table_name}
WHERE issue_id == {self.issue_id}"""
)[0]
assert self.num_comments != 0
result = db.query(
f"""SELECT clean_body
FROM issue_comments
WHERE issue_id == "{self.issue_id}"
ORDER BY created_at ASC
"""
)
self.context = " ".join([res[0] for res in result])
else:
raise QuestionOriginNotSet(
f"\nError: The issue_id for the Question object has not been set.Try using set_origin_id() method."
)