comment works

This commit is contained in:
zhangxunhui 2021-08-13 23:15:41 +08:00
parent 18f54db8cd
commit 3653a6acbc
1 changed files with 25 additions and 0 deletions

25
app/services/comments.py Normal file
View File

@ -0,0 +1,25 @@
# the services related to labels
import sys, requests
sys.path.append("././")
import json
from app.services.authentication import getToken
from app.models.pr_comment import PRComment
from app.models.trigger import *
def return_pr_decision(prTrigger: PRTrigger) -> bool:
try:
token = getToken(prTrigger.installation)
comment = PRComment(pr=prTrigger.pr, body="This is the decision from bot")
headers = {'Authorization': 'token ' + token, 'Accept': 'application/vnd.github.v3+json'}
url = "https://api.github.com/repos/{owner}/{repo}/issues/{pull_request_number}/comments".format(owner=comment.pr.owner.login, repo=comment.pr.repo.name, pull_request_number=comment.pr.number)
data = {"body": comment.body}
response = requests.post(url, data=json.dumps(data), headers=headers)
if response.status_code != 200:
raise Exception("error with func return_pr_decision: code: %s, message: %s" % (response.status_code, json.loads(response.text)["message"]))
print("pause")
except Exception as e:
print("error with func return_pr_decision: %s" % (repr(e)))
if __name__ == "__main__":
return_pr_decision()