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 @@ -225,3 +225,44 @@ 'email': b'evgeniy.pakalo@gmail.com' } ) + + package_json = json.loads(''' + { + "name": "3-way-diff", + "version": "0.0.1", + "description": "3-way diffing of JavaScript objects", + "main": "index.js", + "authors": [ + { + "name": "Shawn Walsh", + "url": "https://github.com/shawnpwalsh" + }, + { + "name": "Markham F Rollins IV", + "url": "https://github.com/mrollinsiv" + } + ], + "keywords": [ + "3-way diff", + "3 way diff", + "three-way diff", + "three way diff" + ], + "devDependencies": { + "babel-core": "^6.20.0", + "babel-preset-es2015": "^6.18.0", + "mocha": "^3.0.2" + }, + "dependencies": { + "lodash": "^4.15.0" + } + }''') + + self.assertEqual( + extract_npm_package_author(package_json), + { + 'fullname': b'Shawn Walsh', + 'name': b'Shawn Walsh', + 'email': None + } + ) 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 @@ -77,19 +77,25 @@ * email """ + + def _author_str(author_data): + if type(author_data) is dict: + author_str = '' + if 'name' in author_data: + author_str += author_data['name'] + if 'email' in author_data: + author_str += ' <%s>' % author_data['email'] + return author_str + else: + return author_data + author_data = {} if 'author' in package_json: - if type(package_json['author']) is str: - author_data = parse_npm_package_author(package_json['author']) - elif type(package_json['author']) is dict: - author_str = '' - if 'name' in package_json['author']: - author_str += package_json['author']['name'] - if 'email' in package_json['author']: - author_str += ' <%s>' % package_json['author']['email'] - author_data = parse_npm_package_author(author_str) + 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_data = parse_npm_package_author(package_json['authors'][0]) + author_str = _author_str(package_json['authors'][0]) + author_data = parse_npm_package_author(author_str) name = author_data.get('name') email = author_data.get('email')