-
Notifications
You must be signed in to change notification settings - Fork 0
/
handle_issues.py
executable file
·75 lines (62 loc) · 2.63 KB
/
handle_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
64
65
66
67
68
69
70
71
72
73
74
75
import requests
import constants
from handle_urls import HandleUrls
import config
class HandleIssues:
def __init__(self):
self.handle_urls = HandleUrls()
def split_message(self, msg):
"""split a message"""
text = ''
if msg != '':
if len(msg.split(' ', 1)) > 1:
text = msg.split(' ', 1)[1]
msg = msg.split(' ', 1)[0]
return msg, text
def new_issue(self, name, chat):
"""Create an Issue"""
payload = "{\n \"title\": \""+name+"\",\n \"labels\": [\n \"telegram\"\n ]\n}"
print(payload)
headers = {
'Content-Type': "application/json",
'Authorization': "token ".format(config.TOKEN_GITHUB),
'Cache-Control': "no-cache",
'Postman-Token': "91a68df35a9b2ddf80b57a6d28374a496bd0ba86"
}
response = requests.request("POST", constants.URL_GITHUB, data=payload, headers=headers)
print(response.text)
return self.handle_urls.send_message("New Issue created {}".format(name), chat)
def rename_issue(self, msg, chat):
"""rename a task by id"""
msg, text = self.split_message(msg)
if text == '':
self.handle_urls.send_message("""
You want to modify the issue {},
but you didn't provide any new text
""".format(msg), chat)
return
payload = "{\n \"title\": \""+text+"\",\n \"labels\": [\n \"telegram\"\n ]\n}"
print(payload)
headers = {
'Content-Type': "application/json",
'Authorization': "token 91a68df35a9b2ddf80b57a6d28374a496bd0ba86",
'Cache-Control': "no-cache",
'Postman-Token': "91a68df35a9b2ddf80b57a6d28374a496bd0ba86"
}
result = requests.request("GET", constants.URL_GITHUB + '/' + msg)
result_json = result.json()
print(result_json)
try:
result_json['state']
except:
return self.handle_urls.send_message("Issue does not exist", chat)
requests.request("POST", constants.URL_GITHUB+'/'+msg, data=payload, headers=headers)
return self.handle_urls.send_message("Issue renamed {}".format(text), chat)
def list_issues(self, chat):
"""lists all the issues active in the T--botcultural"""
issues = self.handle_urls.get_json_from_url(constants.URL_GITHUB)
msg = ''
msg += '\U0001F4CB Issues List\n\n'
for aux in issues:
msg += "[[{}]] - {}\n\n".format(str(aux['number']), aux['title'])
self.handle_urls.send_message(msg, chat)