-
Notifications
You must be signed in to change notification settings - Fork 0
/
issues_api.py
78 lines (51 loc) · 2.15 KB
/
issues_api.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
76
77
78
import requests
import argparse
from base64 import b64encode
import yaml
parser = argparse.ArgumentParser()
parser.add_argument('-n', '--n-delay', help='Number of delay seconds before performing an action', required=True)
parser.add_argument('-i', '--iterations', help='Number of iterations to perform', required=True)
args = parser.parse_args()
def load_config_file():
with open('./config.yaml') as file:
return yaml.safe_load(file)
def get_issues(token):
HEADERS = {
"Accept": "application/vnd.github.v3+json"
}
response = requests.get('https://api.github.com/repos/jasperan/github-utils/issues', headers=HEADERS, auth=('jasperan', token))
print(response.status_code)
assert response.status_code == 200
print('Obtained {} issues'.format(len(response.json())))
for x in response.json():
print(x.get('url'))
def post_issue(token, iteration):
HEADERS = {
"Accept": "application/vnd.github.v3+json"
}
DATA = '{}{}{}'.format('{"title":"', iteration, '"}')
response = requests.post('https://api.github.com/repos/jasperan/github-utils/issues', headers=HEADERS, data=DATA, auth=('jasperan', token))
print(response.status_code)
assert response.status_code == 201
print('Posted {}'.format(response.json().get('url')))
return response.json().get('number')
def close_issue(token, issue_number):
HEADERS = {
"Accept": "application/vnd.github.v3+json"
}
DATA = '{"state":"closed"}'
response = requests.patch('https://api.github.com/repos/jasperan/github-utils/issues/{}'.format(issue_number), headers=HEADERS, data=DATA, auth=('jasperan', token))
print(response.status_code)
assert response.status_code == 200
print('Closed #{}'.format(issue_number))
return response.status_code
def main():
data = load_config_file()
personal_access_token = data['personal_access_token']
#get_issues(personal_access_token)
print('Number of iterations: {}'.format(args.iterations))
for i in range(int(args.iterations)):
num = post_issue(personal_access_token, i)
close_issue(personal_access_token, num)
if __name__ == '__main__':
main()