diff --git a/swh/loader/npm/tests/test_utils.py b/swh/loader/npm/tests/test_utils.py --- a/swh/loader/npm/tests/test_utils.py +++ b/swh/loader/npm/tests/test_utils.py @@ -266,3 +266,54 @@ 'email': None } ) + + package_json = json.loads(''' + { + "name": "yfe-ynpm", + "version": "1.0.0", + "homepage": "http://gitlab.ywwl.com/yfe/yfe-ynpm", + "repository": { + "type": "git", + "url": "git@gitlab.ywwl.com:yfe/yfe-ynpm.git" + }, + "author": [ + "fengmk2 (https://fengmk2.com)", + "xufuzi (https://7993.org)" + ], + "license": "MIT" + }''') + + self.assertEqual( + extract_npm_package_author(package_json), + { + 'fullname': b'fengmk2 ', + 'name': b'fengmk2', + 'email': b'fengmk2@gmail.com' + } + ) + + package_json = json.loads(''' + { + "name": "umi-plugin-whale", + "version": "0.0.8", + "description": "Internal contract component", + "authors": { + "name": "xiaohuoni", + "email": "448627663@qq.com" + }, + "repository": "alitajs/whale", + "devDependencies": { + "np": "^3.0.4", + "umi-tools": "*" + }, + "license": "MIT" + }''') + + self.assertEqual( + extract_npm_package_author(package_json), + { + 'fullname': b'xiaohuoni <448627663@qq.com>', + 'name': b'xiaohuoni', + 'email': b'448627663@qq.com' + } + ) diff --git a/swh/loader/npm/utils.py b/swh/loader/npm/utils.py --- a/swh/loader/npm/utils.py +++ b/swh/loader/npm/utils.py @@ -86,16 +86,16 @@ if 'email' in author_data: author_str += ' <%s>' % author_data['email'] return author_str + elif type(author_data) is list: + return _author_str(author_data[0]) if len(author_data) > 0 else '' else: return author_data author_data = {} - if 'author' in package_json: - author_str = _author_str(package_json['author']) - author_data = parse_npm_package_author(author_str) - elif 'authors' in package_json and len(package_json['authors']) > 0: - author_str = _author_str(package_json['authors'][0]) - author_data = parse_npm_package_author(author_str) + for author_key in ('author', 'authors'): + if author_key in package_json: + author_str = _author_str(package_json[author_key]) + author_data = parse_npm_package_author(author_str) name = author_data.get('name') email = author_data.get('email')