summaryrefslogtreecommitdiff
path: root/git/objects
diff options
context:
space:
mode:
authorTwist <itsluketwist@gmail.com>2022-08-22 18:00:37 +0100
committerTwist <itsluketwist@gmail.com>2022-08-22 18:00:37 +0100
commit146cbdaffdd1b551e6689f162e26226d5a351d6e (patch)
tree16ec594cbe18dc242de3c823b1bdc3de8905c802 /git/objects
parent12d91c6459422c034b790c8bcc5e429aa3a42c3b (diff)
downloadgitpython-146cbdaffdd1b551e6689f162e26226d5a351d6e.tar.gz
Add co_authors property to the Commit object, which parses the commit message for designated co-authors, include a simple test.
Diffstat (limited to 'git/objects')
-rw-r--r--git/objects/commit.py22
1 files changed, 22 insertions, 0 deletions
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