1#!/usr/bin/env python 2 3import datetime 4import re 5import subprocess 6 7RELEASE = re.compile(r'[0-9]+\.[0-9]+\.[0-9]+') 8ISSUE = re.compile(r'#([0-9]+)') 9REVLIST = 'git rev-list develop --abbrev-commit --format="parents %p%n%B%n~~~" --max-count=200 develop' 10TEMPLATE = """ 11boto v{version} 12=========== 13 14:date: {date} 15 16Description goes here. 17 18 19Changes 20------- 21{changes} 22""" 23 24revisions = subprocess.check_output(REVLIST, shell=True, stderr=subprocess.STDOUT) 25 26commit_list = [] 27for hunk in revisions.split('~~~')[:-1]: 28 lines = hunk.strip().splitlines() 29 commit = lines[0].split(' ', 1)[1] 30 parents = lines[1].split(' ', 1)[1].split(' ') 31 message = ' '.join(lines[2:]) 32 33 # print(commit, parents) 34 35 if RELEASE.search(message): 36 print('Found release commit, stopping:') 37 print(message) 38 break 39 40 if len(parents) > 1: 41 commit_list.append([commit, message]) 42 43removals = [ 44 re.compile(r'merge pull request #[0-9]+ from [a-z0-9/_-]+', re.I), 45 re.compile(r"merge branch '[a-z0-9/_-]+' into [a-z0-9/_-]+", re.I), 46 re.compile(r'fix(es)? [#0-9, ]+.?', re.I) 47] 48 49changes = '' 50for commit, message in commit_list: 51 append = [] 52 issues = set() 53 for issue in ISSUE.findall(message): 54 if issue not in issues: 55 append.append(':issue:`{issue}`'.format(issue=issue)) 56 issues.add(issue) 57 append.append(':sha:`{commit}`'.format(commit=commit)) 58 append = ' (' + ', '.join(append) + ')' 59 60 original = message 61 for removal in removals: 62 message = removal.sub('', message) 63 64 message = message.strip() 65 66 if not message: 67 message = original.strip() 68 69 changes += '* ' + message + append + '\n' 70 71print(TEMPLATE.format( 72 version='?.?.?', 73 date=datetime.datetime.now().strftime('%Y/%m/%d'), 74 changes=changes 75)) 76