diff --git a/requirements-swh.txt b/requirements-swh.txt --- a/requirements-swh.txt +++ b/requirements-swh.txt @@ -1,4 +1,4 @@ swh.storage >= 0.0.163 -swh.model >= 0.0.59 +swh.model >= 0.0.60 swh.scheduler >= 0.0.39 swh.loader.core >= 0.0.80 diff --git a/swh/loader/svn/converters.py b/swh/loader/svn/converters.py --- a/swh/loader/svn/converters.py +++ b/swh/loader/svn/converters.py @@ -3,14 +3,11 @@ # License: GNU General Public License version 3, or any later version # See top-level LICENSE file for more information -from typing import Any, Dict, List, Optional, Union - -from email import utils +from typing import Any, Dict, List, Optional from swh.model.model import ( Person, Revision, RevisionType, TimestampWithTimezone ) -from swh.loader.package.utils import EMPTY_AUTHOR from .utils import strdate_to_timestamp @@ -34,33 +31,18 @@ ) -def svn_author_to_swh_person(author: Union[str, bytes]) -> Person: +def svn_author_to_swh_person(author: Optional[bytes]) -> Person: """Convert an svn author to an swh person. Default policy: No information is added. Args: - author (string): the svn author (in bytes) + author: the svn author (in bytes) Returns: a Person """ - # TODO: Align this function and move it up as library helper function - if not author: - return EMPTY_AUTHOR - - if isinstance(author, str): - author = author.encode('utf-8') - - if b'<' in author and b'>' in author: - name, email = utils.parseaddr(author.decode('utf-8')) - return Person( - fullname=author, - name=name.encode('utf-8'), - email=email.encode('utf-8') - ) - - return Person(fullname=author, name=author, email=None) + return Person.from_fullname(author or b'') def build_swh_revision( diff --git a/swh/loader/svn/svn.py b/swh/loader/svn/svn.py --- a/swh/loader/svn/svn.py +++ b/swh/loader/svn/svn.py @@ -106,19 +106,11 @@ def convert_commit_author(self, author): """Convert the commit author into an swh person. - The user becomes a dictionary of the form:: - - { - name: author, - email: '', - fullname: author - } - Args: author (str): the commit author to convert. Returns: - The transformed author as dict. + Person: a model object """ return converters.svn_author_to_swh_person(author) diff --git a/swh/loader/svn/tests/test_converters.py b/swh/loader/svn/tests/test_converters.py --- a/swh/loader/svn/tests/test_converters.py +++ b/swh/loader/svn/tests/test_converters.py @@ -15,7 +15,7 @@ """ actual_person = converters.svn_author_to_swh_person( - 'tony ') + b'tony ') assert actual_person == Person.from_dict({ 'fullname': b'tony ', @@ -28,7 +28,7 @@ """The author and fullname should be the same as the input (author). """ - actual_person = converters.svn_author_to_swh_person('tony') + actual_person = converters.svn_author_to_swh_person(b'tony') assert actual_person == Person.from_dict({ 'fullname': b'tony', 'name': b'tony', @@ -41,7 +41,7 @@ byte-string. """ - actual_person = converters.svn_author_to_swh_person('') + actual_person = converters.svn_author_to_swh_person(b'') assert actual_person == Person.from_dict({ 'fullname': b'', 'name': None,