Skip to content

Commit

Permalink
Builder: Group commits by prefixed tags
Browse files Browse the repository at this point in the history
If a commit has no tag but the tag appears somewhere in the subject,
the commit gets a guessed tag (<tag guessed="true">).

The prefix is removed from the subject line.

RSS: Group commits by tag.
  • Loading branch information
skyjake committed Jan 4, 2012
1 parent ad5244e commit 362933f
Showing 1 changed file with 86 additions and 11 deletions.
97 changes: 86 additions & 11 deletions distrib/builder/changes.py
Expand Up @@ -26,9 +26,21 @@ def __init__(self):
self.link = ''
self.hash = ''
self.message = ''
self.tags = []
self.guessedTags = []

def setSubject(self, subject):
self.extra = ''

# Remote tags from the subject.
pos = subject.find(':')
if subject[pos + 1] in string.whitespace:
for tag in subject[:pos].split('|'):
self.tags.append(tag.strip())
subject = subject[pos + 1:].strip()

if len(subject) == 0: subject = "Commit"

# Check that the subject lines are not too long.
MAX_SUBJECT = 100
if len(utils.collated(subject)) > MAX_SUBJECT:
Expand Down Expand Up @@ -123,15 +135,34 @@ def parse(self):

if not self.should_ignore(entry.subject):
self.entries.append(entry)


self.deduce_tags()

def all_tags(self):
tags = ['Cleanup', 'Fixed', 'Added', 'Refactor', 'Performance', 'Optimize']
for e in self.entries:
for t in e.tags + e.guessedTags:
if t not in tags:
tags.append(t)
return tags

def deduce_tags(self):
# Look for known tags in untagged titles.
allTags = self.all_tags()
for entry in self.entries:
if entry.tags: continue
# This entry has no tags yet.
for tag in allTags:
if tag.lower() in entry.subject.lower():
entry.guessedTags.append(tag)

def generate(self, format):
fromTag = self.fromTag
toTag = self.toTag

if format == 'html':
out = file(Event(toTag).file_path('changes.html'), 'wt')

MAX_COMMITS = 100
entries = self.entries[:MAX_COMMITS]

Expand All @@ -140,16 +171,53 @@ def generate(self, format):
print >> out, 'The <a href="%s">oldest commit</a> is dated %s.</p>' % \
(self.entries[-1].link, self.entries[-1].date)

print >> out, '<ol>'

# Write a list entry for each commit.
for entry in entries:
print >> out, '<li><b>%s</b><br/>' % entry.subject
print >> out, 'by <i>%s</i> on %s' % (entry.author, entry.date)
print >> out, '<a href="%s">(show in repository)</a>' % entry.link
print >> out, '<blockquote>%s</blockquote>' % entry.message
# Form groups.
groups = {}
for tag in self.all_tags():
groups[tag] = []
for e in entries:
if tag in e.tags:
groups[tag].append(e)
for e in entries:
if tag in e.guessedTags:
groups[tag].append(e)

for e in groups[tag]:
entries.remove(e)

groups['Other'] = []
for e in entries:
groups['Other'].append(e)

keys = groups.keys()
keys.sort(cmp=lambda a, b: cmp(str(a).lower(), str(b).lower()))
for group in keys:
if not len(groups[group]): continue

print >> out, '<h3>%s</h3>' % group
print >> out, '<ul>'

# Write a list entry for each commit.
for entry in groups[group]:
otherGroups = []
for tag in entry.tags + entry.guessedTags:
if tag != group:
otherGroups.append(tag)
others = ''
if len(otherGroups) > 1:
others = string.join(otherGroups[:-1], ', ')
others += ' and ' + otherGroups[-1]
elif len(otherGroups) == 1:
others = otherGroups[0]

if others: others = ' <i>(also %s)</i>' % others

print >> out, '<li><b>%s</b>%s<br/>' % (entry.subject, others)
print >> out, 'by <i>%s</i> on ' % entry.author
print >> out, '<a href="%s">%s</a>' % (entry.link, entry.date)
print >> out, '<blockquote style="color:#808080;">%s</blockquote>' % entry.message

print >> out, '</ol>'
print >> out, '</ul>'
out.close()

elif format == 'xml':
Expand All @@ -162,6 +230,13 @@ def generate(self, format):
print >> out, '<author>%s</author>' % entry.author
print >> out, '<repositoryUrl>%s</repositoryUrl>' % entry.link
print >> out, '<sha1>%s</sha1>' % entry.hash
if entry.tags or entry.guessedTags:
print >> out, '<tags>'
for t in entry.tags:
print >> out, '<tag>%s</tag>' % t
for t in entry.guessedTags:
print >> out, '<tag guessed="true">%s</tag>' % t
print >> out, '</tags>'
print >> out, '<title>%s</title>' % entry.subject
if len(entry.message):
print >> out, '<message>%s</message>' % entry.message
Expand Down

0 comments on commit 362933f

Please sign in to comment.