-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathgit_repo.py
57 lines (50 loc) · 1.97 KB
/
git_repo.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
import os
import requests
import json
import repository
def get_auth():
return (os.environ.get('GITHUB_USERNAME'), os.environ.get("GITHUB_PASS"))
def get_pulls():
url = "https://api.github.com/repos/{}/{}/pulls".format(os.environ.get("GITHUB_USERNAME"), os.environ.get("GITHUB_REPO"))
auth = get_auth()
response = json.loads(requests.get(url, auth=get_auth()).text)
return response
def get_players():
url = "https://api.github.com/repos/{}/{}/collaborators".format(os.environ.get("GITHUB_USERNAME"), os.environ.get("GITHUB_REPO"))
response = requests.get(url, auth=get_auth())
player_data = json.loads(response.text)
players = []
for player in player_data:
if player['login'] != os.environ.get("GITHUB_USERNAME"):
players.append(player['login'])
return players
def get_votes(pull_id):
url = "https://api.github.com/repos/{}/{}/pulls/{}/reviews".format(os.environ.get("GITHUB_USERNAME"), os.environ.get("GITHUB_REPO"), pull_id)
response = requests.get(url, auth=get_auth())
approved = []
rejected = []
for review in json.loads(response.text):
if review['state'] == "APPROVED":
approved.append(review)
else:
rejected.append(review)
return (approved, rejected)
def merge(pull):
url = "https://api.github.com/repos/{}/{}/pulls/{}/merge".format(os.environ.get("GITHUB_USERNAME"), os.environ.get("GITHUB_REPO"), pull['number'])
response = requests.put(url, auth=get_auth(), data={})
if response.status_code == 200:
#Merge was successful
return True
else:
#Something went wrong. Oh well.
return response.status_code
def close(pull):
url = "https://api.github.com/repos/{}/{}/pulls/{}".format(os.environ.get("GITHUB_USERNAME"), os.environ.get("GITHUB_REPO"), pull['number'])
payload = {"state" : "closed"}
response = requests.post(url, auth=get_auth(), data=json.dumps(payload))
if response.status_code == 200:
#Close was successful
return True
else:
#Something went wrong. Oh well.
return response.text