-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_me.py
More file actions
67 lines (56 loc) · 2.16 KB
/
test_me.py
File metadata and controls
67 lines (56 loc) · 2.16 KB
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
import json
import requests
from pprint import pprint
#curl -sb -H "Accept: application/json" -u tosoth:123123 http://localhost:7990/rest/api/1.0/projects/TRVCHEF/repos/trv_chef/pull-requests/1/activities > /tmp/1
def get_pr_detail(my_id):
auth='tosoth:123123'
url='http://localhost:7990/rest/api/1.0/projects/TRVCHEF/repos/trv_chef/pull-requests/'+str(my_id)+'/activities'
headers={'Content-type': 'application/json'}
r = requests.get(url, headers=headers, auth=('tosoth', '123123'))
with open('/tmp/1','w') as f:
f.write(r.text)
r.close()
def handle(my_id):
print "handle "+str(my_id)
with open('/tmp/'+str(my_id)) as f:
data = json.load(f)
values=data["values"]
for i in values:
if i[u'action'] == u'COMMENTED' and i[u'comment'][u'text'] == 'test me':
print "found test me "+str(my_id)
replies = i[u'comment'][u'comments']
if replies == []:
print "BINGO! "+str(my_id)
id=i[u'comment'][u'id']
reply(id, "test done1")
else:
print "already handled before "+str(my_id)
def reply(id, content):
auth='tosoth:123123'
url='http://localhost:7990/rest/api/1.0/projects/TRVCHEF/repos/trv_chef/pull-requests/1/comments'
payload='{"text": "'+content+'","parent": {"id":'+str(id)+'}}'
headers={'Content-type': 'application/json'}
r = requests.post(url, data=payload, headers=headers, auth=('tosoth', '123123'))
print r
r.close()
def get(url):
url='http://localhost:7990/rest/api/1.0/projects/TRVCHEF/repos/trv_chef/pull-requests'
headers={'Content-type': 'application/json'}
r = requests.get(url, headers=headers, auth=('tosoth', '123123'))
r.close()
if True:
url='http://localhost:7990/rest/api/1.0/projects/TRVCHEF/repos/trv_chef/pull-requests'
headers={'Content-type': 'application/json'}
r = requests.get(url, headers=headers, auth=('tosoth', '123123'))
pr_text = r.text
r.close()
with open('/tmp/pr','w') as f:
f.write(pr_text)
with open('/tmp/pr') as f:
data_pr = json.load(f)
for i in data_pr["values"]:
pr_content=i[u'description']
pr_id=i[u'id']
print pr_id
get_pr_detail(pr_id)
handle(pr_id)