diff options
-rw-r--r-- | AUTHORS | 1 | ||||
-rw-r--r-- | git/objects/commit.py | 22 | ||||
-rw-r--r-- | test/test_commit.py | 11 |
3 files changed, 34 insertions, 0 deletions
@@ -48,4 +48,5 @@ Contributors are: -Hiroki Tokunaga <tokusan441 _at_ gmail.com> -Julien Mauroy <pro.julien.mauroy _at_ gmail.com> -Patrick Gerard +-Luke Twist <itsluketwist@gmail.com> Portions derived from other open source works and are clearly marked. diff --git a/git/objects/commit.py b/git/objects/commit.py index 66cb9191..65c94f23 100644 --- a/git/objects/commit.py +++ b/git/objects/commit.py @@ -4,6 +4,7 @@ # This module is part of GitPython and is released under # the BSD License: http://www.opensource.org/licenses/bsd-license.php import datetime +import re from subprocess import Popen, PIPE from gitdb import IStream from git.util import hex_to_bin, Actor, Stats, finalize_process @@ -738,3 +739,24 @@ class Commit(base.Object, TraversableIterableObj, Diffable, Serializable): return self # } END serializable implementation + + @property + def co_authors(self) -> List[Actor]: + """ + Search the commit message for any co-authors of this commit. + Details on co-authors: https://github.blog/2018-01-29-commit-together-with-co-authors/ + + :return: List of co-authors for this commit (as Actor objects). + """ + co_authors = [] + + if self.message: + results = re.findall( + r"^Co-authored-by: ((?:\w|\-| ){0,38}) <(\S*)>$", + self.message, + re.MULTILINE, + ) + for author in results: + co_authors.append(Actor(*author)) + + return co_authors diff --git a/test/test_commit.py b/test/test_commit.py index 82126987..cf8e1db6 100644 --- a/test/test_commit.py +++ b/test/test_commit.py @@ -509,3 +509,14 @@ JzJMZDRLQLFvnzqZuCjE assert KEY_1 not in commit.trailers.keys() assert KEY_2 in commit.trailers.keys() assert commit.trailers[KEY_2] == VALUE_2 + + def test_commit_co_authors(self): + commit = copy.copy(self.rorepo.commit("4251bd5")) + commit.message = """Commit message + +Co-authored-by: Test User 1 <602352+test@users.noreply.github.com> +Co-authored-by: test_user_2 <another_user-email@.github.com>""" + assert commit.co_authors == [ + Actor("Test User 1", "602352+test@users.noreply.github.com"), + Actor("test_user_2", "another_user-email@.github.com"), + ] |