|
a/Allura/push_re.py |
|
b/Allura/push_re.py |
1 |
import os
|
1 |
import os
|
|
|
2 |
import re
|
2 |
import shlex
|
3 |
import shlex
|
3 |
import string
|
4 |
import string
|
4 |
import subprocess
|
5 |
import subprocess
|
|
|
6 |
from collections import defaultdict
|
5 |
from ConfigParser import ConfigParser
|
7 |
from ConfigParser import ConfigParser
|
6 |
from datetime import date
|
8 |
from datetime import date
|
|
|
9 |
from urlparse import urljoin
|
|
|
10 |
|
|
|
11 |
from allura.config import middleware
|
|
|
12 |
from allura.lib import rest_api
|
7 |
|
13 |
|
8 |
DEBUG=1
|
14 |
DEBUG=1
|
9 |
CP = ConfigParser()
|
15 |
CP = ConfigParser()
|
10 |
|
16 |
|
|
|
17 |
re_ticket_ref = re.compile(r'\[#\d+\]')
|
|
|
18 |
|
|
|
19 |
CRED={}
|
11 |
|
20 |
|
12 |
def main():
|
21 |
def main():
|
13 |
CP.read(os.path.join(os.environ['HOME'], '.forgepushrc'))
|
22 |
CP.read(os.path.join(os.environ['HOME'], '.forgepushrc'))
|
14 |
engineer = option('re', 'engineer', 'Name of engineer pushing: ')
|
23 |
engineer = option('re', 'engineer', 'Name of engineer pushing: ')
|
|
|
24 |
api_key = option('re', 'api_key', 'Forge API Key:')
|
|
|
25 |
secret_key = option('re', 'secret_key', 'Forge Secret Key:')
|
|
|
26 |
CRED['api_key'] = api_key
|
|
|
27 |
CRED['secret_key'] = secret_key
|
15 |
text, tag = make_ticket_text(engineer)
|
28 |
text, tag = make_ticket_text(engineer)
|
16 |
print '*** Create a ticket on SourceForge (https://sourceforge.net/p/allura/tickets/new/) with the following contents:'
|
29 |
print '*** Create a ticket on SourceForge (https://sourceforge.net/p/allura/tickets/new/) with the following contents:'
|
17 |
print '*** Summary: Production Push (R:%s, D:%s) - allura' % (
|
30 |
print '*** Summary: Production Push (R:%s, D:%s) - allura' % (
|
18 |
tag, date.today().strftime('%Y%m%d'))
|
31 |
tag, date.today().strftime('%Y%m%d'))
|
19 |
print '---BEGIN---'
|
32 |
print '---BEGIN---'
|
|
... |
|
... |
49 |
if last_release: last_release = last_release[-1]
|
62 |
if last_release: last_release = last_release[-1]
|
50 |
else: last_release = ''
|
63 |
else: last_release = ''
|
51 |
changes = command(
|
64 |
changes = command(
|
52 |
'git', 'log', "--format=* %h %s", last_release.strip() + '..')
|
65 |
'git', 'log', "--format=* %h %s", last_release.strip() + '..')
|
53 |
assert changes, 'There were no commits found; maybe you forgot to merge dev->master?'
|
66 |
assert changes, 'There were no commits found; maybe you forgot to merge dev->master?'
|
54 |
changes = ''.join(changes)
|
67 |
changelog = ''.join(changes)
|
|
|
68 |
changes = ''.join(format_changes(changes))
|
|
|
69 |
print 'Changelog:\n%s' % changelog
|
|
|
70 |
print 'Tickets:\n%s' % changes
|
55 |
prelaunch = []
|
71 |
prelaunch = []
|
56 |
postlaunch = []
|
72 |
postlaunch = []
|
57 |
needs_reactor_setup = raw_input('Does this release require a reactor_setup? [n]')
|
73 |
needs_reactor_setup = raw_input('Does this release require a reactor_setup? [n]')
|
58 |
needs_flyway = raw_input('Does this release require a migration? [y]')
|
74 |
needs_flyway = raw_input('Does this release require a migration? [y]')
|
59 |
if needs_reactor_setup[:1].lower() in ('y', '1'):
|
75 |
if needs_reactor_setup[:1].lower() in ('y', '1'):
|
|
... |
|
... |
73 |
prelaunch = [ 'From sfn-mongo do the following:\n' ] + prelaunch
|
89 |
prelaunch = [ 'From sfn-mongo do the following:\n' ] + prelaunch
|
74 |
prelaunch = '\n'.join(prelaunch)
|
90 |
prelaunch = '\n'.join(prelaunch)
|
75 |
else:
|
91 |
else:
|
76 |
prelaunch = '-none-'
|
92 |
prelaunch = '-none-'
|
77 |
return TICKET_TEMPLATE.substitute(locals()), tag
|
93 |
return TICKET_TEMPLATE.substitute(locals()), tag
|
78 |
|
94 |
|
|
|
95 |
def format_changes(changes):
|
|
|
96 |
ticket_groups = defaultdict(list)
|
|
|
97 |
for change in changes:
|
|
|
98 |
for m in re_ticket_ref.finditer(change):
|
|
|
99 |
ticket_groups[m.group(0)].append(change)
|
|
|
100 |
cli = rest_api.RestClient(
|
|
|
101 |
base_uri='http://sourceforge.net', **CRED)
|
|
|
102 |
for ref, commits in sorted(ticket_groups.iteritems()):
|
|
|
103 |
ticket_num = ref[2:-1]
|
|
|
104 |
ticket = cli.request(
|
|
|
105 |
'GET',
|
|
|
106 |
urljoin('/rest/p/allura/tickets/', str(ticket_num)) + '/')['ticket']
|
|
|
107 |
verb = {
|
|
|
108 |
'validation': 'Fix',
|
|
|
109 |
'closed': 'Fix' }.get(ticket['status'], 'Address')
|
|
|
110 |
yield ' * %s %s: %s\n' % (verb, ref, ticket['summary'])
|
79 |
|
111 |
|
80 |
def command(*args):
|
112 |
def command(*args):
|
81 |
if len(args) == 1 and isinstance(args[0], basestring):
|
113 |
if len(args) == 1 and isinstance(args[0], basestring):
|
82 |
argv = shlex.split(args[0])
|
114 |
argv = shlex.split(args[0])
|
83 |
else:
|
115 |
else:
|