| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 12d91c6 commit 146cbda
3 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -48,4 +48,5 @@ Contributors are: | |||
| 48 | 48 | -Hiroki Tokunaga <tokusan441 _at_ gmail.com> | |
| 49 | 49 | -Julien Mauroy <pro.julien.mauroy _at_ gmail.com> | |
| 50 | 50 | -Patrick Gerard | |
| 51 | + -Luke Twist <itsluketwist@gmail.com> | ||
| 51 | 52 | Portions derived from other open source works and are clearly marked. | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -4,6 +4,7 @@ | |||
| 4 | 4 | # This module is part of GitPython and is released under | |
| 5 | 5 | # the BSD License: http://www.opensource.org/licenses/bsd-license.php | |
| 6 | 6 | import datetime | |
| 7 | + import re | ||
| 7 | 8 | from subprocess import Popen, PIPE | |
| 8 | 9 | from gitdb import IStream | |
| 9 | 10 | from git.util import hex_to_bin, Actor, Stats, finalize_process | |
@@ -738,3 +739,24 @@ def _deserialize(self, stream: BytesIO) -> "Commit": | |||
| 738 | 739 | return self | |
| 739 | 740 | ||
| 740 | 741 | # } 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): | |||
| 509 | 509 | assert KEY_1 not in commit.trailers.keys() | |
| 510 | 510 | assert KEY_2 in commit.trailers.keys() | |
| 511 | 511 | 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 | + ] | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments