Fixed pattern for parsing co-authors

The exception was raised if tag co-authors existed in message,
but had wrong format. Added test for case when co-author email
is invalid.

Also changed activity log to print co-authors instead of original
author

Change-Id: I3fdf9295415720414f2522f22053181b51228b32
This commit is contained in:
Ilya Shakhat 2014-02-14 20:12:32 +04:00
parent 34f43995d2
commit be9efd7e2a
3 changed files with 25 additions and 19 deletions

View File

@ -69,17 +69,14 @@ show_record_type=True, show_user_gravatar=True, gravatar_size=32, show_all=True)
<div style="margin-left: {{ gravatar_size * 1.4 }}px;"> <div style="margin-left: {{ gravatar_size * 1.4 }}px;">
{% raw %} {% raw %}
<div class="header">{%html author_link %} ({%html company_link %})</div>
<div class="header">${date_str} in {%html module_link%}</div>
{%if coauthor %} {%if coauthor %}
<div class="header">Co-Authors: <div class="header">
{%each(index,value) coauthor %} {%each(index,value) coauthor %}{%if index>0 %}, {%/if%}{%html value.author_link %} ({%html value.company_link %}){%/each%}
{%if index>0 %},{%/if%}
{%html value.author_link %} ({%html value.company_link %})
{%/each%}
</div> </div>
{%else%}
<div class="header">{%html author_link %} ({%html company_link %})</div>
{%/if%} {%/if%}
<div class="header">${date_str} in {%html module_link%}</div>
{%if record_type == "commit" %} {%if record_type == "commit" %}
<div class="header">Commit &ldquo;${subject}&rdquo;</div> <div class="header">Commit &ldquo;${subject}&rdquo;</div>

View File

@ -68,18 +68,19 @@ GIT_LOG_PATTERN = re.compile(''.join([(r[0] + ':(.*?)\n')
'diff_stat:' + DIFF_STAT_PATTERN, 'diff_stat:' + DIFF_STAT_PATTERN,
re.DOTALL) re.DOTALL)
CO_AUTHOR_PATTERN_RAW = '(?P<author_name>.+?)\s*<(?P<author_email>.+)>'
CO_AUTHOR_PATTERN = re.compile(CO_AUTHOR_PATTERN_RAW, re.IGNORECASE)
MESSAGE_PATTERNS = { MESSAGE_PATTERNS = {
'bug_id': re.compile(r'bug[\s#:]*(?P<id>\d+)', re.IGNORECASE), 'bug_id': re.compile(r'bug[\s#:]*(?P<id>\d+)', re.IGNORECASE),
'blueprint_id': re.compile(r'\b(?:blueprint|bp)\b[ \t]*[#:]?[ \t]*' 'blueprint_id': re.compile(r'\b(?:blueprint|bp)\b[ \t]*[#:]?[ \t]*'
r'(?P<id>[a-z0-9-]+)', re.IGNORECASE), r'(?P<id>[a-z0-9-]+)', re.IGNORECASE),
'change_id': re.compile('Change-Id: (?P<id>I[0-9a-f]{40})', re.IGNORECASE), 'change_id': re.compile('Change-Id: (?P<id>I[0-9a-f]{40})', re.IGNORECASE),
'coauthor': re.compile(r'(?:Co-Authored|Also)-By:' 'coauthor': re.compile(r'(?:Co-Authored|Also)-By:'
r'\s*(?P<id>.*)\s', re.IGNORECASE) r'\s*(?P<id>%s)\s' % CO_AUTHOR_PATTERN_RAW,
re.IGNORECASE)
} }
CO_AUTHOR_PATTERN = re.compile(
r'(?P<author_name>.+?)\s*<(?P<author_email>.+)>', re.IGNORECASE)
class Git(Vcs): class Git(Vcs):
@ -228,14 +229,18 @@ class Git(Vcs):
for bp_name for bp_name
in commit['blueprint_id']] in commit['blueprint_id']]
coauthors = [] if 'coauthor' in commit:
for coauthor in commit.get('coauthor') or []: verified_coauthors = []
m = re.match(CO_AUTHOR_PATTERN, coauthor) for coauthor in commit['coauthor']:
if utils.check_email_validity(m.group("author_email")): m = re.match(CO_AUTHOR_PATTERN, coauthor)
coauthors.append(m.groupdict()) if m and utils.check_email_validity(
m.group("author_email")):
verified_coauthors.append(m.groupdict())
if coauthors: if verified_coauthors:
commit['coauthor'] = coauthors commit['coauthor'] = verified_coauthors
else:
del commit['coauthor'] # no valid authors
yield commit yield commit

View File

@ -84,6 +84,7 @@ author_name:John Doe
author_email:john.doe@dreamhost.com author_email:john.doe@dreamhost.com
subject:add readme for 2.2.2 subject:add readme for 2.2.2
message: implements blueprint fix-me. message: implements blueprint fix-me.
Co-Authored-By: Anonymous <wrong@email>
Change-Id: Id32a4a72ec1d13992b306c4a38e73605758e26c7 Change-Id: Id32a4a72ec1d13992b306c4a38e73605758e26c7
diff_stat: diff_stat:
@ -95,6 +96,7 @@ author_name:Doug Hoffner
author_email:mark.mcclain@dreamhost.com author_email:mark.mcclain@dreamhost.com
subject:add readme for 2.2.2 subject:add readme for 2.2.2
message:Change-Id: Id32a4a72ec1d13992b306c4a38e73605758e26c7 message:Change-Id: Id32a4a72ec1d13992b306c4a38e73605758e26c7
Co-Authored-By: some friend of mine
diff_stat: diff_stat:
@ -109,6 +111,7 @@ subject:adds support off co-authors
message:Change-Id: Id811c762ec1d13992b306c4a38e7360575e61451 message:Change-Id: Id811c762ec1d13992b306c4a38e7360575e61451
Co-Authored-By: Tupac Shakur <tupac.shakur@openstack.com> Co-Authored-By: Tupac Shakur <tupac.shakur@openstack.com>
Also-By: Bob Dylan <bob.dylan@openstack.com> Also-By: Bob Dylan <bob.dylan@openstack.com>
Also-By: Anonymous <wrong@email>
diff_stat: diff_stat:
@ -140,6 +143,7 @@ diff_stat:
self.assertEqual(0, commits[3]['lines_deleted']) self.assertEqual(0, commits[3]['lines_deleted'])
self.assertEqual(set(['dummy:fix-me']), self.assertEqual(set(['dummy:fix-me']),
set(commits[3]['blueprint_id'])) set(commits[3]['blueprint_id']))
self.assertFalse('coauthor' in commits[3])
self.assertEqual(0, commits[4]['files_changed']) self.assertEqual(0, commits[4]['files_changed'])
self.assertEqual(0, commits[4]['lines_added']) self.assertEqual(0, commits[4]['lines_added'])