-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathautomerger.py
39 lines (33 loc) · 1.12 KB
/
automerger.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
import datetime
import config
import api
def print_message(merging, pr_id, user, head_ref, base_ref):
if merging == True:
message = "Merging: "
else:
message = "Not merging: "
print message + str(pr_id) + " - " + user + " wants to merge " + head_ref + " into " + base_ref
def merge(repo, pr_id):
data = api.merge_pr(repo, pr_id)
if "merged" in data and data["merged"]==True:
print "Merged: " + data['sha']
else:
print "Failed: " + data['message']
# Main
def run():
print "Running auto merger at: " + str(datetime.datetime.now())
for repo in config.am_repos:
data = api.get_prs(repo)
if data and 'message' in data[0].keys() and data[0]['message'] == "Not Found":
print "Repo %s not found, make sure it exists"%repo
else:
for i in data:
head_ref=i["head"]["ref"]
base_ref=i["base"]["ref"]
user=i["user"]["login"]
pr_id = i["number"]
if base_ref in config.am_ignore_branches:
print_message(False, pr_id, user, head_ref, base_ref)
else:
print_message(True, pr_id, user, head_ref, base_ref)
merge(repo, pr_id)