File tree Expand file tree Collapse file tree 3 files changed +34
-0
lines changed Expand file tree Collapse file tree 3 files changed +34
-0
lines changed Original file line number Diff line number Diff line change @@ -48,4 +48,5 @@ Contributors are:
4848-Hiroki Tokunaga <tokusan441 _at_ gmail.com>
4949-Julien Mauroy <pro.julien.mauroy _at_ gmail.com>
5050-Patrick Gerard
51+ -Luke Twist <itsluketwist@gmail.com>
5152Portions derived from other open source works and are clearly marked.
Original file line number Diff line number Diff line change 44# This module is part of GitPython and is released under
55# the BSD License: http://www.opensource.org/licenses/bsd-license.php
66import datetime
7+ import re
78from subprocess import Popen , PIPE
89from gitdb import IStream
910from git .util import hex_to_bin , Actor , Stats , finalize_process
@@ -738,3 +739,24 @@ def _deserialize(self, stream: BytesIO) -> "Commit":
738739 return self
739740
740741 # } END serializable implementation
742+
743+ @property
744+ def co_authors (self ) -> List [Actor ]:
745+ """
746+ Search the commit message for any co-authors of this commit.
747+ Details on co-authors: https://github.blog/2018-01-29-commit-together-with-co-authors/
748+
749+ :return: List of co-authors for this commit (as Actor objects).
750+ """
751+ co_authors = []
752+
753+ if self .message :
754+ results = re .findall (
755+ r"^Co-authored-by: ((?:\w|\-| ){0,38}) <(\S*)>$" ,
756+ self .message ,
757+ re .MULTILINE ,
758+ )
759+ for author in results :
760+ co_authors .append (Actor (* author ))
761+
762+ return co_authors
Original file line number Diff line number Diff line change @@ -509,3 +509,14 @@ def test_trailers(self):
509509 assert KEY_1 not in commit .trailers .keys ()
510510 assert KEY_2 in commit .trailers .keys ()
511511 assert commit .trailers [KEY_2 ] == VALUE_2
512+
513+ def test_commit_co_authors (self ):
514+ commit = copy .copy (self .rorepo .commit ("4251bd5" ))
515+ commit .message = """Commit message
516+
517+ Co-authored-by: Test User 1 <602352+test@users.noreply.github.com>
518+ Co-authored-by: test_user_2 <another_user-email@.github.com>"""
519+ assert commit .co_authors == [
520+ Actor ("Test User 1" , "602352+test@users.noreply.github.com" ),
521+ Actor ("test_user_2" , "another_user-email@.github.com" ),
522+ ]
You can’t perform that action at this time.
0 commit comments