-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathpr-report-poster.py
50 lines (44 loc) · 1.61 KB
/
pr-report-poster.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
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
import requests
gh = GithubWrapper()
wv = WeaviateWrapper()
def main():
# Load the queue
crud = CRUD('queue.json')
queue = crud.get_all_needing_posting()
# Treat the reports
for item in queue:
repo_data = item[0]
pr_data = item[1]
session_id = repo_data['session_id']
pr_id = pr_data['id']
# Get the report from amicus.semantic-labs.com/pr/report/markdown/<session_id>
url = "https://amicus.semantic-labs.com/pr/report/markdown/{}".format(session_id)
result = requests.get(url)
document = result.json()["document"]
# Get the comment from amicus.semantic-labs.com/pr/report/comment/<session_id>
url = "https://amicus.semantic-labs.com/pr/report/comment/{}".format(session_id)
result = requests.get(url)
comment = result.json()["comment"]
# Get the PR
pr = gh.get_pull_request("{}/{}".format(repo_data['repo_owner'], repo_data['repo_name']), int(pr_id))
# Post a comment on the PR
utils.post_report(pr, comment)
# Index the report in Weaviate
utils.index_report(pr, document)
# Update the queue
crud.update_post_status(session_id, pr_id, "done")
if __name__ == '__main__':
if len(sys.argv) == 2:
if sys.argv[1] == "--deamon":
while True:
main()
time.sleep(1)
else:
main()