Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add commit co-authors support #1482

Merged
merged 6 commits into from
Aug 25, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions AUTHORS
Original file line number Diff line number Diff line change
Expand Up @@ -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.
2 changes: 1 addition & 1 deletion git/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@
CONDITIONAL_INCLUDE_REGEXP = re.compile(r"(?<=includeIf )\"(gitdir|gitdir/i|onbranch):(.+)\"")


class MetaParserBuilder(abc.ABCMeta):
class MetaParserBuilder(abc.ABCMeta): # noqa: B024
"""Utility class wrapping base-class methods into decorators that assure read-only properties"""

def __new__(cls, name: str, bases: Tuple, clsdict: Dict[str, Any]) -> "MetaParserBuilder":
Expand Down
22 changes: 22 additions & 0 deletions git/objects/commit.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -738,3 +739,24 @@ def _deserialize(self, stream: BytesIO) -> "Commit":
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: (.*) <(.*?)>$",
self.message,
re.MULTILINE,
)
for author in results:
co_authors.append(Actor(*author))

return co_authors
15 changes: 15 additions & 0 deletions test/test_commit.py
Original file line number Diff line number Diff line change
Expand Up @@ -509,3 +509,18 @@ def test_trailers(self):
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>
Co_authored_by: test_user_x <test@github.com>
Co-authored-by: test_user_y <test@github.com> text
Co-authored-by: test_user_3 <test_user_3@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"),
Actor("test_user_3", "test_user_3@github.com"),
]
7 changes: 7 additions & 0 deletions test/test_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,13 @@

import os
import pickle
import sys
import tempfile
import time
from unittest import mock, skipIf
from datetime import datetime

import pytest
import ddt

from git.cmd import dashify
Expand Down Expand Up @@ -154,6 +156,11 @@ def test_lock_file(self):
lock_file._obtain_lock_or_raise()
lock_file._release_lock()

@pytest.mark.xfail(
sys.platform == "cygwin",
reason="Cygwin fails here for some reason, always",
raises=AssertionError
)
def test_blocking_lock_file(self):
my_file = tempfile.mktemp()
lock_file = BlockingLockFile(my_file)
Expand Down