-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathgithub_milestones_configure.py
executable file
·100 lines (80 loc) · 2.66 KB
/
github_milestones_configure.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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
#!/usr/bin/python
from github import Github
from json import dump
from datetime import date, datetime, timedelta
from calendar import monthrange
from itertools import ifilter
import argparse
from github_release_config import *
g = Github(USERNAME, OAUTH_TOKEN)
q = g.get_user(ORGANISATION)
data = {}
parser = argparse.ArgumentParser()
parser.add_argument('--create', metavar='MILESTONE', type=str)
parser.add_argument('--close', metavar='MILESTONE', type=str)
args = parser.parse_args()
#import sys
#sys.exit()
today = date.today()
month = today.month
def add_months(sourcedate, months):
month = sourcedate.month - 1 + months
year = sourcedate.year + month / 12
month = month % 12 + 1
day = min(sourcedate.day, monthrange(year,month)[1])
return date(year, month, day)
# Ensure we have an even numbered month!
if month % 2 > 0:
month += 1
today = date(today.year, month, 1)
m_future = []
for m in range(1, 4):
n = add_months(today, m*2)
m_future.append((n.year, n.month))
del today
# Collect data
for r in REPOS:
print r
repo = q.get_repo(r)
data[r] = []
m_open = repo.get_milestones(state='open')
m_closed = repo.get_milestones(state='closed')
m_all = []
print ' Closed'
for m in m_closed:
print ' %s' % m.title
m_all.append(m.title)
if m.due_on >= datetime.now() - timedelta(1):
m.edit(m.title, state='open')
print ' Opening'
print ' Open'
for m in m_open:
print ' %s' % m.title
m_all.append(m.title)
release = m.title.split('.')
if len(release) == 2:
if m.title == '16.4':
m.edit(m.title, due_on=date(2016, 5, 20))
print ' Pushed back due date for 16.4'
if m.due_on:
if m.due_on < datetime.now() - timedelta(1):
m.edit(m.title, state='closed')
print ' Closing'
else:
year = int('20' + release[0])
month = int(release[1])
day = monthrange(year, month)[-1]
m.edit(m.title, due_on=date(year, month, day))
print ' Updated due date'
else:
print ' Point release, will not modify'
#print ' Checking future milestones'
#for year, month in m_future:
# n = "%d.%d" % (year-2000, month)
# if n not in m_all:
# print ' %s not found - creating' % n
# day = monthrange(year, month)[-1]
# repo.create_milestone(title=n, due_on=date(year, month, day))
print # Seperator
with open('/tmp/github-milestones.json', 'w') as f:
dump(data, f)