Skip to content

Instantly share code, notes, and snippets.

@richardbuckle
Created August 16, 2014 07:35
Show Gist options
  • Save richardbuckle/3024e53c01c80e969fd7 to your computer and use it in GitHub Desktop.
Save richardbuckle/3024e53c01c80e969fd7 to your computer and use it in GitHub Desktop.
Format your Git change log into markdown for nightly builds
#! /usr/bin/env python
'''
Format the Git log between current and master into the markdown required for the HockeyApp nightly builds.
'''
import os
import re
ticketRegex = re.compile(r'#(\d+)')
ticketReplacement = r'[#\1](https://www.example.com/blah/tickets/\1)'
def preamble():
print '''## Nightly build for QA
Built from branch `"%s"` with SHA `%s`.
The technical change log since the last build shipped to the App Store follows:
''' % (currentBranch(), currentHash())
def printMarkdown(line):
if line.startswith('New version'):
# format as markdown heading 3
line = '\n### %s' % line
else:
# format as markdown bullet point, italicizing any merge commits
line = italicizeMerges(line)
line = '* %s' % linkTickets(line)
print line,
def italicizeMerges(line):
'''Detect and italicize merge commits'''
if line.startswith('Merge branch'):
# slice off the trailing newline and italicize, restoring the newline
line = '_%s_\n' % line[:-1]
return line
def linkTickets(line):
'''Detect and hyperlink ticket numbers'''
return ticketRegex.sub(ticketReplacement, line)
def currentBranch():
'''Return the current Git branch'''
command = 'git symbolic-ref --short --quiet HEAD'
f = os.popen(command)
return f.readlines()[0][:-1]
def currentHash():
'''Return the current Git hash'''
command = 'git show-ref --hash --head HEAD'
f = os.popen(command)
return f.readlines()[0][:-1]
def readLog():
'''Scan the Git log and format it into markdown'''
command = 'git log --pretty=format:%%s master..%s' % currentBranch()
f = os.popen(command)
for line in f.readlines():
printMarkdown(line)
print "\n"
def main():
preamble()
readLog()
if __name__ == "__main__":
main()
@richardbuckle
Copy link
Author

Sorry about the 8-space indentation. That was gist, not me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment