-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathparse.py
More file actions
executable file
·82 lines (58 loc) · 2.18 KB
/
parse.py
File metadata and controls
executable file
·82 lines (58 loc) · 2.18 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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#!/usr/bin/env python
import re
import sys
import time
import datetime
import subprocess
DEFAULT_BRANCH_PATTERN = re.compile(r'^origin/release_\d{4}_\d{1,2}_\d{1,2}$')
def abort_merge():
cmd = "git reset --hard origin && git checkout master"
subprocess.call(cmd, shell=True)
def get_remote_branches(pattern=None, merged_only=False):
cmd = "git branch --remotes --list"
if merged_only:
cmd = "%s --merged origin/master" % cmd
branches = subprocess.check_output(cmd, shell=True).split()
if pattern:
branches = [branch for branch in branches if re.match(pattern, branch)]
return branches
def get_time_stamp(branch_name):
year, month, day = map(int, re.findall(r'\d+', branch_name)[:3])
return year * 10000 + month * 100 + day
def get_todays_time_stamp():
now = datetime.datetime.now()
return now.year * 10000 + now.month * 100 + now.day
def integrate(branches):
tag = "integration_%s" % int(time.mktime(time.localtime()))
cmd = "git checkout -b %s origin/master" % tag
print cmd
subprocess.call(cmd, shell=True)
dev_null = open("/dev/null", "wb")
for branch in branches:
cmd = "git merge --no-ff --quiet --no-edit %s" % branch
ret = subprocess.call(cmd, stdout=dev_null, shell=True)
print "Ret => %s" % ret
if ret != 0:
abort_merge()
print("ok, that's enough.")
sys.exit()
def main():
try:
pattern = sys.argv[1]
except IndexError:
pattern = DEFAULT_BRANCH_PATTERN
else:
pattern = re.compile(pattern)
all_branches = get_remote_branches(pattern=pattern)
merged_branches = get_remote_branches(pattern=pattern, merged_only=True)
unmerged_branches = list(set(all_branches) - set(merged_branches))
unmerged_legit_branches = filter(
lambda x: re.match(DEFAULT_BRANCH_PATTERN, x),
unmerged_branches)
print "Release branches to integrate:"
todays_time_stamp = get_todays_time_stamp()
branches_to_integrate = [b for b in unmerged_legit_branches
if get_time_stamp(b) >= todays_time_stamp]
integrate(branches_to_integrate)
if __name__ == '__main__':
main()