-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathpr-chat-main.py
48 lines (41 loc) · 1.46 KB
/
pr-chat-main.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
import os, sys, time, json
from dotenv import load_dotenv
load_dotenv()
from lib.GitHubWrapper import GithubWrapper
from lib.WeaviateWrapper import WeaviateWrapper
import lib.AmicusUtils as utils
from lib.crud import CRUD
from lib.GPTReportChat import GPTReportChat
gh = GithubWrapper()
wv = WeaviateWrapper()
chat = GPTReportChat()
CALLOUT = '@semantic-labs'
def main():
# Load the queue
crud = CRUD('queue.json')
items = crud.get_all_posted()
print(items)
for item in items:
# Split up tuple into repo and pr
repo_data = item[0]
pr_data = item[1]
pr = gh.get_pull_request("{}/{}".format(repo_data['repo_owner'], repo_data['repo_name']), int(pr_data['id']))
# Read last comment
comments = pr.get_issue_comments()
if comments.totalCount == 0:
continue
last_comment = comments.reversed.get_page(0)[-1]
if last_comment.body.lower().strip().startswith(CALLOUT.lower()):
print("Comment received: {}".format(last_comment.body))
chunks = utils.get_query_vector_chunks(pr, last_comment.body)
reply = chat.reply_to_comment(last_comment.body, chunks, last_comment.user.login)
print("Replying: {}".format(reply))
pr.create_issue_comment(reply)
if __name__ == '__main__':
if len(sys.argv) == 2:
if sys.argv[1] == "--deamon":
while True:
main()
time.sleep(1)
else:
main()