Adds support of co-authors of a patchset merged in openstack
According to the recommendation of the openstack wiki, every patchset merged in openstack with in the commit message a flag 'co-authored-by' or 'also-by' will be considered for the commits statistics. Examples: Co-Authored-By: An User <user@os.org> Also-By: An User 2 <user2@os.org> Change-Id: Ia58235c129061942963d34f860230097c64a9828 Implements: blueprint add-support-co-authored-by
This commit is contained in:
		| @@ -73,8 +73,13 @@ MESSAGE_PATTERNS = { | |||||||
|     '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), | ||||||
|  |     'co-author': re.compile(r'(?:Co-Authored|Also)-By:' | ||||||
|  |                             r'\s*(?P<id>.*)\s', re.IGNORECASE) | ||||||
| } | } | ||||||
|  |  | ||||||
|  | CO_AUTHOR_PATTERN = re.compile( | ||||||
|  |     r'(?P<author_name>.+)\s*<(?P<author_email>.+)>', re.IGNORECASE) | ||||||
|  |  | ||||||
|  |  | ||||||
| class Git(Vcs): | class Git(Vcs): | ||||||
|  |  | ||||||
| @@ -216,6 +221,7 @@ class Git(Vcs): | |||||||
|                 commit['release'] = self.release_index[commit['commit_id']] |                 commit['release'] = self.release_index[commit['commit_id']] | ||||||
|             else: |             else: | ||||||
|                 commit['release'] = None |                 commit['release'] = None | ||||||
|  |  | ||||||
|             if 'blueprint_id' in commit: |             if 'blueprint_id' in commit: | ||||||
|                 commit['blueprint_id'] = [(commit['module'] + ':' + bp_name) |                 commit['blueprint_id'] = [(commit['module'] + ':' + bp_name) | ||||||
|                                           for bp_name |                                           for bp_name | ||||||
| @@ -223,6 +229,15 @@ class Git(Vcs): | |||||||
|  |  | ||||||
|             yield commit |             yield commit | ||||||
|  |  | ||||||
|  |             # Handles co-authors in the commit message. According to the bp | ||||||
|  |             # we want to count contribution for authors and co-authors. | ||||||
|  |             if 'co-author' in commit: | ||||||
|  |                 for coauthor in commit['co-author']: | ||||||
|  |                     m = re.match(CO_AUTHOR_PATTERN, coauthor) | ||||||
|  |                     if utils.check_email_validity(m.group("author_email")): | ||||||
|  |                         commit.update(m.groupdict()) | ||||||
|  |                         yield commit | ||||||
|  |  | ||||||
|     def get_last_id(self, branch): |     def get_last_id(self, branch): | ||||||
|         LOG.debug('Get head commit for repo uri: %s', self.repo['uri']) |         LOG.debug('Get head commit for repo uri: %s', self.repo['uri']) | ||||||
|  |  | ||||||
|   | |||||||
| @@ -99,10 +99,26 @@ message:Change-Id: Id32a4a72ec1d13992b306c4a38e73605758e26c7 | |||||||
| diff_stat: | diff_stat: | ||||||
|  |  | ||||||
|  0 files changed, 0 insertions(+), 0 deletions(-) |  0 files changed, 0 insertions(+), 0 deletions(-) | ||||||
|  |  | ||||||
|  |  0 files changed | ||||||
|  | commit_id:12811c76f3a8208b36f81e61451ec17d227b4e58 | ||||||
|  | date:1369831203 | ||||||
|  | author_name:Jimi Hendrix | ||||||
|  | author_email:jimi.hendrix@openstack.com | ||||||
|  | subject:adds support off co-authors | ||||||
|  | message:Change-Id: Id811c762ec1d13992b306c4a38e7360575e61451 | ||||||
|  | Co-Authored-By: Tupac Shakur <tupac.shakur@openstack.com> | ||||||
|  | Also-By: Bob Dylan <bob.dylan@openstack.com> | ||||||
|  |  | ||||||
|  | diff_stat: | ||||||
|  |  | ||||||
|  |  0 files changed, 0 insertions(+), 0 deletions(-) | ||||||
|  |  | ||||||
|             ''' |             ''' | ||||||
|  |  | ||||||
|         commits = list(self.git.log('dummy', 'dummy')) |         commits = list(self.git.log('dummy', 'dummy')) | ||||||
|         self.assertEqual(5, len(commits)) |         commits_expected = 6 + 2  # authors + co-authors | ||||||
|  |         self.assertEqual(commits_expected, len(commits)) | ||||||
|  |  | ||||||
|         self.assertEqual(21, commits[0]['files_changed']) |         self.assertEqual(21, commits[0]['files_changed']) | ||||||
|         self.assertEqual(340, commits[0]['lines_added']) |         self.assertEqual(340, commits[0]['lines_added']) | ||||||
| @@ -128,3 +144,8 @@ diff_stat: | |||||||
|         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']) | ||||||
|         self.assertEqual(0, commits[4]['lines_deleted']) |         self.assertEqual(0, commits[4]['lines_deleted']) | ||||||
|  |  | ||||||
|  |         self.assertEqual( | ||||||
|  |             ['Tupac Shakur <tupac.shakur@openstack.com>', | ||||||
|  |              'Bob Dylan <bob.dylan@openstack.com>'], | ||||||
|  |             commits[5]['co-author']) | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user
	 Sahid Orentino Ferdjaoui
					Sahid Orentino Ferdjaoui